From fb14fba251b98ca9555444a3093215a359d451c4 Mon Sep 17 00:00:00 2001 From: pupnewfster Date: Wed, 6 Mar 2019 19:22:07 -0500 Subject: [PATCH] Cleanup CraftTweaker integration code --- build.properties | 2 +- .../crafttweaker/CrafttweakerIntegration.java | 37 ++--- .../gas/CraftTweakerGasDefinition.java | 19 +-- .../gas/CraftTweakerGasStack.java | 134 ++++++++---------- .../crafttweaker/gas/GasBracketHandler.java | 58 ++------ .../crafttweaker/gas/IGasDefinition.java | 4 +- .../crafttweaker/gas/IGasStack.java | 11 +- .../handlers/ChemicalCrystallizer.java | 87 ++---------- .../handlers/ChemicalDissolution.java | 88 ++---------- .../handlers/ChemicalInfuser.java | 94 ++---------- .../handlers/ChemicalInjection.java | 99 ++----------- .../handlers/ChemicalOxidizer.java | 88 ++---------- .../crafttweaker/handlers/ChemicalWasher.java | 87 ++---------- .../crafttweaker/handlers/Combiner.java | 110 +++----------- .../crafttweaker/handlers/Compressor.java | 113 +++------------ .../crafttweaker/handlers/Crusher.java | 87 ++---------- .../handlers/EnergizedSmelter.java | 97 +++---------- .../crafttweaker/handlers/Enrichment.java | 87 ++---------- .../crafttweaker/handlers/Infuser.java | 96 ++----------- .../crafttweaker/handlers/Purification.java | 113 +++------------ .../crafttweaker/handlers/Reaction.java | 112 ++------------- .../crafttweaker/handlers/Sawmill.java | 97 ++----------- .../crafttweaker/handlers/Separator.java | 94 ++---------- .../handlers/SolarNeutronActivator.java | 86 ++--------- .../handlers/ThermalEvaporation.java | 71 ++-------- .../crafttweaker/helpers/GasHelper.java | 36 ++--- .../helpers/IngredientHelper.java | 125 ++++++++++++++++ .../helpers/RecipeInfoHelper.java | 33 +++++ .../crafttweaker/util/AddMekanismRecipe.java | 69 ++------- .../crafttweaker/util/IngredientWrapper.java | 82 +++++++++++ .../util/RemoveMekanismRecipe.java | 87 +++++------- 31 files changed, 651 insertions(+), 1752 deletions(-) create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java create mode 100644 src/main/java/mekanism/common/integration/crafttweaker/util/IngredientWrapper.java diff --git a/build.properties b/build.properties index 872b3555a..58e085e45 100644 --- a/build.properties +++ b/build.properties @@ -11,7 +11,7 @@ redstoneflux_version=2.0.1.2 buildcraft_version=7.99.12 ctm_version=0.2.1.5 ic2_version=2.8.9-ex112 -crafttweaker_version=4.0.9.289 +crafttweaker_version=4.1.15.527 mtlib_version=3.0.1.3 computercraft_version=1.80pr1 top_version=1.12-1.4.19-11 diff --git a/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java b/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java index 34f1ffac2..92b50050f 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/CrafttweakerIntegration.java @@ -7,38 +7,31 @@ import mekanism.common.Mekanism; import java.util.LinkedList; import java.util.List; -public class CrafttweakerIntegration -{ +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. + * Preferably in (post)init. + *

+ * Applying to early causes remove to malfunction as no recipes have been registered. * Applying to late causes JEI to not pickup the changes. */ - public static void applyRecipeChanges() - { - // Remove before addition, so recipes can be overwritten - LATE_REMOVALS.forEach(action->{ - try - { + public static void applyRecipeChanges() { + //Remove before addition, so recipes can be overwritten + applyChanges(LATE_REMOVALS); + applyChanges(LATE_ADDITIONS); + } + + private static void applyChanges(List actions) { + actions.forEach(action -> { + try { CraftTweakerAPI.apply(action); - } catch (Exception e){ - Mekanism.logger.error("CT action failed", e); - CraftTweakerAPI.logError("Mekanism CT action failed", e); - } - }); - LATE_ADDITIONS.forEach(action->{ - try - { - CraftTweakerAPI.apply(action); - } catch (Exception e){ + } catch (Exception e) { Mekanism.logger.error("CT action failed", e); CraftTweakerAPI.logError("Mekanism CT action failed", e); } }); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java index 7c33fee31..e2ab452da 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasDefinition.java @@ -3,30 +3,25 @@ package mekanism.common.integration.crafttweaker.gas; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; -public class CraftTweakerGasDefinition implements IGasDefinition -{ +public class CraftTweakerGasDefinition implements IGasDefinition { private final Gas gas; - public CraftTweakerGasDefinition(Gas gas) - { + public CraftTweakerGasDefinition(Gas gas) { this.gas = gas; } @Override - public IGasStack asStack(int millibuckets) - { - return new CraftTweakerGasStack(new GasStack(gas, millibuckets)); + public IGasStack asStack(int mb) { + return new CraftTweakerGasStack(new GasStack(gas, mb)); } @Override - public String getName() - { + public String getName() { return gas.getName(); } @Override - public String getDisplayName() - { + public String getDisplayName() { return gas.getLocalizedName(); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java index 408f09577..998f4228c 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/CraftTweakerGasStack.java @@ -1,154 +1,146 @@ 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.item.*; import crafttweaker.api.liquid.ILiquidStack; import crafttweaker.api.player.IPlayer; import mekanism.api.gas.GasStack; import java.util.List; -public class CraftTweakerGasStack implements IGasStack -{ +public class CraftTweakerGasStack implements IGasStack { private final GasStack stack; - public CraftTweakerGasStack(GasStack stack) - { + public CraftTweakerGasStack(GasStack stack) { this.stack = stack; } - @Override - public IGasDefinition getDefinition() - { + public IGasDefinition getDefinition() { return new CraftTweakerGasDefinition(stack.getGas()); } @Override - public String getName() - { + public String getName() { return stack.getGas().getName(); } @Override - public String getDisplayName() - { + public String getDisplayName() { return stack.getGas().getLocalizedName(); } @Override - public String getMark() - { + public String getMark() { return null; } @Override - public int getAmount() - { + public int getAmount() { return stack.amount; } @Override - public List getItems() - { + public List getItems() { return null; } @Override - public IItemStack[] getItemArray() - { + public IItemStack[] getItemArray() { return new IItemStack[0]; } @Override - public List getLiquids() - { + public List getLiquids() { return null; } @Override - public IIngredient amount(int amount) - { + public IIngredient amount(int amount) { return withAmount(amount); } @Override - public IIngredient or(IIngredient iIngredient) - { + public IIngredient or(IIngredient iIngredient) { return null; } @Override - public IIngredient transform(IItemTransformer iItemTransformer) - { + public IIngredient transformNew(IItemTransformerNew transformer) { return null; } @Override - public IIngredient only(IItemCondition iItemCondition) - { + public IIngredient transform(IItemTransformer iItemTransformer) { return null; } @Override - public IIngredient marked(String s) - { + public IIngredient only(IItemCondition iItemCondition) { 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) - { + public IIngredient marked(String s) { return null; } @Override - public boolean hasTransformers() - { + public boolean matches(IItemStack iItemStack) { return false; } @Override - public IGasStack withAmount(int amount) - { + 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 IItemStack applyNewTransform(IItemStack item) { + return null; + } + + @Override + public boolean hasNewTransformers() { + return false; + } + + @Override + public boolean hasTransformers() { + return false; + } + + @Override + public IGasStack withAmount(int amount) { return new CraftTweakerGasStack(new GasStack(stack.getGas(), amount)); } @Override - public Object getInternal() - { - return null; + public Object getInternal() { + return stack; } @Override - public String toString() - { + public String toCommandString() { + return toString(); + } + + @Override + public String toString() { return String.format("", stack.getGas().getName(), stack.amount); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java b/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java index 37da770ae..b2bd0031d 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/GasBracketHandler.java @@ -23,82 +23,54 @@ import java.util.List; @BracketHandler(priority = 100) @ModOnly("mtlib") @ZenRegister -public class GasBracketHandler implements IBracketHandler -{ +public class GasBracketHandler implements IBracketHandler { private final IZenSymbol symbolAny; private final IJavaMethod method; - public GasBracketHandler() - { + 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("*")) - { + 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()); - } + if (tokens.size() > 2 && 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) - { + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex) { StringBuilder valueBuilder = new StringBuilder(); - for (int i = startIndex; i < endIndex; i++) - { + 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; + return gas == null ? null : new GasReferenceSymbol(environment, valueBuilder.toString()); } - private class GasReferenceSymbol implements IZenSymbol - { + private class GasReferenceSymbol implements IZenSymbol { private final IEnvironmentGlobal environment; private final String name; - public GasReferenceSymbol(IEnvironmentGlobal environment, String name) - { + public GasReferenceSymbol(IEnvironmentGlobal environment, String name) { this.environment = environment; this.name = name; } @Override - public IPartialExpression instance(ZenPosition zenPosition) - { + public IPartialExpression instance(ZenPosition zenPosition) { return new ExpressionCallStatic(zenPosition, environment, method, new ExpressionString(zenPosition, name)); } } - public static IGasStack getGas(String 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; - } + return gas == null ? null : new CraftTweakerGasStack(new GasStack(gas, 1)); } -} +} \ No newline at end of file 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 4a581ec36..fddce8add 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasDefinition.java @@ -13,11 +13,11 @@ import stanhebben.zenscript.annotations.ZenOperator; public interface IGasDefinition { @ZenOperator(OperatorType.MUL) - IGasStack asStack(int millibuckets); + IGasStack asStack(int mb); @ZenGetter("NAME") String getName(); @ZenGetter("displayName") String getDisplayName(); -} +} \ No newline at end of file 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 20feb1cce..d56aacca1 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/gas/IGasStack.java @@ -3,17 +3,12 @@ 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; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; -import stanhebben.zenscript.annotations.ZenOperator; +import stanhebben.zenscript.annotations.*; @ZenClass("mod.mekanism.gas.IGasStack") @ModOnly("mtlib") @ZenRegister -public interface IGasStack extends IIngredient -{ +public interface IGasStack extends IIngredient { @ZenGetter("definition") IGasDefinition getDefinition(); @@ -31,4 +26,4 @@ public interface IGasStack extends IIngredient IGasStack withAmount(int amount); Object getInternal(); -} +} \ No newline at end of file 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 3eea8f873..1f6e2a61f 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalCrystallizer.java @@ -1,105 +1,44 @@ 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; 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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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.crystallizer") @ModOnly("mtlib") @ZenRegister -public class ChemicalCrystallizer -{ +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; + public static void addRecipe(IGasStack gasInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, gasInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER, + new CrystallizerRecipe(GasHelper.toGas(gasInput), InputHelper.toStack(itemOutput)))); } - - CrystallizerRecipe recipe = new CrystallizerRecipe(GasHelper.toGas(gasInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER.get(), itemOutput, gasInput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient itemOutput; - private IIngredient gasInput; - - public Remove(String name, Map map, IIngredient itemOutput, IIngredient gasInput) - { - super(name, map); - this.itemOutput = itemOutput; - this.gasInput = gasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CHEMICAL_CRYSTALLIZER, new IngredientWrapper(itemOutput), new IngredientWrapper(gasInput))); } } -} +} \ No newline at end of file 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 8daa55493..e3d22dcef 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalDissolution.java @@ -1,106 +1,44 @@ 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; 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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.GasOutput; 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 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; + public static void addRecipe(IItemStack itemInput, IGasStack gasOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, gasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER, + new DissolutionRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)))); } - - DissolutionRecipe recipe = new DissolutionRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), gasOutput, itemInput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient gasOutput; - private IIngredient itemInput; - - public Remove(String name, Map map, IIngredient gasOutput, IIngredient itemInput) - { - super(name, map); - - this.gasOutput = gasOutput; - this.itemInput = itemInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient itemInput) { + if (IngredientHelper.checkNotNull(NAME, gasOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CHEMICAL_DISSOLUTION_CHAMBER, new IngredientWrapper(gasOutput), new IngredientWrapper(itemInput))); } } -} +} \ No newline at end of file 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 ce504bc1b..cb1685173 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInfuser.java @@ -1,110 +1,42 @@ 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; -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.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.GasOutput; 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 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; + public static void addRecipe(IGasStack leftGasInput, IGasStack rightGasInput, IGasStack gasOutput) { + if (IngredientHelper.checkNotNull(NAME, leftGasInput, rightGasInput, gasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER, + new ChemicalInfuserRecipe(GasHelper.toGas(leftGasInput), GasHelper.toGas(rightGasInput), GasHelper.toGas(gasOutput)))); } - - ChemicalInfuserRecipe recipe = new ChemicalInfuserRecipe(GasHelper.toGas(leftGasInput), GasHelper.toGas(rightGasInput), GasHelper.toGas(gasOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_INFUSER.get(), gasOutput, leftGasInput, rightGasInput)); - } - - 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) - { - super(name, map); - - this.gasOutput = gasOutput; - this.leftGasInput = leftGasInput; - this.rightGasInput = rightGasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient leftGasInput, @Optional IIngredient rightGasInput) { + if (IngredientHelper.checkNotNull(NAME, gasOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CHEMICAL_INFUSER, new IngredientWrapper(gasOutput), new IngredientWrapper(leftGasInput, rightGasInput))); } } -} +} \ No newline at end of file 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 474281a83..965c4550e 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalInjection.java @@ -1,118 +1,45 @@ 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; -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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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; + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, gasInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER, + new InjectionRecipe(new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()), + new ItemStackOutput(InputHelper.toStack(itemOutput))))); } - - AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); - ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); - - InjectionRecipe recipe = new InjectionRecipe(input, output); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER.get(), itemOutput, itemInput, gasInput)); - } - - 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) - { - super(name, map); - this.itemOutput = itemOutput; - this.itemInput = itemInput; - this.gasInput = gasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CHEMICAL_INJECTION_CHAMBER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput, gasInput))); } } -} +} \ No newline at end of file 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 545c4a922..257637337 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalOxidizer.java @@ -1,106 +1,44 @@ 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; 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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.GasOutput; 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") @ModOnly("mtlib") @ZenRegister -public class ChemicalOxidizer -{ +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; + public static void addRecipe(IItemStack itemInput, IGasStack gasOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, gasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER, + new OxidationRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)))); } - - OxidationRecipe recipe = new OxidationRecipe(InputHelper.toStack(itemInput), GasHelper.toGas(gasOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_OXIDIZER.get(), gasOutput, itemInput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient gasOutput; - private IIngredient itemInput; - - public Remove(String name, Map map, IIngredient gasOutput, IIngredient itemInput) - { - super(name, map); - - this.gasOutput = gasOutput; - this.itemInput = itemInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient itemInput) { + if (IngredientHelper.checkNotNull(NAME, gasOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CHEMICAL_OXIDIZER, new IngredientWrapper(gasOutput), new IngredientWrapper(itemInput))); } } -} +} \ No newline at end of file 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 ddd864379..305e774ea 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ChemicalWasher.java @@ -1,103 +1,42 @@ 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; -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.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.GasOutput; 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 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; + public static void addRecipe(IGasStack gasInput, IGasStack gasOutput) { + if (IngredientHelper.checkNotNull(NAME, gasInput, gasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER, + new WasherRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)))); } - - WasherRecipe recipe = new WasherRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CHEMICAL_WASHER.get(), gasOutput, gasInput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient gasOutput; - private IIngredient gasInput; - - public Remove(String name, Map map, IIngredient gasOutput, IIngredient gasInput) - { - super(name, map); - - this.gasOutput = gasOutput; - this.gasInput = gasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient gasOutput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, gasOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CHEMICAL_WASHER, new IngredientWrapper(gasOutput), new IngredientWrapper(gasInput))); } } -} +} \ No newline at end of file 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 452549aeb..5533dfdad 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Combiner.java @@ -1,50 +1,36 @@ 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; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.inputs.DoubleMachineInput; -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 class Combiner { public static final String NAME = "Mekanism Combiner"; @ZenMethod - public static void addRecipe(IItemStack itemInput, IItemStack extraInput, IItemStack itemOutput) - { - if (itemInput == null || extraInput == null || itemOutput == null) - { - LogHelper.logError(String.format("Required parameters missing for %s Recipe.", NAME)); - return; + public static void addRecipe(IItemStack itemInput, IItemStack extraInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, extraInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER, + new CombinerRecipe(new DoubleMachineInput(InputHelper.toStack(itemInput), InputHelper.toStack(extraInput)), + new ItemStackOutput(InputHelper.toStack(itemOutput))))); } - - DoubleMachineInput input = new DoubleMachineInput(InputHelper.toStack(itemInput), InputHelper.toStack(extraInput)); - ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); - CombinerRecipe recipe = new CombinerRecipe(input, output); - - CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER.get(), recipe)); } /** @@ -53,80 +39,18 @@ public class Combiner */ @ZenMethod @Deprecated - 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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.COMBINER, + new CombinerRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)))); } - - CombinerRecipe recipe = new CombinerRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.COMBINER.get(), itemOutput, itemInput, gasInput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient itemOutput; - private IIngredient itemInput; - private IIngredient itemExtra; - - public Remove(String name, Map map, IIngredient itemOutput, IIngredient itemInput, IIngredient extraInput) - { - super(name, map); - - this.itemOutput = itemOutput; - this.itemInput = itemInput; - this.itemExtra = extraInput; - } - - @Override - public void addRecipes() - { - Map recipesToRemove = new HashMap<>(); - - for (Map.Entry entry : ((Map) RecipeHandler.Recipe.COMBINER.get()).entrySet()) - { - IItemStack inputItem = InputHelper.toIItemStack(entry.getKey().itemStack); - IItemStack extraItem = InputHelper.toIItemStack(entry.getKey().extraStack); - IItemStack outputItem = InputHelper.toIItemStack(entry.getValue().getOutput().output); - - if (!StackHelper.matches(itemInput, inputItem)) - continue; - if (!StackHelper.matches(itemExtra, extraItem)) - 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(), itemExtra.toString(), itemOutput.toString())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.COMBINER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput, gasInput))); } } -} +} \ No newline at end of file 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 e58d760db..d353f60d4 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Compressor.java @@ -1,132 +1,53 @@ 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; -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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR, + new OsmiumCompressorRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)))); } - - OsmiumCompressorRecipe recipe = new OsmiumCompressorRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.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; + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, gasInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR, + new OsmiumCompressorRecipe(new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()), + new ItemStackOutput(InputHelper.toStack(itemOutput))))); } - - AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); - ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); - - OsmiumCompressorRecipe recipe = new OsmiumCompressorRecipe(input, output); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.OSMIUM_COMPRESSOR.get(), itemOutput, itemInput, gasInput)); - } - - 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) - { - super(name, map); - - this.itemOutput = itemOutput; - this.itemInput = itemInput; - this.gasInput = gasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.OSMIUM_COMPRESSOR, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput, gasInput))); } } -} +} \ No newline at end of file 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 20bc28beb..9ed89e7d1 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Crusher.java @@ -1,103 +1,42 @@ 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; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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.crusher") @ModOnly("mtlib") @ZenRegister -public class Crusher -{ +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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.CRUSHER, + new CrusherRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)))); } - - CrusherRecipe recipe = new CrusherRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.CRUSHER.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) - { - super(name, map); - - this.itemOutput = itemOutput; - this.itemInput = itemInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.CRUSHER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput))); } } -} +} \ No newline at end of file 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 f8f969350..dc9060779 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/EnergizedSmelter.java @@ -1,117 +1,54 @@ 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; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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.smelter") @ModOnly("mtlib") @ZenRegister -public class EnergizedSmelter -{ +public class EnergizedSmelter { public static final String NAME = "Mekanism Smelter"; private static boolean removedRecipe = false; private static boolean addedRecipe = false; - public static boolean hasRemovedRecipe() - { + public static boolean hasRemovedRecipe() { return removedRecipe; } - public static boolean hasAddedRecipe() - { + public static boolean hasAddedRecipe() { return addedRecipe; } @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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER, + new SmeltingRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)))); + addedRecipe = true; } - - SmeltingRecipe recipe = new SmeltingRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), recipe)); - addedRecipe = true; } @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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENERGIZED_SMELTER.get(), itemInput, itemOutput)); - removedRecipe = true; - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient itemInput; - private IIngredient itemOutput; - - public Remove(String name, Map map, IIngredient itemInput, IIngredient itemOutput) - { - super(name, map); - - this.itemInput = itemInput; - this.itemOutput = itemOutput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.ENERGIZED_SMELTER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput))); + removedRecipe = true; } } -} +} \ No newline at end of file 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 7f408f439..116267395 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Enrichment.java @@ -1,103 +1,42 @@ 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; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.inputs.ItemStackInput; -import mekanism.common.recipe.inputs.MachineInput; import mekanism.common.recipe.machines.EnrichmentRecipe; -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.enrichment") @ModOnly("mtlib") @ZenRegister -public class Enrichment -{ +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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER, + new EnrichmentRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)))); } - - EnrichmentRecipe recipe = new EnrichmentRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.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; - - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), itemInput, itemOutput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient itemOutput; - private IIngredient itemInput; - - public Remove(String name, Map map, IIngredient itemInput, IIngredient itemOutput) - { - super(name, map); - this.itemOutput = itemOutput; - this.itemInput = itemInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.ENRICHMENT_CHAMBER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput))); } } -} +} \ No newline at end of file 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 fa7d387ff..4b8d1cfe8 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Infuser.java @@ -2,114 +2,48 @@ 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; import mekanism.api.infuse.InfuseRegistry; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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()) - { + public static void addRecipe(String infuseType, int infuseAmount, IItemStack itemInput, IItemStack itemOutput) { + if (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); - - CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), recipe)); + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER, + new MetallurgicInfuserRecipe(new InfusionInput(InfuseRegistry.get(infuseType), infuseAmount, InputHelper.toStack(itemInput)), + new ItemStackOutput(InputHelper.toStack(itemOutput))))); + } } @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 = ""; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.METALLURGIC_INFUSER.get(), itemOutput, itemInput, infuseType)); - } - - 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) - { - super(name, map); - - this.itemOutput = itemOutput; - this.itemInput = itemInput; - this.infuseType = infuseType; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional String infuseType) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.METALLURGIC_INFUSER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput, infuseType))); } } -} +} \ No newline at end of file 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 85b35ee48..1977ad076 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Purification.java @@ -1,132 +1,53 @@ 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; -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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER, + new PurificationRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)))); } - - PurificationRecipe recipe = new PurificationRecipe(InputHelper.toStack(itemInput), InputHelper.toStack(itemOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; + public static void addRecipe(IItemStack itemInput, IGasStack gasInput, IItemStack itemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput, gasInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER, + new PurificationRecipe(new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()), + new ItemStackOutput(InputHelper.toStack(itemOutput))))); } - - AdvancedMachineInput input = new AdvancedMachineInput(InputHelper.toStack(itemInput), GasHelper.toGas(gasInput).getGas()); - ItemStackOutput output = new ItemStackOutput(InputHelper.toStack(itemOutput)); - - PurificationRecipe recipe = new PurificationRecipe(input, output); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.PURIFICATION_CHAMBER.get(), itemOutput, itemInput, gasInput)); - } - - 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) - { - super(name, map); - - this.itemOutput = itemOutput; - this.itemInput = itemInput; - this.gasInput = gasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.PURIFICATION_CHAMBER, new IngredientWrapper(itemOutput), new IngredientWrapper(itemInput, gasInput))); } } -} +} \ No newline at end of file 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 56308a9d7..d6b74e8f1 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Reaction.java @@ -1,132 +1,48 @@ 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; 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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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; + public static void addRecipe(IItemStack itemInput, ILiquidStack liquidInput, IGasStack gasInput, IItemStack itemOutput, IGasStack gasOutput, double energy, int duration) { + if (IngredientHelper.checkNotNull(NAME, itemInput, liquidInput, gasInput, itemOutput, gasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER, + new PressurizedRecipe(new PressurizedInput(InputHelper.toStack(itemInput), InputHelper.toFluid(liquidInput), GasHelper.toGas(gasInput)), + new PressurizedOutput(InputHelper.toStack(itemOutput), GasHelper.toGas(gasOutput)), + energy, duration))); } - - 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); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER.get(), itemOutput, gasOutput, itemInput, liquidInput, gasInput)); - } - - 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) - { - super(name, map); - - this.itemOutput = itemOutput; - this.gasOutput = gasOutput; - this.itemInput = itemInput; - this.liquidInput = liquidInput; - this.gasInput = gasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemOutput, IIngredient gasOutput, @Optional IIngredient itemInput, @Optional IIngredient liquidInput, @Optional IIngredient gasInput) { + if (IngredientHelper.checkNotNull(NAME, itemOutput, gasOutput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.PRESSURIZED_REACTION_CHAMBER, new IngredientWrapper(itemOutput, gasOutput), new IngredientWrapper(itemInput, liquidInput, gasInput))); } } -} +} \ No newline at end of file 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 4e9924485..8febf6065 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Sawmill.java @@ -1,115 +1,44 @@ 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; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 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; + public static void addRecipe(IItemStack itemInput, IItemStack itemOutput, @Optional IItemStack optionalItemOutput, @Optional double optionalChance) { + if (IngredientHelper.checkNotNull(NAME, itemInput, itemOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL, + new SawmillRecipe(new ItemStackInput(toStack(itemInput)), + optionalItemOutput == null ? new ChanceOutput(toStack(itemOutput)) : new ChanceOutput(toStack(itemOutput), toStack(optionalItemOutput), optionalChance)))); } - - 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); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.PRECISION_SAWMILL.get(), itemInput, itemOutput, optionalItemOutput)); - } - - 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) - { - super(name, map); - this.itemInput = itemInput; - this.itemOutput = itemOutput; - this.optionalItemOutput = optionalItemOutput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput, @Optional IIngredient optionalItemOutput) { + if (IngredientHelper.checkNotNull(NAME, itemInput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.PRECISION_SAWMILL, new IngredientWrapper(itemInput), new IngredientWrapper(itemOutput, optionalItemOutput))); } } -} +} \ No newline at end of file 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 9bac88a62..bede4a57c 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/Separator.java @@ -1,112 +1,44 @@ 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; 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; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.ChemicalPairOutput; 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 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; + public static void addRecipe(ILiquidStack liquidInput, double energy, IGasStack leftGasOutput, IGasStack rightGasOutput) { + if (IngredientHelper.checkNotNull(NAME, liquidInput, leftGasOutput, rightGasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR, + new SeparatorRecipe(InputHelper.toFluid(liquidInput), energy, GasHelper.toGas(leftGasOutput), GasHelper.toGas(rightGasOutput)))); } - - SeparatorRecipe recipe = new SeparatorRecipe(InputHelper.toFluid(liquidInput), energy, GasHelper.toGas(leftGasOutput), GasHelper.toGas(rightGasOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.get(), liquidInput, leftGasInput, rightGasInput)); - } - - 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) - { - super(name, map); - this.liquidInput = liquidInput; - this.leftGasInput = leftGasInput; - this.rightGasInput = rightGasInput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient liquidInput, @Optional IIngredient leftGasOutput, @Optional IIngredient rightGasOutput) { + if (IngredientHelper.checkNotNull(NAME, liquidInput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR, new IngredientWrapper(liquidInput), new IngredientWrapper(leftGasOutput, rightGasOutput))); } } -} +} \ No newline at end of file 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 7a6025228..e71bf2177 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/SolarNeutronActivator.java @@ -1,102 +1,42 @@ 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; -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.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.GasOutput; 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") @ModOnly("mtlib") @ZenRegister -public class 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; + public static void addRecipe(IGasStack gasInput, IGasStack gasOutput) { + if (IngredientHelper.checkNotNull(NAME, gasInput, gasOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR, + new SolarNeutronRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)))); } - - SolarNeutronRecipe recipe = new SolarNeutronRecipe(GasHelper.toGas(gasInput), GasHelper.toGas(gasOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR.get(), gasInput, gasOutput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient gasInput; - private IIngredient gasOutput; - - public Remove(String name, Map map, IIngredient gasInput, IIngredient gasOutput) - { - super(name, map); - this.gasInput = gasInput; - this.gasOutput = gasOutput; - } - - @Override - public void addRecipes() - { - 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())); - } + public static void removeRecipe(IIngredient gasInput, @Optional IIngredient gasOutput) { + if (IngredientHelper.checkNotNull(NAME, gasInput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.SOLAR_NEUTRON_ACTIVATOR, new IngredientWrapper(gasOutput), new IngredientWrapper(gasInput))); } } -} +} \ No newline at end of file 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 f4431485e..63e8fff09 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/ThermalEvaporation.java @@ -1,91 +1,42 @@ 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; import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; import mekanism.common.integration.crafttweaker.util.AddMekanismRecipe; import mekanism.common.integration.crafttweaker.util.RemoveMekanismRecipe; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; 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 mekanism.common.recipe.outputs.FluidOutput; 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") @ModOnly("mtlib") @ZenRegister -public class 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; + if (IngredientHelper.checkNotNull(NAME, liquidInput, liquidOutput)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new AddMekanismRecipe(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT, + new ThermalEvaporationRecipe(InputHelper.toFluid(liquidInput), InputHelper.toFluid(liquidOutput)))); } - - ThermalEvaporationRecipe recipe = new ThermalEvaporationRecipe(InputHelper.toFluid(liquidInput), InputHelper.toFluid(liquidOutput)); - - CrafttweakerIntegration.LATE_ADDITIONS.add(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; - - CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT.get(), liquidInput, liquidOutput)); - } - - private static class Remove extends RemoveMekanismRecipe - { - private IIngredient liquidInput; - private IIngredient liquidOutput; - - public Remove(String name, Map map, IIngredient liquidInput, IIngredient liquidOutput) - { - super(name, map); - this.liquidInput = liquidInput; - this.liquidOutput = liquidOutput; - } - - @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())); - } + if (IngredientHelper.checkNotNull(NAME, liquidInput)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveMekanismRecipe(NAME, + RecipeHandler.Recipe.THERMAL_EVAPORATION_PLANT, new IngredientWrapper(liquidOutput), new IngredientWrapper(liquidInput))); } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java index 7975556c6..cc302bd3d 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/GasHelper.java @@ -6,47 +6,31 @@ import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; -public class GasHelper -{ - private GasHelper() - { +public class GasHelper { + private GasHelper() { } - public static boolean matches(IIngredient ingredient, IGasStack gasStack) - { - if (ingredient == null) - { + public static boolean matches(IIngredient ingredient, IGasStack gasStack) { + if (ingredient == null) { return false; } - - if (ingredient == IngredientAny.INSTANCE) - { + if (ingredient == IngredientAny.INSTANCE) { return true; } - - if (ingredient instanceof IGasStack) - { + 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 toGas(IGasStack iStack) { + return iStack == null ? null : new GasStack(GasRegistry.getGas(iStack.getName()), iStack.getAmount()); } - public static GasStack[] toGases(IGasStack[] iStack) - { + 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; } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java new file mode 100644 index 000000000..53aa981c5 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java @@ -0,0 +1,125 @@ +package mekanism.common.integration.crafttweaker.helpers; + +import com.blamejared.mtlib.helpers.InputHelper; +import com.blamejared.mtlib.helpers.LogHelper; +import com.blamejared.mtlib.helpers.StackHelper; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.item.IngredientAny; +import crafttweaker.api.liquid.ILiquidStack; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; +import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.util.IngredientWrapper; +import mekanism.common.recipe.inputs.*; +import mekanism.common.recipe.outputs.*; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +public class IngredientHelper { + private IngredientHelper() { + } + + public static IIngredient optionalIngredient(IIngredient ingredient) { + return ingredient != null ? ingredient : IngredientAny.INSTANCE; + } + + public static boolean checkNotNull(String name, IIngredient... ingredients) { + for (IIngredient ingredient : ingredients) { + if (ingredient == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); + return false; + } + } + return true; + } + + private static IIngredient getIngredient(Object ingredient) { + if (ingredient instanceof ItemStack) { + return InputHelper.toIItemStack((ItemStack) ingredient); + } else if (ingredient instanceof GasStack) { + return new CraftTweakerGasStack((GasStack) ingredient); + } else if (ingredient instanceof Gas) { + return new CraftTweakerGasStack(new GasStack((Gas) ingredient, 1)); + } else if (ingredient instanceof FluidStack) { + return InputHelper.toILiquidStack((FluidStack) ingredient); + } else if (ingredient instanceof Fluid) { + return InputHelper.toILiquidStack(new FluidStack((Fluid) ingredient, 1)); + } + //TODO: Support other types of things like ore dict + return IngredientAny.INSTANCE; + } + + public static boolean matches(IIngredient input, IIngredient toMatch) { + if (input instanceof IGasStack) { + return GasHelper.matches(toMatch, (IGasStack) input); + } else if (input instanceof IItemStack) { + return StackHelper.matches(toMatch, (IItemStack) input); + } else if (input instanceof ILiquidStack) { + return StackHelper.matches(toMatch, (ILiquidStack) input); + } + //TODO: Support other types of things like ore dict + return false; + } + + public static boolean matches(Object input, IIngredient toMatch) { + return matches(getIngredient(input), toMatch); + } + + public static > boolean matches(INPUT in, IngredientWrapper toMatch) { + if (in instanceof ItemStackInput) { + ItemStackInput input = (ItemStackInput) in; + return matches(input.ingredient, toMatch.getIngredient()); + } else if (in instanceof GasInput) { + GasInput input = (GasInput) in; + return matches(input.ingredient, toMatch.getIngredient()); + } else if (in instanceof FluidInput) { + FluidInput input = (FluidInput) in; + return matches(input.ingredient, toMatch.getIngredient()); + } else if (in instanceof AdvancedMachineInput) { + AdvancedMachineInput input = (AdvancedMachineInput) in; + return matches(input.gasType, toMatch.getLeft()) && matches(input.itemStack, toMatch.getRight()); + } else if (in instanceof ChemicalPairInput) { + ChemicalPairInput input = (ChemicalPairInput) in; + return matches(input.leftGas, toMatch.getLeft()) && matches(input.rightGas, toMatch.getRight()); + } else if (in instanceof DoubleMachineInput) { + DoubleMachineInput input = (DoubleMachineInput) in; + return matches(input.itemStack, toMatch.getLeft()) && matches(input.extraStack, toMatch.getRight()); + } else if (in instanceof PressurizedInput) { + PressurizedInput input = (PressurizedInput) in; + return matches(input.getSolid(), toMatch.getLeft()) && matches(input.getFluid(), toMatch.getMiddle()) && matches(input.getGas(), toMatch.getRight()); + } else if (in instanceof InfusionInput) { + InfusionInput input = (InfusionInput) in; + return matches(input.inputStack, toMatch.getIngredient()) && (toMatch.getInfuseType().isEmpty() || toMatch.getInfuseType().equalsIgnoreCase(input.infuse.type.name)); + } else if (in instanceof IntegerInput) { + IntegerInput input = (IntegerInput) in; + return input.ingredient == toMatch.getAmount(); + } + return false; + } + + public static > boolean matches(OUTPUT out, IngredientWrapper toMatch) { + if (out instanceof ItemStackOutput) { + ItemStackOutput output = (ItemStackOutput) out; + return matches(output.output, toMatch.getIngredient()); + } else if (out instanceof GasOutput) { + GasOutput output = (GasOutput) out; + return matches(output.output, toMatch.getIngredient()); + } else if (out instanceof FluidOutput) { + FluidOutput output = (FluidOutput) out; + return matches(output.output, toMatch.getIngredient()); + } else if (out instanceof ChanceOutput) { + ChanceOutput output = (ChanceOutput) out; + return matches(output.primaryOutput, toMatch.getLeft()) && matches(output.secondaryOutput, toMatch.getRight()); + } else if (out instanceof ChemicalPairOutput) { + ChemicalPairOutput output = (ChemicalPairOutput) out; + return matches(output.leftGas, toMatch.getLeft()) && matches(output.rightGas, toMatch.getRight()); + } else if (out instanceof PressurizedOutput) { + PressurizedOutput output = (PressurizedOutput) out; + return matches(output.getItemOutput(), toMatch.getLeft()) && matches(output.getGasOutput(), toMatch.getRight()); + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java new file mode 100644 index 000000000..cdc8a2408 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java @@ -0,0 +1,33 @@ +package mekanism.common.integration.crafttweaker.helpers; + +import com.blamejared.mtlib.helpers.LogHelper; +import mekanism.common.recipe.inputs.MachineInput; +import mekanism.common.recipe.machines.MachineRecipe; +import mekanism.common.recipe.outputs.*; + +import java.util.Map; + +public class RecipeInfoHelper { + private RecipeInfoHelper() { + } + + public static 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) { + ChemicalPairOutput out = (ChemicalPairOutput) output; + return "[" + LogHelper.getStackDescription(out.leftGas) + ", " + LogHelper.getStackDescription(out.rightGas) + "]"; + } else if (output instanceof ChanceOutput) { + return LogHelper.getStackDescription(((ChanceOutput) output).primaryOutput); + } else if (output instanceof PressurizedOutput) { + PressurizedOutput out = (PressurizedOutput) output; + return "[" + LogHelper.getStackDescription(out.getItemOutput()) + ", " + LogHelper.getStackDescription(out.getGasOutput()) + "]"; + } + return null; + } +} \ No newline at end of file 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 90da48aeb..a0a896e92 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/AddMekanismRecipe.java @@ -1,72 +1,21 @@ package mekanism.common.integration.crafttweaker.util; -import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.utils.BaseMapAddition; +import mekanism.common.integration.crafttweaker.helpers.RecipeInfoHelper; +import mekanism.common.recipe.RecipeHandler.Recipe; 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 -{ - private MachineRecipe recipe; - - public AddMekanismRecipe(String name, Map map, MachineRecipe recipe) - { - super(name, map); - this.recipe = recipe; - } - - public void addRecipes() - { - this.recipes.put(recipe.getInput(), recipe); +public class AddMekanismRecipe extends BaseMapAddition { + public AddMekanismRecipe(String name, Recipe recipeType, MachineRecipe recipe) { + super(name, recipeType.get()); + recipes.put(recipe.getInput(), recipe); } @Override - public void apply() - { - addRecipes(); - - super.apply(); + protected String getRecipeInfo(Map.Entry recipe) { + return RecipeInfoHelper.getRecipeInfo(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; - } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/util/IngredientWrapper.java b/src/main/java/mekanism/common/integration/crafttweaker/util/IngredientWrapper.java new file mode 100644 index 000000000..2928eb503 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/IngredientWrapper.java @@ -0,0 +1,82 @@ +package mekanism.common.integration.crafttweaker.util; + +import com.blamejared.mtlib.helpers.LogHelper; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IngredientAny; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; + +public class IngredientWrapper { + private final IIngredient left; + private final IIngredient middle; + private final IIngredient right; + private final String infuseType; + + public IngredientWrapper(IIngredient ingredient) { + this(ingredient, IngredientAny.INSTANCE); + } + + public IngredientWrapper(IIngredient left, IIngredient right) { + this(left, IngredientAny.INSTANCE, right); + } + + public IngredientWrapper(IIngredient left, IIngredient middle, IIngredient right) { + this.left = IngredientHelper.optionalIngredient(left); + this.middle = IngredientHelper.optionalIngredient(middle); + this.right = IngredientHelper.optionalIngredient(right); + this.infuseType = ""; + } + + public IngredientWrapper(IIngredient ingredient, String infuseType) { + this.left = IngredientHelper.optionalIngredient(ingredient); + this.middle = IngredientAny.INSTANCE; + this.right = IngredientAny.INSTANCE; + this.infuseType = infuseType == null ? "" : infuseType; + } + + public String getInfuseType() { + return this.infuseType; + } + + public IIngredient getIngredient() { + return this.left; + } + + public IIngredient getLeft() { + return this.left; + } + + public IIngredient getMiddle() { + return this.middle; + } + + public IIngredient getRight() { + return this.right; + } + + public int getAmount() { + //TODO: Make this method actually do something if we ever need to use IntegerInput as an input type + return 0; + } + + @Override + public String toString() { + String output = ""; + if (!left.equals(IngredientAny.INSTANCE)) { + output += LogHelper.getStackDescription(left); + } + if (!middle.equals(IngredientAny.INSTANCE)) { + output += ", " + LogHelper.getStackDescription(middle); + } + if (!right.equals(IngredientAny.INSTANCE)) { + output += ", " + LogHelper.getStackDescription(right); + } + if (!infuseType.isEmpty()) { + output += ", " + infuseType; + } + return output; + } + + public boolean isEmpty() { + return left.equals(IngredientAny.INSTANCE) && middle.equals(IngredientAny.INSTANCE) && right.equals(IngredientAny.INSTANCE) && infuseType.isEmpty(); + } +} \ No newline at end of file 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 f895762a4..d28ee6c00 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/util/RemoveMekanismRecipe.java @@ -2,65 +2,48 @@ package mekanism.common.integration.crafttweaker.util; import com.blamejared.mtlib.helpers.LogHelper; import com.blamejared.mtlib.utils.BaseMapRemoval; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; +import mekanism.common.integration.crafttweaker.helpers.RecipeInfoHelper; +import mekanism.common.recipe.RecipeHandler.Recipe; 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 abstract class RemoveMekanismRecipe extends BaseMapRemoval -{ - public RemoveMekanismRecipe(String name, Map map) - { - super(name, map); - } - - public abstract void addRecipes(); - - @Override - public void apply() - { - addRecipes(); - - super.apply(); +public class RemoveMekanismRecipe, OUTPUT extends MachineOutput, RECIPE extends MachineRecipe> extends BaseMapRemoval { + public RemoveMekanismRecipe(String name, Recipe recipeType, IngredientWrapper output, IngredientWrapper input) { + super(name, recipeType.get()); + map.forEach((key, value) -> { + if (IngredientHelper.matches(key, input) && IngredientHelper.matches(value.getOutput(), output)) { + recipes.put(key, value); + } + }); + if (recipes.isEmpty()) { + String warning = ""; + if (input.isEmpty()) { + if (!output.isEmpty()) { //It should never be the case they both are empty but just in case they are ignore it + warning = String.format("output: '%s'", output.toString()); + } + } else if (output.isEmpty()) { + warning = String.format("input: '%s'", input.toString()); + } else { + warning = String.format("input: '%s' and output: '%s'", input.toString(), output.toString()); + } + if (!warning.isEmpty()) { + LogHelper.logWarning(String.format("No %s recipe found for %s. Command ignored!", name, warning)); + } + } } @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; + protected String getRecipeInfo(Map.Entry recipe) { + return RecipeInfoHelper.getRecipeInfo(recipe); } -} + + @Override + public String describe() { + //Only describe it if it didn't already throw a warning about no recipes found + return recipes.isEmpty() ? "" : super.describe(); + } +} \ No newline at end of file