From 6f5ac750f64e24341493abf37d90137099c08e47 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Fri, 18 Aug 2017 20:38:20 +0200 Subject: [PATCH 1/8] Add CraftTweaker integration Optional dependency on MTLib to make CraftTweaker integration easier Thanks to @jaredlll08 for letting me use the "old" ModTweaker code (which was almost 100% compatible) --- build.gradle | 19 ++- build.properties | 2 + .../gas/CraftTweakerGasDefinition.java | 32 ++++ .../gas/CraftTweakerGasStack.java | 154 ++++++++++++++++++ .../crafttweaker/gas/IGasDefinition.java | 19 +++ .../crafttweaker/gas/IGasStack.java | 30 ++++ .../handlers/ChemicalCrystallizer.java | 86 ++++++++++ .../handlers/ChemicalDissolution.java | 86 ++++++++++ .../handlers/ChemicalInfuser.java | 88 ++++++++++ .../handlers/ChemicalInjection.java | 97 +++++++++++ .../handlers/ChemicalOxidizer.java | 82 ++++++++++ .../crafttweaker/handlers/ChemicalWasher.java | 83 ++++++++++ .../crafttweaker/handlers/Combiner.java | 109 +++++++++++++ .../crafttweaker/handlers/Compressor.java | 111 +++++++++++++ .../crafttweaker/handlers/Crusher.java | 83 ++++++++++ .../handlers/EnergizedSmelter.java | 83 ++++++++++ .../crafttweaker/handlers/Enrichment.java | 79 +++++++++ .../crafttweaker/handlers/Infuser.java | 93 +++++++++++ .../crafttweaker/handlers/Purification.java | 110 +++++++++++++ .../crafttweaker/handlers/Reaction.java | 106 ++++++++++++ .../crafttweaker/handlers/Sawmill.java | 94 +++++++++++ .../crafttweaker/handlers/Separator.java | 91 +++++++++++ .../handlers/SolarNeutronActivator.java | 79 +++++++++ .../handlers/ThermalEvaporation.java | 67 ++++++++ .../crafttweaker/helpers/GasHelper.java | 52 ++++++ .../crafttweaker/util/AddMekanismRecipe.java | 63 +++++++ .../util/RemoveMekanismRecipe.java | 57 +++++++ 27 files changed, 2049 insertions(+), 6 deletions(-) create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java diff --git a/build.gradle b/build.gradle index 39d804f96..452756915 100644 --- a/build.gradle +++ b/build.gradle @@ -73,6 +73,10 @@ repositories { name 'ic2' url 'http://maven.ic2.player.to' } + maven { + name 'BlameJared - Crafttweaker' + url 'http://maven.blamejared.com/' + } } // Define properties file @@ -101,17 +105,20 @@ minecraft { dependencies { deobfCompile "MCMultiPart2:MCMultiPart-exp:${config.mcmp_version}" - deobfProvided "mezz.jei:jei_1.12:${config.jei_version}:api" // still on 1.12 - runtime "mezz.jei:jei_1.12:${config.jei_version}" // still on 1.12 - compile "net.darkhax.tesla:Tesla-1.12:${config.tesla_version}" // still on 1.12 + deobfProvided "mezz.jei:jei_1.12:${config.jei_version}:api" + runtime "mezz.jei:jei_1.12:${config.jei_version}" + compile "net.darkhax.tesla:Tesla-1.12:${config.tesla_version}" compile "inventory-tweaks:InventoryTweaks:${config.invtweak_version}:api" compile "li.cil.oc:OpenComputers:MC1.11.2-${config.opencomputers_version}:api" // Not updated yet deobfCompile "mcp.mobius.waila:Hwyla:${config.hwyla_version}" - deobfCompile "cofh:RedstoneFlux:1.12-${config.redstoneflux_version}:universal" // still on 1.12 + deobfCompile "cofh:RedstoneFlux:1.12-${config.redstoneflux_version}:universal" deobfCompile "com.mod-buildcraft:buildcraft-api:${config.buildcraft_version}" - deobfProvided "team.chisel.ctm:CTM:MC1.12-${config.ctm_version}:api" // still on 1.12 - runtime "team.chisel.ctm:CTM:MC1.12-${config.ctm_version}" // still on 1.12 + deobfProvided "team.chisel.ctm:CTM:MC1.12-${config.ctm_version}:api" + runtime "team.chisel.ctm:CTM:MC1.12-${config.ctm_version}" compile "net.industrial-craft:industrialcraft-2:${config.ic2_version}:api" + deobfProvided "CraftTweaker2:CraftTweaker2-API:${config.crafttweaker_version}" + runtime "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-${config.crafttweaker_version}" + deobfCompile "com.blamejared:MTLib:${config.mtlib_version}" } processResources diff --git a/build.properties b/build.properties index b5be0efe5..33bcfe844 100644 --- a/build.properties +++ b/build.properties @@ -12,3 +12,5 @@ redstoneflux_version=2.0.0.1 buildcraft_version=7.99.6 ctm_version=0.2.1.5 ic2_version=2.8.9-ex112 +crafttweaker_version=4.0.3.247 +mtlib_version=3.0.0.1 diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java new file mode 100644 index 000000000..7c33fee31 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java @@ -0,0 +1,32 @@ +package mekanism.common.integration.crafttweaker.gas; + +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; + +public class CraftTweakerGasDefinition implements IGasDefinition +{ + private final Gas gas; + + public CraftTweakerGasDefinition(Gas gas) + { + this.gas = gas; + } + + @Override + public IGasStack asStack(int millibuckets) + { + return new CraftTweakerGasStack(new GasStack(gas, millibuckets)); + } + + @Override + public String getName() + { + return gas.getName(); + } + + @Override + public String getDisplayName() + { + return gas.getLocalizedName(); + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java new file mode 100644 index 000000000..ada69e5c2 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java @@ -0,0 +1,154 @@ +package mekanism.common.integration.crafttweaker.gas; + +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemCondition; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IItemTransformer; +import crafttweaker.api.liquid.ILiquidStack; +import crafttweaker.api.player.IPlayer; +import mekanism.api.gas.GasStack; + +import java.util.List; + +public class CraftTweakerGasStack implements IGasStack +{ + private final GasStack stack; + + public CraftTweakerGasStack(GasStack stack) + { + this.stack = stack; + } + + + @Override + public IGasDefinition getDefinition() + { + return new CraftTweakerGasDefinition(stack.getGas()); + } + + @Override + public String getName() + { + return stack.getGas().getName(); + } + + @Override + public String getDisplayName() + { + return stack.getGas().getLocalizedName(); + } + + @Override + public String getMark() + { + return null; + } + + @Override + public int getAmount() + { + return stack.amount; + } + + @Override + public List getItems() + { + return null; + } + + @Override + public IItemStack[] getItemArray() + { + return new IItemStack[0]; + } + + @Override + public List getLiquids() + { + return null; + } + + @Override + public IIngredient amount(int amount) + { + return withAmount(amount); + } + + @Override + public IIngredient or(IIngredient iIngredient) + { + return null; + } + + @Override + public IIngredient transform(IItemTransformer iItemTransformer) + { + return null; + } + + @Override + public IIngredient only(IItemCondition iItemCondition) + { + return null; + } + + @Override + public IIngredient marked(String s) + { + return null; + } + + @Override + public boolean matches(IItemStack iItemStack) + { + return false; + } + + @Override + public boolean matchesExact(IItemStack iItemStack) + { + return false; + } + + @Override + public boolean matches(ILiquidStack iLiquidStack) + { + return false; + } + + @Override + public boolean contains(IIngredient iIngredient) + { + return false; + } + + @Override + public IItemStack applyTransform(IItemStack iItemStack, IPlayer iPlayer) + { + return null; + } + + @Override + public boolean hasTransformers() + { + return false; + } + + @Override + public IGasStack withAmount(int amount) + { + return null; + } + + @Override + public Object getInternal() + { + return null; + } + + @Override + public String toString() + { + return ""; + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java new file mode 100644 index 000000000..4584b0722 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java @@ -0,0 +1,19 @@ +package mekanism.common.integration.crafttweaker.gas; + +import stanhebben.zenscript.annotations.OperatorType; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenOperator; + +@ZenClass("mod.mekanism.gas.IGasDefinition") +public interface IGasDefinition +{ + @ZenOperator(OperatorType.MUL) + IGasStack asStack(int millibuckets); + + @ZenGetter("NAME") + String getName(); + + @ZenGetter("displayName") + String getDisplayName(); +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java new file mode 100644 index 000000000..029c084c8 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java @@ -0,0 +1,30 @@ +package mekanism.common.integration.crafttweaker.gas; + +import crafttweaker.api.item.IIngredient; +import stanhebben.zenscript.annotations.OperatorType; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.ZenOperator; + +@ZenClass("mod.mekanism.gas.IGasStack") +public interface IGasStack extends IIngredient +{ + @ZenGetter("definition") + IGasDefinition getDefinition(); + + @ZenGetter("NAME") + String getName(); + + @ZenGetter("displayName") + String getDisplayName(); + + @ZenGetter("amount") + int getAmount(); + + @ZenOperator(OperatorType.MUL) + @ZenMethod + IGasStack withAmount(int amount); + + Object getInternal(); +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java new file mode 100644 index 000000000..21020d5ed --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java @@ -0,0 +1,86 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.GasInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.CrystallizerRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.crystallizer") +@ModOnly("mtlib") +@ZenRegister +public class ChemicalCrystallizer +{ + public static final String NAME = "Mekanism Chemical Crystallizer"; + + @ZenMethod + public static void addRecipe(IGasStack gasInput, IItemStack itemOutput) + { + if (gasInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + CrystallizerRecipe recipe = new CrystallizerRecipe(GasHelper.toGas(gasInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient gasInput) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get()).entrySet()) + { + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java new file mode 100644 index 000000000..c2c8ef44c --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java @@ -0,0 +1,86 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ItemStackInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.DissolutionRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.chemical.dissolution") +@ModOnly("mtlib") +@ZenRegister +public class ChemicalDissolution +{ + public static final String NAME = "Mekanism Chemical Dissolution Chamber"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IGasStack gasOutput) + { + if (itemInput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + DissolutionRecipe recipe = new DissolutionRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient itemInput) + { + if (gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), itemInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java new file mode 100644 index 000000000..0647d656d --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java @@ -0,0 +1,88 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.LogHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ChemicalPairInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.ChemicalInfuserRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.chemical.infuser") +@ModOnly("mtlib") +@ZenRegister +public class ChemicalInfuser +{ + public static final String NAME = "Mekanism Chemical Infuser"; + + @ZenMethod + public static void addRecipe(IGasStack leftGasInput, IGasStack rightGasInput, IGasStack gasOutput) + { + if (leftGasInput == null || rightGasInput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + ChemicalInfuserRecipe recipe = new ChemicalInfuserRecipe(GasHelper.toGas(leftGasInput), GasHelper.toGas(rightGasInput), GasHelper.toGas(gasOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient leftGasInput, @Optional IIngredient rightGasInput) + { + if (gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (leftGasInput == null) + leftGasInput = IngredientAny.INSTANCE; + if (rightGasInput == null) + rightGasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_INFUSER.get()).entrySet()) + { + IGasStack inputGasLeft = new CraftTweakerGasStack(entry.getKey().leftGas); + IGasStack inputGasRight = new CraftTweakerGasStack(entry.getKey().rightGas); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + if (!GasHelper.matches(leftGasInput, inputGasLeft)) + continue; + if (!GasHelper.matches(rightGasInput, inputGasRight)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, gasOutput.toString(), leftGasInput.toString(), rightGasInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java new file mode 100644 index 000000000..839d9e7a8 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java @@ -0,0 +1,97 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.AdvancedMachineInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.InjectionRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.outputs.ItemStackOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + + +@ZenClass("mods.mekanism.chemical.injection") +@ModOnly("mtlib") +@ZenRegister +public class ChemicalInjection +{ + public static final String NAME = "Mekanism Chemical Injection Chamber"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) + { + if (itemInput == null || gasInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); + ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); + + InjectionRecipe recipe = new InjectionRecipe(input, output); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), itemInput.toString(), gasInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java new file mode 100644 index 000000000..5759d42c1 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java @@ -0,0 +1,82 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ItemStackInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.OxidationRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.chemical.oxidizer") +public class ChemicalOxidizer +{ + public static final String NAME = "Mekanism Chemical Oxidizer"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IGasStack gasOutput) + { + if (itemInput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + OxidationRecipe recipe = new OxidationRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient itemInput) + { + if (gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), itemInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java new file mode 100644 index 000000000..8aeba4f05 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java @@ -0,0 +1,83 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.LogHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.GasInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.WasherRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.chemical.washer") +@ModOnly("mtlib") +@ZenRegister +public class ChemicalWasher +{ + public static final String NAME = "Mekanism Chemical Washer"; + + @ZenMethod + public static void addRecipe(IGasStack gasInput, IGasStack gasOutput) + { + if (gasInput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + WasherRecipe recipe = new WasherRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient gasInput) + { + if (gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_WASHER.get()).entrySet()) + { + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), gasInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java new file mode 100644 index 000000000..d4236b90d --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java @@ -0,0 +1,109 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.AdvancedMachineInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.CombinerRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.outputs.ItemStackOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.combiner") +@ModOnly("mtlib") +@ZenRegister +public class Combiner +{ + public static final String NAME = "Mekanism Combiner"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) + { + if (itemInput == null || gasInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); + ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); + CombinerRecipe recipe = new CombinerRecipe(input, output); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); + } + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + CombinerRecipe recipe = new CombinerRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.COMBINER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemInput.toString(), gasInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java new file mode 100644 index 000000000..01ea3996a --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java @@ -0,0 +1,111 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.AdvancedMachineInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.OsmiumCompressorRecipe; +import mekanism.common.recipe.outputs.ItemStackOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.compressor") +@ModOnly("mtlib") +@ZenRegister +public class Compressor +{ + public static final String NAME = "Mekanism Compressor"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + OsmiumCompressorRecipe recipe = new OsmiumCompressorRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipe)); + } + + @SuppressWarnings("unchecked") + @ZenMethod + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) + { + if (itemInput == null || gasInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); + ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); + + OsmiumCompressorRecipe recipe = new OsmiumCompressorRecipe(input, output); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemInput.toString(), gasInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java new file mode 100644 index 000000000..5c817f914 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java @@ -0,0 +1,83 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ItemStackInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.CrusherRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.crusher") +@ModOnly("mtlib") +@ZenRegister +public class Crusher +{ + public static final String NAME = "Mekanism Crusher"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + CrusherRecipe recipe = new CrusherRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CRUSHER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java new file mode 100644 index 000000000..7a6e61778 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java @@ -0,0 +1,83 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ItemStackInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.SmeltingRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.smelter") +@ModOnly("mtlib") +@ZenRegister +public class EnergizedSmelter +{ + public static final String NAME = "Mekanism Smelter"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + SmeltingRecipe recipe = new SmeltingRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput) + { + if (itemInput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemOutput == null) + itemOutput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ENERGIZED_SMELTER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java new file mode 100644 index 000000000..664dbfc3e --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java @@ -0,0 +1,79 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ItemStackInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.CrusherRecipe; +import mekanism.common.recipe.machines.MachineRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.enrichment") +@ModOnly("mtlib") +@ZenRegister +public class Enrichment +{ + public static final String NAME = "Mekanism Enrichment Chamber"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", NAME)); + return; + } + + CrusherRecipe recipe = new CrusherRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput) + { + if(itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", NAME)); + } + + if(itemInput == null) itemInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for(Map.Entry entry : ((Map) RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if(!StackHelper.matches(itemOutput, outputItem)) continue; + if(!StackHelper.matches(itemInput, inputItem)) continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if(!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java new file mode 100644 index 000000000..932c395a3 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java @@ -0,0 +1,93 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.api.infuse.InfuseRegistry; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.InfusionInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.MetallurgicInfuserRecipe; +import mekanism.common.recipe.outputs.ItemStackOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.infuser") +@ModOnly("mtlib") +@ZenRegister +public class Infuser +{ + public static final String NAME = "Mekanism Metallurgic Infuser"; + + @ZenMethod + public static void addRecipe(String infuseType, int infuseAmount, IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null || infuseType == null || infuseType.isEmpty()) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + InfusionInput input = new InfusionInput(InfuseRegistry.get(infuseType), infuseAmount, InputHelper.toStack(itemInput)); + ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); + + MetallurgicInfuserRecipe recipe = new MetallurgicInfuserRecipe(input, output); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional String infuseType) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + if (infuseType == null) + infuseType = ""; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.METALLURGIC_INFUSER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().inputStack); + String typeInfuse = entry.getKey().infuse.type.name; + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!infuseType.isEmpty() && !infuseType.equalsIgnoreCase(typeInfuse)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java new file mode 100644 index 000000000..cc05d3cfe --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java @@ -0,0 +1,110 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.AdvancedMachineInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.PurificationRecipe; +import mekanism.common.recipe.outputs.ItemStackOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.purification") +@ModOnly("mtlib") +@ZenRegister +public class Purification +{ + public static final String NAME = "Mekanism Purification"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + PurificationRecipe recipe = new PurificationRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipe)); + } + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) + { + if (itemInput == null || gasInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); + ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); + + PurificationRecipe recipe = new PurificationRecipe(input, output); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) + { + if (itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PURIFICATION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), itemInput.toString(), gasInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java new file mode 100644 index 000000000..c0c6cd3e8 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java @@ -0,0 +1,106 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import crafttweaker.api.liquid.ILiquidStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.inputs.PressurizedInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.PressurizedRecipe; +import mekanism.common.recipe.outputs.PressurizedOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + + +@ZenClass("mods.mekanism.reaction") +@ModOnly("mtlib") +@ZenRegister +public class Reaction +{ + public static final String NAME = "Mekanism Reaction"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, ILiquidStack liquidInput, IGasStack gasInput, IItemStack itemOutput, IGasStack gasOutput, double energy, int duration) + { + if (itemInput == null || liquidInput == null || gasInput == null || itemOutput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + PressurizedInput input = new PressurizedInput(InputHelper.toStack(itemInput), InputHelper.toFluid(liquidInput), GasHelper.toGas(gasInput)); + PressurizedOutput output = new PressurizedOutput(InputHelper.toStack(itemOutput), GasHelper.toGas(gasOutput)); + + PressurizedRecipe recipe = new PressurizedRecipe(input, output, energy, duration); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemOutput, IIngredient gasOutput, @Optional IIngredient itemInput, @Optional IIngredient liquidInput, @Optional IIngredient gasInput) + { + if (itemOutput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; + if (liquidInput == null) + liquidInput = IngredientAny.INSTANCE; + if (gasInput == null) + gasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().getSolid()); + ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().getFluid()); + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().getGas()); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.getItemOutput()); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.getGasOutput()); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!StackHelper.matches(liquidInput, inputLiquid)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s, %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), gasOutput.toString(), itemInput.toString(), liquidInput.toString(), gasInput.toString())); + } + } + +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java new file mode 100644 index 000000000..f4b77289f --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java @@ -0,0 +1,94 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.ItemStackInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.SawmillRecipe; +import mekanism.common.recipe.outputs.ChanceOutput; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +import static com.blamejared.mtlib.helpers.InputHelper.toStack; + +@ZenClass("mods.mekanism.sawmill") +@ModOnly("mtlib") +@ZenRegister +public class Sawmill +{ + public static final String NAME = "Mekanism Sawmill"; + + @ZenMethod + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput, @Optional IItemStack optionalItemOutput, @Optional double optionalChance) + { + if (itemInput == null || itemOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + ItemStackInput input = new ItemStackInput(toStack(itemInput)); + ChanceOutput output = optionalItemOutput == null ? new ChanceOutput(toStack(itemOutput)) : new ChanceOutput(toStack(itemOutput), toStack(optionalItemOutput), optionalChance); + + SawmillRecipe recipe = new SawmillRecipe(input, output); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput, @Optional IIngredient optionalItemOutput) + { + if (itemInput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (itemOutput == null) + itemOutput = IngredientAny.INSTANCE; + if (optionalItemOutput == null) + optionalItemOutput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PRECISION_SAWMILL.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.primaryOutput); + IItemStack outputItemOptional = InputHelper.toIItemStack(entry.getValue().recipeOutput.secondaryOutput); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!StackHelper.matches(optionalItemOutput, outputItemOptional)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java new file mode 100644 index 000000000..331be3f94 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java @@ -0,0 +1,91 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import crafttweaker.api.liquid.ILiquidStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.FluidInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.SeparatorRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.separator") +@ModOnly("mtlib") +@ZenRegister +public class Separator +{ + public static final String NAME = "Mekanism Separator"; + + @ZenMethod + public static void addRecipe(ILiquidStack liquidInput, double energy, IGasStack leftGasOutput, IGasStack rightGasOutput) + { + if (liquidInput == null || leftGasOutput == null || rightGasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + SeparatorRecipe recipe = new SeparatorRecipe(InputHelper.toFluid(liquidInput), energy, GasHelper.toGas(leftGasOutput), GasHelper.toGas(rightGasOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient liquidInput, @Optional IIngredient leftGasInput, @Optional IIngredient rightGasInput) + { + if (liquidInput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (leftGasInput == null) + leftGasInput = IngredientAny.INSTANCE; + if (rightGasInput == null) + leftGasInput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get()).entrySet()) + { + ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().ingredient); + IGasStack outputItemLeft = new CraftTweakerGasStack(entry.getValue().recipeOutput.leftGas); + IGasStack outputItemRight = new CraftTweakerGasStack(entry.getValue().recipeOutput.rightGas); + + if (!StackHelper.matches(liquidInput, inputLiquid)) + continue; + if (!GasHelper.matches(leftGasInput, outputItemLeft)) + continue; + if (!GasHelper.matches(rightGasInput, outputItemRight)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, liquidInput.toString(), leftGasInput.toString(), rightGasInput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java new file mode 100644 index 000000000..19997217e --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java @@ -0,0 +1,79 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import com.blamejared.mtlib.helpers.LogHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.GasInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.SolarNeutronRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.solarneutronactivator") +public class SolarNeutronActivator +{ + public static final String NAME = "Mekanism Solar Neutron Activator"; + + @ZenMethod + public static void addRecipe(IGasStack gasInput, IGasStack gasOutput) + { + if (gasInput == null || gasOutput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + SolarNeutronRecipe recipe = new SolarNeutronRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient gasInput, @Optional IIngredient gasOutput) + { + if (gasInput == null) + { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if (gasOutput == null) + gasOutput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get()).entrySet()) + { + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if (!recipes.isEmpty()) + { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasInput.toString(), gasOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java new file mode 100644 index 000000000..696563815 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java @@ -0,0 +1,67 @@ +package mekanism.common.integration.crafttweaker.handlers; +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import crafttweaker.api.liquid.ILiquidStack; +import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.FluidInput; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.machines.ThermalEvaporationRecipe; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.HashMap; +import java.util.Map; + +@ZenClass("mods.mekanism.thermalevaporation") +public class ThermalEvaporation +{ + public static final String NAME = "Mekanism Solar Evaporation"; + + @ZenMethod + public static void addRecipe(ILiquidStack liquidInput, ILiquidStack liquidOutput) { + if(liquidInput == null || liquidOutput == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + ThermalEvaporationRecipe recipe = new ThermalEvaporationRecipe(InputHelper.toFluid(liquidInput), InputHelper.toFluid(liquidOutput)); + + CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), recipe)); + } + + @ZenMethod + public static void removeRecipe(IIngredient liquidInput, @Optional IIngredient liquidOutput) { + if(liquidInput == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); + return; + } + + if(liquidOutput == null) liquidOutput = IngredientAny.INSTANCE; + + Map recipes = new HashMap<>(); + + for(Map.Entry entry : ((Map) RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get()).entrySet() ) { + ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().ingredient); + ILiquidStack outputLiquid = InputHelper.toILiquidStack(entry.getValue().recipeOutput.output); + + if(!StackHelper.matches(liquidInput, inputLiquid)) continue; + if(!StackHelper.matches(liquidOutput, outputLiquid)) continue; + + recipes.put(entry.getKey(), entry.getValue()); + } + + if(!recipes.isEmpty()) { + CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), recipes)); + } else { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, liquidInput.toString(), liquidOutput.toString())); + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java new file mode 100644 index 000000000..7975556c6 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java @@ -0,0 +1,52 @@ +package mekanism.common.integration.crafttweaker.helpers; + +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import mekanism.api.gas.GasRegistry; +import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; + +public class GasHelper +{ + private GasHelper() + { + } + + public static boolean matches(IIngredient ingredient, IGasStack gasStack) + { + if (ingredient == null) + { + return false; + } + + if (ingredient == IngredientAny.INSTANCE) + { + return true; + } + + if (ingredient instanceof IGasStack) + { + return toGas((IGasStack) ingredient).isGasEqual(toGas(gasStack)); + } + + return false; + } + + public static GasStack toGas(IGasStack iStack) + { + if (iStack == null) + { + return null; + } + else + return new GasStack(GasRegistry.getGas(iStack.getName()), iStack.getAmount()); + } + + public static GasStack[] toGases(IGasStack[] iStack) + { + GasStack[] stack = new GasStack[iStack.length]; + for (int i = 0; i < stack.length; i++) + stack[i] = toGas(iStack[i]); + return stack; + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java b/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java new file mode 100644 index 000000000..ce50ab79c --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java @@ -0,0 +1,63 @@ +package mekanism.common.integration.crafttweaker.util; + +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.utils.BaseMapAddition; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.outputs.ChanceOutput; +import mekanism.common.recipe.outputs.ChemicalPairOutput; +import mekanism.common.recipe.outputs.FluidOutput; +import mekanism.common.recipe.outputs.GasOutput; +import mekanism.common.recipe.outputs.ItemStackOutput; +import mekanism.common.recipe.outputs.MachineOutput; +import mekanism.common.recipe.outputs.PressurizedOutput; + +import java.util.Map; + +public class AddMekanismRecipe extends BaseMapAddition +{ + public AddMekanismRecipe(String name, Map map, Map recipes) + { + super(name, map, recipes); + } + + public AddMekanismRecipe(String name, Map map, MachineRecipe recipe) + { + super(name, map); + + recipes.put(recipe.getInput(), recipe); + } + + @Override + protected String getRecipeInfo(Map.Entry recipe) + { + MachineOutput output = recipe.getValue().recipeOutput; + + if (output instanceof ItemStackOutput) + { + return LogHelper.getStackDescription(((ItemStackOutput) output).output); + } + else if (output instanceof GasOutput) + { + return LogHelper.getStackDescription(((GasOutput) output).output); + } + else if (output instanceof FluidOutput) + { + return LogHelper.getStackDescription(((FluidOutput) output).output); + } + else if (output instanceof ChemicalPairOutput) + { + return "[" + LogHelper.getStackDescription(((ChemicalPairOutput) output).leftGas) + ", " + LogHelper.getStackDescription(((ChemicalPairOutput) output).rightGas) + "]"; + } + else if (output instanceof ChanceOutput) + { + return LogHelper.getStackDescription(((ChanceOutput) output).primaryOutput); + } + else if (output instanceof PressurizedOutput) + { + return "[" + LogHelper.getStackDescription(((PressurizedOutput) output).getItemOutput()) + ", " + LogHelper.getStackDescription(((PressurizedOutput) output).getGasOutput()) + "]"; + } + + return null; + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java b/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java new file mode 100644 index 000000000..17c1897f3 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java @@ -0,0 +1,57 @@ +package mekanism.common.integration.crafttweaker.util; + +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.utils.BaseMapRemoval; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.outputs.ChanceOutput; +import mekanism.common.recipe.outputs.ChemicalPairOutput; +import mekanism.common.recipe.outputs.FluidOutput; +import mekanism.common.recipe.outputs.GasOutput; +import mekanism.common.recipe.outputs.ItemStackOutput; +import mekanism.common.recipe.outputs.MachineOutput; +import mekanism.common.recipe.outputs.PressurizedOutput; + +import java.util.Map; + +public class RemoveMekanismRecipe extends BaseMapRemoval +{ + public RemoveMekanismRecipe(String name, Map map, Map recipes) + { + super(name, map, recipes); + } + + + @Override + protected String getRecipeInfo(Map.Entry recipe) + { + MachineOutput output = recipe.getValue().recipeOutput; + + if (output instanceof ItemStackOutput) + { + return LogHelper.getStackDescription(((ItemStackOutput) output).output); + } + else if (output instanceof GasOutput) + { + return LogHelper.getStackDescription(((GasOutput) output).output); + } + else if (output instanceof FluidOutput) + { + return LogHelper.getStackDescription(((FluidOutput) output).output); + } + else if (output instanceof ChemicalPairOutput) + { + return "[" + LogHelper.getStackDescription(((ChemicalPairOutput) output).leftGas) + ", " + LogHelper.getStackDescription(((ChemicalPairOutput) output).rightGas) + "]"; + } + else if (output instanceof ChanceOutput) + { + return LogHelper.getStackDescription(((ChanceOutput) output).primaryOutput); + } + else if (output instanceof PressurizedOutput) + { + return "[" + LogHelper.getStackDescription(((PressurizedOutput) output).getItemOutput()) + ", " + LogHelper.getStackDescription(((PressurizedOutput) output).getGasOutput()) + "]"; + } + + return null; + } +} From 794f4c46da01396a04fc6cfd5327736122ed1527 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Sat, 19 Aug 2017 13:49:14 +0200 Subject: [PATCH 2/8] Move CraftTweaker apply to postinit. Fixes CraftTweaker removal of recipes not working due to load order. Mekanisms own recipes are added during init (right place), but CT happens before that. --- .../common/integration/MekanismHooks.java | 6 ++ .../crafttweaker/CrafttweakerIntegration.java | 26 ++++++ .../handlers/ChemicalCrystallizer.java | 56 ++++++++----- .../handlers/ChemicalDissolution.java | 55 +++++++++---- .../handlers/ChemicalInfuser.java | 64 ++++++++++----- .../handlers/ChemicalInjection.java | 62 ++++++++++----- .../handlers/ChemicalOxidizer.java | 55 +++++++++---- .../crafttweaker/handlers/ChemicalWasher.java | 55 +++++++++---- .../crafttweaker/handlers/Combiner.java | 64 ++++++++++----- .../crafttweaker/handlers/Compressor.java | 66 ++++++++++------ .../crafttweaker/handlers/Crusher.java | 55 +++++++++---- .../handlers/EnergizedSmelter.java | 55 +++++++++---- .../crafttweaker/handlers/Enrichment.java | 64 ++++++++++----- .../crafttweaker/handlers/Infuser.java | 63 ++++++++++----- .../crafttweaker/handlers/Purification.java | 63 ++++++++++----- .../crafttweaker/handlers/Reaction.java | 79 +++++++++++++------ .../crafttweaker/handlers/Sawmill.java | 64 ++++++++++----- .../crafttweaker/handlers/Separator.java | 64 ++++++++++----- .../handlers/SolarNeutronActivator.java | 56 ++++++++----- .../handlers/ThermalEvaporation.java | 44 ++++++++--- .../crafttweaker/util/AddMekanismRecipe.java | 19 +++-- .../util/RemoveMekanismRecipe.java | 15 +++- 22 files changed, 798 insertions(+), 352 deletions(-) create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java diff --git a/src/main/java/mekanism/common/integration/MekanismHooks.java b/src/main/java/mekanism/common/integration/MekanismHooks.java index 28765fccd..fa4dd3a5f 100644 --- a/src/main/java/mekanism/common/integration/MekanismHooks.java +++ b/src/main/java/mekanism/common/integration/MekanismHooks.java @@ -16,6 +16,7 @@ import mekanism.common.Resource; import mekanism.common.block.states.BlockStateTransmitter.TransmitterType; import mekanism.common.integration.computer.CCPeripheral; import mekanism.common.integration.computer.OCDriver; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.recipe.RecipeHandler; import mekanism.common.util.MekanismUtils; import net.minecraft.init.Items; @@ -91,6 +92,11 @@ public final class MekanismHooks { loadCCPeripheralProviders(); } + + if(Loader.isModLoaded("crafttweaker")) + { + CrafttweakerIntegration.apply(); + } } @Method(modid = MekanismHooks.IC2_MOD_ID) diff --git a/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java b/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java new file mode 100644 index 000000000..245636178 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java @@ -0,0 +1,26 @@ +package mekanism.common.integration.crafttweaker; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.IAction; + +import java.util.LinkedList; +import java.util.List; + +public class CrafttweakerIntegration +{ + public static final List LATE_REMOVALS = new LinkedList<>(); + public static final List LATE_ADDITIONS = new LinkedList<>(); + + /** + * Apply after (machine)recipes have been applied, but before the FMLLoadCompleteEvent is fired. + * Preferbly in (post)init. + * + * Applying to early causes remove to mallfunction as no recipes have been registered. + * Applying to late causes JEI to not pickup the changes. + */ + public static void apply() + { + LATE_REMOVALS.forEach(CraftTweakerAPI::apply); + LATE_ADDITIONS.forEach(CraftTweakerAPI::apply); + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java index 21020d5ed..8f99c496a 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java @@ -9,6 +9,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -44,7 +45,7 @@ public class ChemicalCrystallizer CrystallizerRecipe recipe = new CrystallizerRecipe(GasHelper.toGas(gasInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), recipe)); } @ZenMethod @@ -59,28 +60,47 @@ public class ChemicalCrystallizer if (gasInput == null) gasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), itemOutput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient gasInput) { - IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); - - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!GasHelper.matches(gasInput, inputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + super(name, map); + this.itemOutput = itemOutput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get()).entrySet()) + { + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java index c2c8ef44c..6b41f71b2 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java @@ -9,6 +9,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -44,7 +45,7 @@ public class ChemicalDissolution DissolutionRecipe recipe = new DissolutionRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), recipe)); } @ZenMethod @@ -59,28 +60,48 @@ public class ChemicalDissolution if (itemInput == null) itemInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), gasOutput, itemInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient gasOutput; + private IIngredient itemInput; + + public Remove(String name, Map map, IIngredient gasOutput, IIngredient itemInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); - IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!GasHelper.matches(gasOutput, outputGas)) - continue; - if (!StackHelper.matches(itemInput, inputItem)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.gasOutput = gasOutput; + this.itemInput = itemInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), itemInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), itemInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java index 0647d656d..ce504bc1b 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java @@ -1,11 +1,11 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.LogHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -41,7 +41,7 @@ public class ChemicalInfuser ChemicalInfuserRecipe recipe = new ChemicalInfuserRecipe(GasHelper.toGas(leftGasInput), GasHelper.toGas(rightGasInput), GasHelper.toGas(gasOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), recipe)); } @ZenMethod @@ -58,31 +58,53 @@ public class ChemicalInfuser if (rightGasInput == null) rightGasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), gasOutput, leftGasInput, rightGasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_INFUSER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient gasOutput; + private IIngredient leftGasInput; + private IIngredient rightGasInput; + + public Remove(String name, Map map, IIngredient gasOutput, IIngredient leftGasInput, IIngredient rightGasInput) { - IGasStack inputGasLeft = new CraftTweakerGasStack(entry.getKey().leftGas); - IGasStack inputGasRight = new CraftTweakerGasStack(entry.getKey().rightGas); - IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!GasHelper.matches(gasOutput, outputGas)) - continue; - if (!GasHelper.matches(leftGasInput, inputGasLeft)) - continue; - if (!GasHelper.matches(rightGasInput, inputGasRight)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.gasOutput = gasOutput; + this.leftGasInput = leftGasInput; + this.rightGasInput = rightGasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, gasOutput.toString(), leftGasInput.toString(), rightGasInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_INFUSER.get()).entrySet()) + { + IGasStack inputGasLeft = new CraftTweakerGasStack(entry.getKey().leftGas); + IGasStack inputGasRight = new CraftTweakerGasStack(entry.getKey().rightGas); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + if (!GasHelper.matches(leftGasInput, inputGasLeft)) + continue; + if (!GasHelper.matches(rightGasInput, inputGasRight)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, gasOutput.toString(), leftGasInput.toString(), rightGasInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java index 839d9e7a8..8b25304f2 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java @@ -10,6 +10,7 @@ import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -67,31 +68,52 @@ public class ChemicalInjection if (gasInput == null) gasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), itemOutput, itemInput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput, IIngredient gasInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); - IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); - - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!GasHelper.matches(gasInput, inputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + super(name, map); + this.itemOutput = itemOutput; + this.itemInput = itemInput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), itemInput.toString(), gasInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), itemInput.toString(), gasInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java index 5759d42c1..6c22e0463 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java @@ -7,6 +7,7 @@ import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -40,7 +41,7 @@ public class ChemicalOxidizer OxidationRecipe recipe = new OxidationRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), recipe)); } @ZenMethod @@ -55,28 +56,48 @@ public class ChemicalOxidizer if (itemInput == null) itemInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), gasOutput, itemInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient gasOutput; + private IIngredient itemInput; + + public Remove(String name, Map map, IIngredient gasOutput, IIngredient itemInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); - IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!GasHelper.matches(gasOutput, outputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.gasOutput = gasOutput; + this.itemInput = itemInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), itemInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), itemInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java index 8aeba4f05..850058017 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java @@ -6,6 +6,7 @@ import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -41,7 +42,7 @@ public class ChemicalWasher WasherRecipe recipe = new WasherRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), recipe)); } @ZenMethod @@ -56,28 +57,48 @@ public class ChemicalWasher if (gasInput == null) gasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), gasOutput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_WASHER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient gasOutput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient gasOutput, IIngredient gasInput) { - IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); - IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!GasHelper.matches(gasInput, inputGas)) - continue; - if (!GasHelper.matches(gasOutput, outputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.gasOutput = gasOutput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), gasInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CHEMICAL_WASHER.get()).entrySet()) + { + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasOutput.toString(), gasInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java index d4236b90d..409811013 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java @@ -10,6 +10,7 @@ import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -25,6 +26,7 @@ import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; +import javax.imageio.stream.IIOByteBuffer; import java.util.HashMap; import java.util.Map; @@ -48,7 +50,7 @@ public class Combiner ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); CombinerRecipe recipe = new CombinerRecipe(input, output); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); } @ZenMethod @@ -79,31 +81,53 @@ public class Combiner if (itemInput == null) itemInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.COMBINER.get(), itemOutput, itemInput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.COMBINER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput, IIngredient gasInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); - IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); + super(name, map); - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!GasHelper.matches(gasInput, inputGas)) - continue; - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemOutput = itemOutput; + this.itemInput = itemInput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemInput.toString(), gasInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.COMBINER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemInput.toString(), gasInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java index 01ea3996a..df37ae453 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java @@ -10,6 +10,7 @@ import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -46,10 +47,9 @@ public class Compressor OsmiumCompressorRecipe recipe = new OsmiumCompressorRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipe)); } - @SuppressWarnings("unchecked") @ZenMethod public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) { @@ -64,7 +64,7 @@ public class Compressor OsmiumCompressorRecipe recipe = new OsmiumCompressorRecipe(input, output); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipe)); } @ZenMethod @@ -81,31 +81,53 @@ public class Compressor if (gasInput == null) gasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), itemOutput, itemInput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput, IIngredient gasInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); - IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); + super(name, map); - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!GasHelper.matches(gasInput, inputGas)) - continue; - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemOutput = itemOutput; + this.itemInput = itemInput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemInput.toString(), gasInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemInput.toString(), gasInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java index 5c817f914..febe91445 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java @@ -9,6 +9,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; import mekanism.common.recipe.RecipeHandler; @@ -41,7 +42,7 @@ public class Crusher CrusherRecipe recipe = new CrusherRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipe)); } @ZenMethod @@ -56,28 +57,48 @@ public class Crusher if (itemInput == null) itemInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CRUSHER.get(), itemOutput, itemInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CRUSHER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!StackHelper.matches(itemInput, inputItem)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemOutput = itemOutput; + this.itemInput = itemInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.CRUSHER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java index 7a6e61778..aa872e540 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java @@ -9,6 +9,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; import mekanism.common.recipe.RecipeHandler; @@ -41,7 +42,7 @@ public class EnergizedSmelter SmeltingRecipe recipe = new SmeltingRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), recipe)); } @ZenMethod @@ -56,28 +57,48 @@ public class EnergizedSmelter if (itemOutput == null) itemOutput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), itemInput, itemOutput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ENERGIZED_SMELTER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemInput; + private IIngredient itemOutput; + + public Remove(String name, Map map, IIngredient itemInput, IIngredient itemOutput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemInput = itemInput; + this.itemOutput = itemOutput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ENERGIZED_SMELTER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java index 664dbfc3e..d933cb8a9 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java @@ -9,12 +9,13 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.inputs.ItemStackInput; import mekanism.common.recipe.inputs.MachineInput; -import mekanism.common.recipe.machines.CrusherRecipe; +import mekanism.common.recipe.machines.EnrichmentRecipe; import mekanism.common.recipe.machines.MachineRecipe; import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; @@ -39,41 +40,64 @@ public class Enrichment return; } - CrusherRecipe recipe = new CrusherRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); + EnrichmentRecipe recipe = new EnrichmentRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), recipe)); } @ZenMethod public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput) { - if(itemOutput == null) + if (itemOutput == null) { LogHelper.logError(String.format("Required parameters missing for %s recipe.", NAME)); } - if(itemInput == null) itemInput = IngredientAny.INSTANCE; + if (itemInput == null) + itemInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); - for(Map.Entry entry : ((Map) RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get()).entrySet()) + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), itemOutput, itemInput)); + } + + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); - - if(!StackHelper.matches(itemOutput, outputItem)) continue; - if(!StackHelper.matches(itemInput, inputItem)) continue; - - recipes.put(entry.getKey(), entry.getValue()); + super(name, map); + this.itemOutput = itemOutput; + this.itemInput = itemInput; } - if(!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java index 932c395a3..7b0239cab 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java @@ -10,6 +10,7 @@ import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import mekanism.api.infuse.InfuseRegistry; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; import mekanism.common.recipe.RecipeHandler; @@ -46,7 +47,7 @@ public class Infuser MetallurgicInfuserRecipe recipe = new MetallurgicInfuserRecipe(input, output); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), recipe)); } @ZenMethod @@ -63,31 +64,53 @@ public class Infuser if (infuseType == null) infuseType = ""; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), itemOutput, itemInput, infuseType)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.METALLURGIC_INFUSER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + private String infuseType; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput, String infuseType) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().inputStack); - String typeInfuse = entry.getKey().infuse.type.name; - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!infuseType.isEmpty() && !infuseType.equalsIgnoreCase(typeInfuse)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemOutput = itemOutput; + this.itemInput = itemInput; + this.infuseType = infuseType; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.METALLURGIC_INFUSER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().inputStack); + String typeInfuse = entry.getKey().infuse.type.name; + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!infuseType.isEmpty() && !infuseType.equalsIgnoreCase(typeInfuse)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java index cc05d3cfe..12403e748 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java @@ -10,6 +10,7 @@ import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -46,7 +47,7 @@ public class Purification PurificationRecipe recipe = new PurificationRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipe)); } @ZenMethod @@ -80,31 +81,53 @@ public class Purification if (gasInput == null) gasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), itemOutput, itemInput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PURIFICATION_CHAMBER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient itemInput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput, IIngredient gasInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); - IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + super(name, map); - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!GasHelper.matches(gasInput, inputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemOutput = itemOutput; + this.itemInput = itemInput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), itemInput.toString(), gasInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PURIFICATION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); + IGasStack inputGas = new CraftTweakerGasStack(new GasStack(entry.getKey().gasType, 1)); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.output); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), itemInput.toString(), gasInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java index c0c6cd3e8..af06505a6 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java @@ -10,6 +10,7 @@ import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import crafttweaker.api.liquid.ILiquidStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -50,7 +51,7 @@ public class Reaction PressurizedRecipe recipe = new PressurizedRecipe(input, output, energy, duration); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), recipe)); } @ZenMethod @@ -69,37 +70,63 @@ public class Reaction if (gasInput == null) gasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), itemOutput, gasOutput, itemInput, liquidInput, gasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemOutput; + private IIngredient gasOutput; + private IIngredient itemInput; + private IIngredient liquidInput; + private IIngredient gasInput; + + public Remove(String name, Map map, IIngredient itemOutput, IIngredient gasOutput, IIngredient itemInput, IIngredient liquidInput, IIngredient gasInput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().getSolid()); - ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().getFluid()); - IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().getGas()); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.getItemOutput()); - IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.getGasOutput()); + super(name, map); - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!StackHelper.matches(liquidInput, inputLiquid)) - continue; - if (!GasHelper.matches(gasInput, inputGas)) - continue; - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!GasHelper.matches(gasOutput, outputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + this.itemOutput = itemOutput; + this.gasOutput = gasOutput; + this.itemInput = itemInput; + this.liquidInput = liquidInput; + this.gasInput = gasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s, %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), gasOutput.toString(), itemInput.toString(), liquidInput.toString(), gasInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().getSolid()); + ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().getFluid()); + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().getGas()); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.getItemOutput()); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.getGasOutput()); + + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!StackHelper.matches(liquidInput, inputLiquid)) + continue; + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s, %s, %s and %s. Command ignored!", NAME, itemOutput.toString(), gasOutput.toString(), itemInput.toString(), liquidInput.toString(), gasInput.toString())); + } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java index f4b77289f..cc2577bde 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java @@ -9,6 +9,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; import mekanism.common.recipe.RecipeHandler; @@ -47,7 +48,7 @@ public class Sawmill SawmillRecipe recipe = new SawmillRecipe(input, output); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), recipe)); } @ZenMethod @@ -64,31 +65,52 @@ public class Sawmill if (optionalItemOutput == null) optionalItemOutput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), itemInput, itemOutput, optionalItemOutput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PRECISION_SAWMILL.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient itemInput; + private IIngredient itemOutput; + private IIngredient optionalItemOutput; + + public Remove(String name, Map map, IIngredient itemInput, IIngredient itemOutput, IIngredient optionalItemOutput) { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.primaryOutput); - IItemStack outputItemOptional = InputHelper.toIItemStack(entry.getValue().recipeOutput.secondaryOutput); - - if (!StackHelper.matches(itemOutput, outputItem)) - continue; - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!StackHelper.matches(optionalItemOutput, outputItemOptional)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + super(name, map); + this.itemInput = itemInput; + this.itemOutput = itemOutput; + this.optionalItemOutput = optionalItemOutput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.PRECISION_SAWMILL.get()).entrySet()) + { + IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().ingredient); + IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().recipeOutput.primaryOutput); + IItemStack outputItemOptional = InputHelper.toIItemStack(entry.getValue().recipeOutput.secondaryOutput); + + if (!StackHelper.matches(itemOutput, outputItem)) + continue; + if (!StackHelper.matches(itemInput, inputItem)) + continue; + if (!StackHelper.matches(optionalItemOutput, outputItemOptional)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, itemInput.toString(), itemOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java index 331be3f94..5fab418c2 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java @@ -9,6 +9,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; import crafttweaker.api.liquid.ILiquidStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -44,7 +45,7 @@ public class Separator SeparatorRecipe recipe = new SeparatorRecipe(InputHelper.toFluid(liquidInput), energy, GasHelper.toGas(leftGasOutput), GasHelper.toGas(rightGasOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), recipe)); } @ZenMethod @@ -61,31 +62,52 @@ public class Separator if (rightGasInput == null) leftGasInput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), liquidInput, leftGasInput, rightGasInput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient liquidInput; + private IIngredient leftGasInput; + private IIngredient rightGasInput; + + public Remove(String name, Map map, IIngredient liquidInput, IIngredient leftGasInput, IIngredient rightGasInput) { - ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().ingredient); - IGasStack outputItemLeft = new CraftTweakerGasStack(entry.getValue().recipeOutput.leftGas); - IGasStack outputItemRight = new CraftTweakerGasStack(entry.getValue().recipeOutput.rightGas); - - if (!StackHelper.matches(liquidInput, inputLiquid)) - continue; - if (!GasHelper.matches(leftGasInput, outputItemLeft)) - continue; - if (!GasHelper.matches(rightGasInput, outputItemRight)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + super(name, map); + this.liquidInput = liquidInput; + this.leftGasInput = leftGasInput; + this.rightGasInput = rightGasInput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, liquidInput.toString(), leftGasInput.toString(), rightGasInput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get()).entrySet()) + { + ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().ingredient); + IGasStack outputItemLeft = new CraftTweakerGasStack(entry.getValue().recipeOutput.leftGas); + IGasStack outputItemRight = new CraftTweakerGasStack(entry.getValue().recipeOutput.rightGas); + + if (!StackHelper.matches(liquidInput, inputLiquid)) + continue; + if (!GasHelper.matches(leftGasInput, outputItemLeft)) + continue; + if (!GasHelper.matches(rightGasInput, outputItemRight)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s, %s and %s. Command ignored!", NAME, liquidInput.toString(), leftGasInput.toString(), rightGasInput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java index 19997217e..538556cb8 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java @@ -4,6 +4,7 @@ import com.blamejared.mtlib.helpers.LogHelper; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.helpers.GasHelper; @@ -37,7 +38,7 @@ public class SolarNeutronActivator SolarNeutronRecipe recipe = new SolarNeutronRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), recipe)); } @ZenMethod @@ -52,28 +53,47 @@ public class SolarNeutronActivator if (gasOutput == null) gasOutput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), gasInput, gasOutput)); + } - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get()).entrySet()) + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient gasInput; + private IIngredient gasOutput; + + public Remove(String name, Map map, IIngredient gasInput, IIngredient gasOutput) { - IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); - IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); - - if (!GasHelper.matches(gasInput, inputGas)) - continue; - if (!GasHelper.matches(gasOutput, outputGas)) - continue; - - recipes.put(entry.getKey(), entry.getValue()); + super(name, map); + this.gasInput = gasInput; + this.gasOutput = gasOutput; } - if (!recipes.isEmpty()) + @Override + public void addRecipes() { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), recipes)); - } - else - { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasInput.toString(), gasOutput.toString())); + Map recipesToRemove = new HashMap<>(); + + for (Map.Entry entry : ((Map) RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get()).entrySet()) + { + IGasStack inputGas = new CraftTweakerGasStack(entry.getKey().ingredient); + IGasStack outputGas = new CraftTweakerGasStack(entry.getValue().recipeOutput.output); + + if (!GasHelper.matches(gasInput, inputGas)) + continue; + if (!GasHelper.matches(gasOutput, outputGas)) + continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if (!recipesToRemove.isEmpty()) + { + recipes.putAll(recipesToRemove); + } + else + { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, gasInput.toString(), gasOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java index 696563815..9233a9291 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java @@ -6,6 +6,7 @@ import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; import crafttweaker.api.liquid.ILiquidStack; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; import mekanism.common.recipe.RecipeHandler; @@ -34,7 +35,7 @@ public class ThermalEvaporation ThermalEvaporationRecipe recipe = new ThermalEvaporationRecipe(InputHelper.toFluid(liquidInput), InputHelper.toFluid(liquidOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), recipe)); } @ZenMethod @@ -46,22 +47,41 @@ public class ThermalEvaporation if(liquidOutput == null) liquidOutput = IngredientAny.INSTANCE; - Map recipes = new HashMap<>(); - for(Map.Entry entry : ((Map) RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get()).entrySet() ) { - ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().ingredient); - ILiquidStack outputLiquid = InputHelper.toILiquidStack(entry.getValue().recipeOutput.output); + } - if(!StackHelper.matches(liquidInput, inputLiquid)) continue; - if(!StackHelper.matches(liquidOutput, outputLiquid)) continue; + private static class Remove extends RemoveMekanismRecipe + { + private IIngredient liquidInput; + private IIngredient liquidOutput; - recipes.put(entry.getKey(), entry.getValue()); + public Remove(String name, Map map, IIngredient liquidInput, IIngredient liquidOutput) + { + super(name, map); + this.liquidInput = liquidInput; + this.liquidOutput = liquidOutput; } - if(!recipes.isEmpty()) { - CraftTweakerAPI.apply(new RemoveMekanismRecipe(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), recipes)); - } else { - LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, liquidInput.toString(), liquidOutput.toString())); + @Override + public void addRecipes() + { + Map recipesToRemove = new HashMap<>(); + + for(Map.Entry entry : ((Map) RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get()).entrySet() ) { + ILiquidStack inputLiquid = InputHelper.toILiquidStack(entry.getKey().ingredient); + ILiquidStack outputLiquid = InputHelper.toILiquidStack(entry.getValue().recipeOutput.output); + + if(!StackHelper.matches(liquidInput, inputLiquid)) continue; + if(!StackHelper.matches(liquidOutput, outputLiquid)) continue; + + recipesToRemove.put(entry.getKey(), entry.getValue()); + } + + if(!recipesToRemove.isEmpty()) { + recipes.putAll(recipesToRemove); + } else { + LogHelper.logWarning(String.format("No %s recipe found for %s and %s. Command ignored!", NAME, liquidInput.toString(), liquidOutput.toString())); + } } } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java b/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java index ce50ab79c..90da48aeb 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java @@ -16,16 +16,25 @@ import java.util.Map; public class AddMekanismRecipe extends BaseMapAddition { - public AddMekanismRecipe(String name, Map map, Map recipes) - { - super(name, map, recipes); - } + private MachineRecipe recipe; public AddMekanismRecipe(String name, Map map, MachineRecipe recipe) { super(name, map); + this.recipe = recipe; + } - recipes.put(recipe.getInput(), recipe); + public void addRecipes() + { + this.recipes.put(recipe.getInput(), recipe); + } + + @Override + public void apply() + { + addRecipes(); + + super.apply(); } @Override diff --git a/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java b/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java index 17c1897f3..f895762a4 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java @@ -14,13 +14,22 @@ import mekanism.common.recipe.outputs.PressurizedOutput; import java.util.Map; -public class RemoveMekanismRecipe extends BaseMapRemoval +public abstract class RemoveMekanismRecipe extends BaseMapRemoval { - public RemoveMekanismRecipe(String name, Map map, Map recipes) + public RemoveMekanismRecipe(String name, Map map) { - super(name, map, recipes); + super(name, map); } + public abstract void addRecipes(); + + @Override + public void apply() + { + addRecipes(); + + super.apply(); + } @Override protected String getRecipeInfo(Map.Entry recipe) From 6c6e9e22dbe4db268778ced0efbbfa208033d4c9 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Sat, 19 Aug 2017 14:02:25 +0200 Subject: [PATCH 3/8] Fix some missed CraftTweaker statements.. --- .../crafttweaker/handlers/ChemicalCrystallizer.java | 1 - .../crafttweaker/handlers/ChemicalDissolution.java | 1 - .../integration/crafttweaker/handlers/ChemicalInjection.java | 3 +-- .../integration/crafttweaker/handlers/ChemicalOxidizer.java | 1 - .../integration/crafttweaker/handlers/ChemicalWasher.java | 1 - .../common/integration/crafttweaker/handlers/Combiner.java | 4 +--- .../common/integration/crafttweaker/handlers/Compressor.java | 1 - .../common/integration/crafttweaker/handlers/Crusher.java | 1 - .../integration/crafttweaker/handlers/EnergizedSmelter.java | 1 - .../common/integration/crafttweaker/handlers/Enrichment.java | 1 - .../common/integration/crafttweaker/handlers/Infuser.java | 1 - .../integration/crafttweaker/handlers/Purification.java | 3 +-- .../common/integration/crafttweaker/handlers/Reaction.java | 1 - .../common/integration/crafttweaker/handlers/Sawmill.java | 1 - .../common/integration/crafttweaker/handlers/Separator.java | 1 - .../crafttweaker/handlers/SolarNeutronActivator.java | 1 - .../integration/crafttweaker/handlers/ThermalEvaporation.java | 4 ++-- 17 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java index 8f99c496a..6d038884f 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java index 6b41f71b2..8daa55493 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java index 8b25304f2..474281a83 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; @@ -51,7 +50,7 @@ public class ChemicalInjection InjectionRecipe recipe = new InjectionRecipe(input, output); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), recipe)); } @ZenMethod diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java index 6c22e0463..074f4c234 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java index 850058017..ddd864379 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java @@ -1,7 +1,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.LogHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java index 409811013..65f5982b9 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; @@ -26,7 +25,6 @@ import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; -import javax.imageio.stream.IIOByteBuffer; import java.util.HashMap; import java.util.Map; @@ -64,7 +62,7 @@ public class Combiner CombinerRecipe recipe = new CombinerRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); } @ZenMethod diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java index df37ae453..e58d760db 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java index febe91445..20bc28beb 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java index aa872e540..534f22fbc 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java index d933cb8a9..da54bc7c4 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java index 7b0239cab..fa7d387ff 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java index 12403e748..85b35ee48 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; @@ -64,7 +63,7 @@ public class Purification PurificationRecipe recipe = new PurificationRecipe(input, output); - CraftTweakerAPI.apply(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipe)); + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), recipe)); } @ZenMethod diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java index af06505a6..56308a9d7 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java index cc2577bde..4e9924485 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java index 5fab418c2..9bac88a62 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java @@ -3,7 +3,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java index 538556cb8..3669d823c 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java @@ -1,7 +1,6 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.LogHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java index 9233a9291..bdcae392d 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java @@ -1,8 +1,8 @@ package mekanism.common.integration.crafttweaker.handlers; + import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; -import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; import crafttweaker.api.liquid.ILiquidStack; @@ -47,7 +47,7 @@ public class ThermalEvaporation if(liquidOutput == null) liquidOutput = IngredientAny.INSTANCE; - + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), liquidInput, liquidOutput)); } private static class Remove extends RemoveMekanismRecipe From 29e31e5b1b00e140ae317c1d244bf397b43cbf75 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Sat, 19 Aug 2017 17:52:50 +0200 Subject: [PATCH 4/8] Add missing brackethandler for crafttweaker --- .../crafttweaker/gas/GasBracketHandler.java | 104 ++++++++++++++++++ .../crafttweaker/gas/IGasDefinition.java | 4 + .../crafttweaker/gas/IGasStack.java | 4 + .../handlers/ChemicalCrystallizer.java | 2 +- .../handlers/ChemicalOxidizer.java | 4 + .../crafttweaker/handlers/Enrichment.java | 12 +- .../handlers/SolarNeutronActivator.java | 4 + .../handlers/ThermalEvaporation.java | 4 + 8 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java new file mode 100644 index 000000000..37da770ae --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java @@ -0,0 +1,104 @@ +package mekanism.common.integration.crafttweaker.gas; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.BracketHandler; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IngredientAny; +import crafttweaker.zenscript.IBracketHandler; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasRegistry; +import mekanism.api.gas.GasStack; +import stanhebben.zenscript.compiler.IEnvironmentGlobal; +import stanhebben.zenscript.expression.ExpressionCallStatic; +import stanhebben.zenscript.expression.ExpressionString; +import stanhebben.zenscript.expression.partial.IPartialExpression; +import stanhebben.zenscript.parser.Token; +import stanhebben.zenscript.symbols.IZenSymbol; +import stanhebben.zenscript.type.natives.IJavaMethod; +import stanhebben.zenscript.util.ZenPosition; + +import java.util.List; + +@BracketHandler(priority = 100) +@ModOnly("mtlib") +@ZenRegister +public class GasBracketHandler implements IBracketHandler +{ + private final IZenSymbol symbolAny; + private final IJavaMethod method; + + public GasBracketHandler() + { + this.symbolAny = CraftTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE"); + this.method = CraftTweakerAPI.getJavaMethod(GasBracketHandler.class, "getGas", String.class); + } + + @Override + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) + { + if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) + { + return symbolAny; + } + + if (tokens.size() > 2) + { + if (tokens.get(0).getValue().equals("gas") && tokens.get(1).getValue().equals(":")) + { + return find(environment, tokens, 2, tokens.size()); + } + } + + return null; + } + + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex) + { + StringBuilder valueBuilder = new StringBuilder(); + for (int i = startIndex; i < endIndex; i++) + { + Token token = tokens.get(i); + valueBuilder.append(token.getValue()); + } + + Gas gas = GasRegistry.getGas(valueBuilder.toString()); + if (gas != null) + { + return new GasReferenceSymbol(environment, valueBuilder.toString()); + } + + return null; + } + + private class GasReferenceSymbol implements IZenSymbol + { + private final IEnvironmentGlobal environment; + private final String name; + + public GasReferenceSymbol(IEnvironmentGlobal environment, String name) + { + this.environment = environment; + this.name = name; + } + + @Override + public IPartialExpression instance(ZenPosition zenPosition) + { + return new ExpressionCallStatic(zenPosition, environment, method, new ExpressionString(zenPosition, name)); + } + } + + public static IGasStack getGas(String name) + { + Gas gas = GasRegistry.getGas(name); + if (gas != null) + { + return new CraftTweakerGasStack(new GasStack(gas, 1)); + } + else + { + return null; + } + } +} diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java index 4584b0722..4a581ec36 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java @@ -1,11 +1,15 @@ package mekanism.common.integration.crafttweaker.gas; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; import stanhebben.zenscript.annotations.OperatorType; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenOperator; @ZenClass("mod.mekanism.gas.IGasDefinition") +@ModOnly("mtlib") +@ZenRegister public interface IGasDefinition { @ZenOperator(OperatorType.MUL) diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java index 029c084c8..20feb1cce 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java @@ -1,5 +1,7 @@ package mekanism.common.integration.crafttweaker.gas; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import stanhebben.zenscript.annotations.OperatorType; import stanhebben.zenscript.annotations.ZenClass; @@ -8,6 +10,8 @@ import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenOperator; @ZenClass("mod.mekanism.gas.IGasStack") +@ModOnly("mtlib") +@ZenRegister public interface IGasStack extends IIngredient { @ZenGetter("definition") diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java index 6d038884f..3eea8f873 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java @@ -26,7 +26,7 @@ import stanhebben.zenscript.annotations.ZenMethod; import java.util.HashMap; import java.util.Map; -@ZenClass("mods.mekanism.crystallizer") +@ZenClass("mods.mekanism.chemical.crystallizer") @ModOnly("mtlib") @ZenRegister public class ChemicalCrystallizer diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java index 074f4c234..545c4a922 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java @@ -3,6 +3,8 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; @@ -25,6 +27,8 @@ import java.util.HashMap; import java.util.Map; @ZenClass("mods.mekanism.chemical.oxidizer") +@ModOnly("mtlib") +@ZenRegister public class ChemicalOxidizer { public static final String NAME = "Mekanism Chemical Oxidizer"; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java index da54bc7c4..eaf38d749 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java @@ -45,18 +45,18 @@ public class Enrichment } @ZenMethod - public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput) + public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput) { - if (itemOutput == null) + if (itemInput == null) { LogHelper.logError(String.format("Required parameters missing for %s recipe.", NAME)); } - if (itemInput == null) - itemInput = IngredientAny.INSTANCE; + if (itemOutput == null) + itemOutput = IngredientAny.INSTANCE; - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), itemOutput, itemInput)); + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), itemInput, itemOutput)); } private static class Remove extends RemoveMekanismRecipe @@ -64,7 +64,7 @@ public class Enrichment private IIngredient itemOutput; private IIngredient itemInput; - public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput) + public Remove(String name, Map map, IIngredient itemInput, IIngredient itemOutput) { super(name, map); this.itemOutput = itemOutput; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java index 3669d823c..7a6025228 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java @@ -1,6 +1,8 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.LogHelper; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; @@ -22,6 +24,8 @@ import java.util.HashMap; import java.util.Map; @ZenClass("mods.mekanism.solarneutronactivator") +@ModOnly("mtlib") +@ZenRegister public class SolarNeutronActivator { public static final String NAME = "Mekanism Solar Neutron Activator"; diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java index bdcae392d..f4431485e 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java @@ -3,6 +3,8 @@ package mekanism.common.integration.crafttweaker.handlers; import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IngredientAny; import crafttweaker.api.liquid.ILiquidStack; @@ -22,6 +24,8 @@ import java.util.HashMap; import java.util.Map; @ZenClass("mods.mekanism.thermalevaporation") +@ModOnly("mtlib") +@ZenRegister public class ThermalEvaporation { public static final String NAME = "Mekanism Solar Evaporation"; From 63fff888ce23e4e76bb394fd81a3607acc82b070 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Sat, 19 Aug 2017 18:09:13 +0200 Subject: [PATCH 5/8] Hook after oredict did it's thing. Allowes CraftTweaker to modify all te recipes added by the OreDict manager. --- src/main/java/mekanism/common/Mekanism.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 8545be92b..7837ad289 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -817,12 +817,11 @@ public class Mekanism { logger.info("Fake player readout: UUID = " + gameProfile.getId().toString() + ", name = " + gameProfile.getName()); + OreDictManager.init(); hooks.hook(); MinecraftForge.EVENT_BUS.post(new BoxBlacklistEvent()); - OreDictManager.init(); - logger.info("Hooking complete."); } From 0b61278d560697f8af6d9296505e9fbb41ec36f4 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Sun, 20 Aug 2017 13:15:13 +0200 Subject: [PATCH 6/8] Update method name to applyRecipeChanges --- src/main/java/mekanism/common/integration/MekanismHooks.java | 2 +- .../integration/crafttweaker/CrafttweakerIntegration.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/mekanism/common/integration/MekanismHooks.java b/src/main/java/mekanism/common/integration/MekanismHooks.java index fa4dd3a5f..1d9fa4ad8 100644 --- a/src/main/java/mekanism/common/integration/MekanismHooks.java +++ b/src/main/java/mekanism/common/integration/MekanismHooks.java @@ -95,7 +95,7 @@ public final class MekanismHooks if(Loader.isModLoaded("crafttweaker")) { - CrafttweakerIntegration.apply(); + CrafttweakerIntegration.applyRecipeChanges(); } } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java b/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java index 245636178..a9eae136a 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java @@ -18,7 +18,7 @@ public class CrafttweakerIntegration * Applying to early causes remove to mallfunction as no recipes have been registered. * Applying to late causes JEI to not pickup the changes. */ - public static void apply() + public static void applyRecipeChanges() { LATE_REMOVALS.forEach(CraftTweakerAPI::apply); LATE_ADDITIONS.forEach(CraftTweakerAPI::apply); From 077d6fe34eaa4c999078f310ed7f335bdd009557 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Mon, 21 Aug 2017 19:33:31 +0200 Subject: [PATCH 7/8] Fix wildcard check crafttweaker --- src/main/java/mekanism/common/util/StackUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mekanism/common/util/StackUtils.java b/src/main/java/mekanism/common/util/StackUtils.java index c69ed2dde..534c9a4c7 100644 --- a/src/main/java/mekanism/common/util/StackUtils.java +++ b/src/main/java/mekanism/common/util/StackUtils.java @@ -61,7 +61,7 @@ public final class StackUtils return check == wild; } - return wild.getItem() == check.getItem() && (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE || wild.getItemDamage() == check.getItemDamage()); + return wild.getItem() == check.getItem() && (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE || check.getItemDamage() == OreDictionary.WILDCARD_VALUE || wild.getItemDamage() == check.getItemDamage()); } public static boolean equalsWildcardWithNBT(ItemStack wild, ItemStack check) From 9efd716ea0408856c5ef2fdd1f53def57e8eb779 Mon Sep 17 00:00:00 2001 From: Tom Elfring Date: Wed, 23 Aug 2017 19:25:39 +0200 Subject: [PATCH 8/8] Add wildcard support to more recipes Added wildcard for: - AdvancedmachineInput - InfusionInput - PressurizedInput --- .../mekanism/common/recipe/RecipeHandler.java | 18 ++++++++++++++++++ .../recipe/inputs/AdvancedMachineInput.java | 6 ++++++ .../common/recipe/inputs/InfusionInput.java | 6 ++++++ .../common/recipe/inputs/PressurizedInput.java | 6 ++++++ 4 files changed, 36 insertions(+) diff --git a/src/main/java/mekanism/common/recipe/RecipeHandler.java b/src/main/java/mekanism/common/recipe/RecipeHandler.java index 67ff6a009..8f5a8d9f0 100644 --- a/src/main/java/mekanism/common/recipe/RecipeHandler.java +++ b/src/main/java/mekanism/common/recipe/RecipeHandler.java @@ -287,6 +287,12 @@ public final class RecipeHandler HashMap recipes = Recipe.METALLURGIC_INFUSER.get(); MetallurgicInfuserRecipe recipe = recipes.get(input); + + if(recipe == null) + { + recipe = recipes.get(input.wildCopy()); + } + return recipe == null ? null : recipe.copy(); } @@ -427,6 +433,12 @@ public final class RecipeHandler if(input.isValid()) { RECIPE recipe = recipes.get(input); + + if(recipe == null) + { + recipe = recipes.get(input.wildCopy()); + } + return recipe == null ? null : recipe.copy(); } @@ -484,6 +496,12 @@ public final class RecipeHandler HashMap recipes = Recipe.PRESSURIZED_REACTION_CHAMBER.get(); PressurizedRecipe recipe = recipes.get(input); + + if(recipe == null) + { + recipe = recipes.get(input.wildCopy()); + } + return recipe == null ? null : recipe.copy(); } diff --git a/src/main/java/mekanism/common/recipe/inputs/AdvancedMachineInput.java b/src/main/java/mekanism/common/recipe/inputs/AdvancedMachineInput.java index f43e3e2a3..7a3977a74 100644 --- a/src/main/java/mekanism/common/recipe/inputs/AdvancedMachineInput.java +++ b/src/main/java/mekanism/common/recipe/inputs/AdvancedMachineInput.java @@ -7,6 +7,7 @@ import mekanism.common.util.StackUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; +import net.minecraftforge.oredict.OreDictionary; public class AdvancedMachineInput extends MachineInput { @@ -94,4 +95,9 @@ public class AdvancedMachineInput extends MachineInput { return other instanceof AdvancedMachineInput; } + + public AdvancedMachineInput wildCopy() + { + return new AdvancedMachineInput(new ItemStack(itemStack.getItem(), itemStack.getCount(), OreDictionary.WILDCARD_VALUE), gasType); + } } diff --git a/src/main/java/mekanism/common/recipe/inputs/InfusionInput.java b/src/main/java/mekanism/common/recipe/inputs/InfusionInput.java index 41919c75d..4e97f9771 100644 --- a/src/main/java/mekanism/common/recipe/inputs/InfusionInput.java +++ b/src/main/java/mekanism/common/recipe/inputs/InfusionInput.java @@ -8,6 +8,7 @@ import mekanism.common.util.StackUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; +import net.minecraftforge.oredict.OreDictionary; /** * An infusion input, containing the type of and amount of infuse the operation requires, as well as the input ItemStack. @@ -94,4 +95,9 @@ public class InfusionInput extends MachineInput { return other instanceof InfusionInput; } + + public InfusionInput wildCopy() + { + return new InfusionInput(infuse, new ItemStack(inputStack.getItem(), inputStack.getCount(), OreDictionary.WILDCARD_VALUE)); + } } diff --git a/src/main/java/mekanism/common/recipe/inputs/PressurizedInput.java b/src/main/java/mekanism/common/recipe/inputs/PressurizedInput.java index 46eb15af7..9f019f5c6 100644 --- a/src/main/java/mekanism/common/recipe/inputs/PressurizedInput.java +++ b/src/main/java/mekanism/common/recipe/inputs/PressurizedInput.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.oredict.OreDictionary; /** * An input of a gas, a fluid and an item for the pressurized reaction chamber @@ -165,4 +166,9 @@ public class PressurizedInput extends MachineInput { return other instanceof PressurizedInput; } + + public PressurizedInput wildCopy() + { + return new PressurizedInput(new ItemStack(theSolid.getItem(), theSolid.getCount(), OreDictionary.WILDCARD_VALUE), theFluid, theGas); + } }