improved: Railcraft Cokeoven, is now Undoable and easier ZenScript functions
modified: src/main/java/modtweaker2/mods/railcraft/handlers/CokeOven.java
This commit is contained in:
parent
e84eb65fb6
commit
bb23195bf7
1 changed files with 62 additions and 53 deletions
|
@ -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)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue