diff --git a/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java b/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java index 27156bb..4ad1f69 100644 --- a/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java +++ b/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java @@ -3,6 +3,7 @@ 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.InputHelper.toIItemStack; import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.InputHelper.toStacks; import static modtweaker2.helpers.StackHelper.matches; @@ -14,10 +15,12 @@ import java.util.List; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; +import minetweaker.api.item.WeightedItemStack; import minetweaker.api.liquid.ILiquidStack; import modtweaker2.helpers.LogHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; +import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import forestry.factory.gadgets.MachineSqueezer; @@ -30,10 +33,37 @@ public class Squeezer { public static final String name = "Forestry Squeezer"; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Adds a recipe without additional item output + * + * @param fluidOutput recipe fluid amount + * @param ingredients recipe ingredients + * @param timePerItem time per crafting operation + */ @ZenMethod + public static void addRecipe(ILiquidStack fluidOutput, int timePerItem, IItemStack[] ingredients) { + MineTweakerAPI.apply(new Add( new Recipe(timePerItem, toStacks(ingredients), toFluid(fluidOutput), null, 0) )); + } + + /** + * Adds a recipe with additional item output + * + * @param fluidOutput recipe fluid amount + * @param itemOutput recipe output + * @param ingredients recipe ingredients + * @param timePerItem time per crafting operation + */ + @ZenMethod + public static void addRecipe(ILiquidStack fluidOutput, WeightedItemStack itemOutput, int timePerItem, IItemStack[] ingredients) { + MineTweakerAPI.apply(new Add( new Recipe(timePerItem, toStacks(ingredients), toFluid(fluidOutput), toStack(itemOutput.getStack()), (int) itemOutput.getPercent()) )); + } + + @ZenMethod + @Deprecated public static void addRecipe(int timePerItem, IItemStack[] resources, ILiquidStack liquid, IItemStack remnants, int chance) { MineTweakerAPI.apply(new Add(new Recipe(timePerItem, toStacks(resources), toFluid(liquid), toStack(remnants), chance))); + + //TODO: this should definitiv solved somehow better MachineSqueezer.RecipeManager.recipeFluids.add(getFluid(liquid)); MachineSqueezer.RecipeManager.recipeInputs.addAll(Arrays.asList(toStacks(resources))); } @@ -52,13 +82,36 @@ public class Squeezer { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Removes a recipe for the Centrifuge + * + * @param liquid liquid output + * @param ingredients list of ingredients + */ @ZenMethod - public static void removeRecipe(IIngredient liquid) { + public static void removeRecipe(IIngredient liquid, @Optional IIngredient[] ingredients) { List recipes = new LinkedList(); for (Recipe r : RecipeManager.recipes) { if (r != null && r.liquid != null && matches(liquid, toILiquidStack(r.liquid))) { - recipes.add(r); + // optional check for ingredients + if (ingredients != null) { + boolean matched = false; + for (int i = 0; i < ingredients.length; i++) { + if ( matches(ingredients[i], toIItemStack(r.resources[i])) && (ingredients[i].getAmount() == toIItemStack(r.resources[i]).getAmount()) ) + matched = true; + else { + matched = false; + // if one ingredients doesn't match abort all further checks + break; + } + } + // if some ingredient doesn't match, the last one is false + if (matched) + recipes.add(r); + } else { + recipes.add(r); + } } }