-
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.
- Loading branch information
1 parent
1ccf4ab
commit 370c85f
Showing
7 changed files
with
188 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.nomiceu.nomilabs.groovy.NCActiveCoolerHelper | ||
|
||
import static nc.enumm.MetaEnums.CoolerType.* | ||
|
||
/** | ||
* Change a NuclearCraft Active Cooler Recipe.<br> | ||
* Inputs:<br> | ||
* FluidStack newFluid: The new fluid which should be accepted as input to Active Fluid Cooler<br> | ||
* CoolerType type: The type of active cooler fluid which this recipe should replace, having that recipe removed as | ||
* well as using the cooling and consumption from that type. | ||
*/ | ||
|
||
NCActiveCoolerHelper.changeCoolerRecipe(fluid('liquid_helium'), HELIUM) | ||
|
||
NCActiveCoolerHelper.changeCoolerRecipe(fluid('moltenempoweredemeradic'), EMERALD) |
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
88 changes: 88 additions & 0 deletions
88
src/main/java/com/nomiceu/nomilabs/groovy/NCActiveCoolerHelper.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,88 @@ | ||
package com.nomiceu.nomilabs.groovy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fml.common.Optional; | ||
|
||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
import com.nomiceu.nomilabs.LabsValues; | ||
import com.nomiceu.nomilabs.integration.nuclearcraft.AccessibleCoolerType; | ||
|
||
import nc.config.NCConfig; | ||
import nc.enumm.MetaEnums; | ||
import nc.recipe.NCRecipes; | ||
import nc.recipe.other.ActiveCoolerRecipes; | ||
|
||
public class NCActiveCoolerHelper { | ||
|
||
/* | ||
* Reference must not be CHANGED! References are stored in TileActiveCooler! | ||
* ID - 1 -> Fluid Name | ||
*/ | ||
public static final List<String> fluidNamesFromIDs = new ArrayList<>(); | ||
|
||
static { | ||
reloadFluidNames(); | ||
} | ||
|
||
@SuppressWarnings("ConstantValue") | ||
private static void reloadFluidNames() { | ||
fluidNamesFromIDs.clear(); | ||
for (int i = 1; i < MetaEnums.CoolerType.values().length; i++) { | ||
fluidNamesFromIDs.add(i - 1, | ||
((AccessibleCoolerType) (Object) MetaEnums.CoolerType.values()[i]).getOriginalFluidName()); | ||
} | ||
} | ||
|
||
public static void onReload() { | ||
// Usually Active Cooler is null on Pre-Init or Init Load | ||
if (NCRecipes.active_cooler == null) return; | ||
|
||
reloadFluidNames(); | ||
|
||
NCRecipes.active_cooler.removeAllRecipes(); | ||
NCRecipes.active_cooler.addRecipes(); | ||
} | ||
|
||
public static void afterScriptLoad() { | ||
// Usually Active Cooler is null on Pre-Init or Init Load | ||
if (NCRecipes.active_cooler == null) return; | ||
|
||
NCRecipes.active_cooler.refreshCache(); | ||
} | ||
|
||
@Optional.Method(modid = LabsValues.NUCLEARCRAFT_MODID) | ||
public static void changeCoolerRecipe(FluidStack newStack, MetaEnums.CoolerType type) { | ||
if (NCRecipes.active_cooler == null) { | ||
GroovyLog.get().error("Active Cooler Recipes not Found!"); | ||
return; | ||
} | ||
|
||
boolean removed = false; | ||
for (var recipe : NCRecipes.active_cooler.getRecipeList()) { | ||
if (recipe.fluidIngredients().size() == 1) { | ||
var ing = recipe.fluidIngredients().get(0); | ||
if (ing.getInputStackList().size() == 1 && | ||
Objects.equals(ing.getInputStackList().get(0).getFluid().getName(), type.getFluidName())) { | ||
NCRecipes.active_cooler.removeRecipe(recipe); | ||
removed = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!removed) { | ||
GroovyLog.get().error("Could not find ActiveCooler recipe for " + type.getFluidName() + "!"); | ||
} | ||
|
||
NCRecipes.active_cooler.addRecipe( | ||
ActiveCoolerRecipes.fluidStack(newStack.getFluid().getName(), NCConfig.active_cooler_max_rate), | ||
Math.round(NCConfig.fission_active_cooling_rate[type.getID() - 1] * NCConfig.active_cooler_max_rate / | ||
20.0), | ||
Math.round(NCConfig.fusion_active_cooling_rate[type.getID() - 1] * NCConfig.active_cooler_max_rate / | ||
20.0)); | ||
fluidNamesFromIDs.set(type.getID() - 1, newStack.getFluid().getName()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/nomiceu/nomilabs/integration/nuclearcraft/AccessibleCoolerType.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,6 @@ | ||
package com.nomiceu.nomilabs.integration.nuclearcraft; | ||
|
||
public interface AccessibleCoolerType { | ||
|
||
String getOriginalFluidName(); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/nomiceu/nomilabs/mixin/nuclearcraft/CoolerTypeMixin.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,40 @@ | ||
package com.nomiceu.nomilabs.mixin.nuclearcraft; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import com.nomiceu.nomilabs.groovy.NCActiveCoolerHelper; | ||
import com.nomiceu.nomilabs.integration.nuclearcraft.AccessibleCoolerType; | ||
|
||
import nc.enumm.MetaEnums; | ||
|
||
/** | ||
* Allows for proper checking of custom Active Cooler Fluids. | ||
*/ | ||
@Mixin(value = MetaEnums.CoolerType.class, remap = false) | ||
public class CoolerTypeMixin implements AccessibleCoolerType { | ||
|
||
@Shadow | ||
private int id; | ||
|
||
@Shadow | ||
private String fluidName; | ||
|
||
@Inject(method = "getFluidName", at = @At("HEAD"), cancellable = true) | ||
private void getProperFluidName(CallbackInfoReturnable<String> cir) { | ||
if (id == 0) | ||
cir.setReturnValue(fluidName); | ||
else | ||
cir.setReturnValue(NCActiveCoolerHelper.fluidNamesFromIDs.get(id - 1)); | ||
} | ||
|
||
@Override | ||
@Unique | ||
public String getOriginalFluidName() { | ||
return fluidName; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/nomiceu/nomilabs/mixin/nuclearcraft/TileActiveCoolerMixin.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,24 @@ | ||
package com.nomiceu.nomilabs.mixin.nuclearcraft; | ||
|
||
import java.util.List; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import com.nomiceu.nomilabs.groovy.NCActiveCoolerHelper; | ||
|
||
import nc.tile.fluid.TileActiveCooler; | ||
|
||
/** | ||
* Allows for Tile Active Coolers to accept custom fluids. | ||
*/ | ||
@Mixin(value = TileActiveCooler.class, remap = false) | ||
public class TileActiveCoolerMixin { | ||
|
||
@Inject(method = "validFluids", at = @At("HEAD"), cancellable = true) | ||
private static void getProperValidFluids(CallbackInfoReturnable<List<String>> cir) { | ||
cir.setReturnValue(NCActiveCoolerHelper.fluidNamesFromIDs); | ||
} | ||
} |
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