-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Setting Default Fluids + AR Integration
- Loading branch information
1 parent
3d472c3
commit 6b1c70a
Showing
13 changed files
with
153 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/com/nomiceu/nomilabs/mixin/FluidRegistryMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.nomiceu.nomilabs.NomiLabs; | ||
import com.nomiceu.nomilabs.config.LabsConfig; | ||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidRegistry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Set; | ||
|
||
@Mixin(value = FluidRegistry.class, remap = false) | ||
public class FluidRegistryMixin { | ||
@Shadow | ||
static BiMap<String, Fluid> fluids; | ||
|
||
@Shadow | ||
static BiMap<Fluid, Integer> fluidIDs; | ||
|
||
@Shadow | ||
static BiMap<Integer, String> fluidNames; | ||
|
||
@Shadow | ||
static BiMap<String, String> defaultFluidName; | ||
|
||
@Shadow | ||
static BiMap<String, Fluid> masterFluidReference; | ||
|
||
@Inject(method = "loadFluidDefaults(Lcom/google/common/collect/BiMap;Ljava/util/Set;)V", at = @At( | ||
value = "FIELD", | ||
target = "Lnet/minecraftforge/fluids/FluidRegistry;currentBucketFluids:Ljava/util/Set;", | ||
shift = At.Shift.AFTER), | ||
require = 1) | ||
private static void loadSpecifiedFluidDefaults(BiMap<Fluid, Integer> localFluidIDs, Set<String> defaultNames, CallbackInfo ci) { | ||
if (LabsConfig.advanced.defaultFluids.length == 0) return; | ||
int changed = 0; | ||
for (var fluidName : LabsConfig.advanced.defaultFluids) { | ||
NomiLabs.LOGGER.debug("Processing Input {}", fluidName); | ||
|
||
var fluid = masterFluidReference.get(fluidName); | ||
if (fluid == null) | ||
throw new IllegalArgumentException("Nomi Labs: Config Entry " + fluidName + "in Default Fluids Config doesn't exist!"); | ||
var oldFluid = fluids.get(fluid.getName()); | ||
if (oldFluid == null) continue; | ||
|
||
var oldName = masterFluidReference.inverse().get(oldFluid); | ||
if (oldName.equals(fluidName)) { | ||
NomiLabs.LOGGER.debug("Default fluid of {} is already {}. Not Changing...", fluid.getName(), fluidName); | ||
continue; | ||
} | ||
|
||
NomiLabs.LOGGER.debug("Changing default fluid of {}, from {} to {}.", fluid.getName(), oldName, fluidName); | ||
changed++; | ||
|
||
fluids.forcePut(fluid.getName(), fluid); | ||
defaultFluidName.forcePut(fluid.getName(), fluidName); | ||
Integer id = localFluidIDs.remove(oldFluid); | ||
localFluidIDs.forcePut(fluid, id); | ||
fluidNames.forcePut(id, fluid.getName()); | ||
} | ||
if (changed == 0) { | ||
NomiLabs.LOGGER.info("No Fluids Changed."); | ||
return; | ||
} | ||
NomiLabs.LOGGER.info("Changed {} Default Fluid(s)!", changed); | ||
fluidIDs = localFluidIDs; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/nomiceu/nomilabs/mixin/advancedrocketry/AdvancedRocketryMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.nomiceu.nomilabs.mixin.advancedrocketry; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraftforge.fluids.BlockFluidBase; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import zmaster587.advancedRocketry.AdvancedRocketry; | ||
import zmaster587.libVulpes.api.LibVulpesBlocks; | ||
|
||
@Mixin(value = AdvancedRocketry.class, remap = false) | ||
public class AdvancedRocketryMixin { | ||
@Redirect(method = "registerBlocks", at = @At(value = "INVOKE", target = "Lzmaster587/libVulpes/api/LibVulpesBlocks;registerBlock(Lnet/minecraft/block/Block;)Lnet/minecraft/block/Block;")) | ||
public <T extends Block> T registerBlocksProperly(T block) { | ||
if (block instanceof BlockFluidBase) { | ||
return LibVulpesBlocks.registerBlock(block, null, false); | ||
} | ||
return LibVulpesBlocks.registerBlock(block); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"package": "com.nomiceu.nomilabs.mixin.advancedrocketry", | ||
"refmap": "mixins.nomilabs.refmap.json", | ||
"target": "@env(DEFAULT)", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
"AdvancedRocketryMixin" | ||
], | ||
"client": [], | ||
"server": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters