package modtweaker2.mods.forestry.handlers; import static modtweaker2.helpers.InputHelper.getFluid; import static modtweaker2.helpers.InputHelper.toFluid; import static modtweaker2.helpers.InputHelper.toILiquidStack; import static modtweaker2.helpers.StackHelper.matches; import java.util.LinkedList; import java.util.List; import minetweaker.MineTweakerAPI; import minetweaker.api.liquid.ILiquidStack; import modtweaker2.helpers.InputHelper; import modtweaker2.helpers.LogHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import forestry.factory.gadgets.MachineStill; import forestry.factory.gadgets.MachineStill.Recipe; import forestry.factory.gadgets.MachineStill.RecipeManager; @ZenClass("mods.forestry.Still") public class Still { public static final String name = "Forestry Still"; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @ZenMethod public static void addRecipe(int timePerUnit, ILiquidStack input, ILiquidStack output) { output.amount(output.getAmount() / 100); input.amount(input.getAmount() / 100); MineTweakerAPI.apply(new Add(new Recipe(timePerUnit, toFluid(input), toFluid(output)))); MachineStill.RecipeManager.recipeFluidInputs.add(getFluid(input)); MachineStill.RecipeManager.recipeFluidOutputs.add(getFluid(output)); } private static class Add extends BaseListAddition { public Add(Recipe recipe) { super("Forestry Still", MachineStill.RecipeManager.recipes); recipes.add(recipe); } @Override public String getRecipeInfo(Recipe recipe) { return InputHelper.getStackDescription(recipe.output); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @ZenMethod public static void removeRecipe(ILiquidStack output, ILiquidStack input) { List recipes = new LinkedList(); for (Recipe r : RecipeManager.recipes) { if (r != null && r.output != null && matches(output, toILiquidStack(r.output))) { recipes.add(r); } } if(!recipes.isEmpty()) { MineTweakerAPI.apply(new Remove(recipes)); } else { LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Still.name, output.toString())); } } private static class Remove extends BaseListRemoval { public Remove(List recipes) { super(Still.name, RecipeManager.recipes, recipes); } @Override public String getRecipeInfo(Recipe recipe) { return InputHelper.getStackDescription(recipe.output); } } }