From bb23195bf76023b381e8f9a213192afd88870bcd Mon Sep 17 00:00:00 2001 From: Tobias Wohlfarth Date: Wed, 1 Jul 2015 19:21:53 +0200 Subject: [PATCH] improved: Railcraft Cokeoven, is now Undoable and easier ZenScript functions modified: src/main/java/modtweaker2/mods/railcraft/handlers/CokeOven.java --- .../mods/railcraft/handlers/CokeOven.java | 115 ++++++++++-------- 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/src/main/java/modtweaker2/mods/railcraft/handlers/CokeOven.java b/src/main/java/modtweaker2/mods/railcraft/handlers/CokeOven.java index 20011ae..928f335 100644 --- a/src/main/java/modtweaker2/mods/railcraft/handlers/CokeOven.java +++ b/src/main/java/modtweaker2/mods/railcraft/handlers/CokeOven.java @@ -2,78 +2,86 @@ package modtweaker2.mods.railcraft.handlers; import static modtweaker2.helpers.InputHelper.toFluid; import static modtweaker2.helpers.InputHelper.toStack; - -import java.lang.reflect.Field; -import java.util.List; - -import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; import minetweaker.api.liquid.ILiquidStack; +import minetweaker.mc1710.item.MCItemStack; import mods.railcraft.api.crafting.ICokeOvenRecipe; -import mods.railcraft.common.util.crafting.CokeOvenCraftingManager; +import mods.railcraft.api.crafting.RailcraftCraftingManager; import mods.railcraft.common.util.crafting.CokeOvenCraftingManager.CokeOvenRecipe; import modtweaker2.mods.railcraft.RailcraftHelper; +import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @ZenClass("mods.railcraft.CokeOven") public class CokeOven { + + /** + * Adds a recipe for the Coke Oven + * + * @param itemOutput ItemStack result + * @param fluidOutput FluidStack result + * @param ingredient item input + * @param timePerItem time per item to process + */ @ZenMethod - public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack output, ILiquidStack fluidOutput, int cookTime) { - MineTweakerAPI.apply(new Add(toStack(input), matchDamage, matchNBT, toStack(output), toFluid(fluidOutput), cookTime)); + public static void addRecipe(IItemStack itemOutput, ILiquidStack fluidOutput, IItemStack ingredient, int timePerItem) { + boolean matchEmptyNBT; + if (toStack(ingredient).stackTagCompound == null) + matchEmptyNBT = false; + else + matchEmptyNBT = true; + + if (ingredient.getDamage() == OreDictionary.WILDCARD_VALUE) + MineTweakerAPI.apply(new Add( new CokeOvenRecipe(toStack(ingredient), false, matchEmptyNBT, toStack(itemOutput), toFluid(fluidOutput), timePerItem) )); + else + MineTweakerAPI.apply(new Add( new CokeOvenRecipe(toStack(ingredient), true, matchEmptyNBT, toStack(itemOutput), toFluid(fluidOutput), timePerItem) )); + } + /** + * Adds a recipe for the Coke Oven (Use this, if you want to have an Input strictly without NBT Data) + * + * @param itemOutput ItemStack result + * @param fluidOutput FluidStack result + * @param ingredient item input + * @param matchEmptyNBT should the input only match an item with no NBT Data + * @param timePerItem time per item to process + */ + @ZenMethod + public static void addRecipe(IItemStack itemOutput, ILiquidStack fluidOutput, IItemStack ingredient, boolean matchEmptyNBT, int timePerItem) { + if (ingredient.getDamage() == OreDictionary.WILDCARD_VALUE) + MineTweakerAPI.apply(new Add( new CokeOvenRecipe(toStack(ingredient), false, matchEmptyNBT, toStack(itemOutput), toFluid(fluidOutput), timePerItem) )); + else + MineTweakerAPI.apply(new Add( new CokeOvenRecipe(toStack(ingredient), true, matchEmptyNBT, toStack(itemOutput), toFluid(fluidOutput), timePerItem) )); } - private static class Add implements IUndoableAction { + /** + * Adds a recipe for the Coke Oven + * + * @param ingredient item input + * @param matchDamage should the recipe compare NBT Data + * @param matchNBT should the recipe compare NBT Data + * @param itemOutput ItemStack result + * @param fluidOutput FluidStack result + * @param cookTime time per item to process + */ + @Deprecated + @ZenMethod + public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack output, ILiquidStack fluidOutput, int cookTime) { + MineTweakerAPI.apply(new Add( new CokeOvenRecipe(toStack(input), matchDamage, matchNBT, toStack(output), toFluid(fluidOutput), cookTime) )); + } - private ItemStack stack; - private boolean matchDamage; - private boolean matchNBT; - private ItemStack stack2; - private FluidStack fluid; - private int cookTime; + private static class Add extends BaseListAddition { - public Add(ItemStack stack, boolean matchDamage, boolean matchNBT, ItemStack stack2, FluidStack fluid, int cookTime) { - this.stack = stack; - this.matchDamage = matchDamage; - this.matchNBT = matchNBT; - this.stack2 = stack2; - this.fluid = fluid; - this.cookTime = cookTime; + public Add(CokeOvenRecipe recipe) { + super("Railcraft CokeOven", RailcraftCraftingManager.cokeOven.getRecipes(), recipe); } - @Override - public void apply() { - CokeOvenCraftingManager.getInstance().addRecipe(stack, matchDamage, matchNBT, stack2, fluid, cookTime); - - } - - @Override - public boolean canUndo() { - return false; - } - - @Override - public String describe() { - return "Adding a Railcraft CokeOven recipie for " + stack.getUnlocalizedName() + " and " + stack2.getUnlocalizedName() + "to get " + fluid.getUnlocalizedName(); - } - - @Override - public String describeUndo() { - return null; - } - - @Override - public Object getOverrideKey() { - return null; - } - - @Override - public void undo() { - + public String getRecipeInfo() { + return " " + new MCItemStack(((ICokeOvenRecipe) recipe).getInput()) + " (Input)"; } } @@ -89,6 +97,7 @@ public class CokeOven { super("Coke Oven", RailcraftHelper.oven, stack); } + @SuppressWarnings("unchecked") @Override public void apply() { for (ICokeOvenRecipe r : RailcraftHelper.oven) { @@ -101,7 +110,7 @@ public class CokeOven { @Override public String getRecipeInfo() { - return stack.getDisplayName(); + return " " + new MCItemStack(stack) + " (Input)"; } } }