From 27e4fffd07e00b5ec33f8ffcc4c38d511ad1aa14 Mon Sep 17 00:00:00 2001 From: Tobias Wohlfarth Date: Tue, 28 Jul 2015 20:41:56 +0200 Subject: [PATCH] add: Fermenter fuel support modified: src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java --- .../mods/forestry/handlers/Fermenter.java | 94 ++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java b/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java index 1ae25e2..bb764cc 100644 --- a/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java +++ b/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java @@ -6,9 +6,12 @@ import static modtweaker2.helpers.InputHelper.toILiquidStack; import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.StackHelper.matches; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; @@ -17,9 +20,14 @@ import minetweaker.api.liquid.ILiquidStack; import modtweaker2.helpers.LogHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; +import modtweaker2.utils.BaseMapAddition; +import modtweaker2.utils.BaseMapRemoval; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; +import forestry.api.fuels.FermenterFuel; +import forestry.api.fuels.FuelManager; import forestry.factory.gadgets.MachineFermenter.Recipe; import forestry.factory.gadgets.MachineFermenter.RecipeManager; @@ -30,9 +38,26 @@ public class Fermenter { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - @ZenMethod - public static void addRecipe(IItemStack resource, ILiquidStack liquid, int fermentationValue, float modifier, ILiquidStack output) { - MineTweakerAPI.apply(new Add(new Recipe(toStack(resource), fermentationValue, modifier, toFluid(output), toFluid(liquid)))); + + /** + * Adds a fermenter recipe. Amount of fluid output is calculated: fermentationValue * fluidOutputModifier + * Note: the actual consumption of fluid input depends on the fermentation fuel + * + * @param fluidOutput type of fluid produced + * @param fluidInput type of fluid required in input + * @param resource organic item + * @param fermentationValue amount of inputFluid on organic item requires + * @param fluidOutputModifier Output multiplier (this is usually a from the input fluid + */ + @ZenMethod + public static void addRecipe(ILiquidStack fluidOutput, IItemStack resource, ILiquidStack fluidInput, int fermentationValue, float fluidOutputModifier) { + MineTweakerAPI.apply(new Add(new Recipe(toStack(resource), fermentationValue, fluidOutputModifier, toFluid(fluidOutput), toFluid(fluidInput)))); + } + + @Deprecated + @ZenMethod + public static void addRecipe(IItemStack resource, ILiquidStack fluidInput, int fermentationValue, float fluidOutputModifier, ILiquidStack fluidOutput) { + MineTweakerAPI.apply(new Add(new Recipe(toStack(resource), fermentationValue, fluidOutputModifier, toFluid(fluidOutput), toFluid(fluidInput)))); } private static class Add extends BaseListAddition { @@ -175,4 +200,67 @@ public class Fermenter { return LogHelper.getStackDescription(recipe.output); } } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds fermenter fuel. + * Note: the actual consumption of fluid input depends on the fermentation fuel + * + * @param item Item that is a valid fuel for the fermenter + * @param fermentPerCycle How much is fermeted per work cycle, i.e. how much fluid of the input is consumed. + * @param burnDuration Amount of work cycles a single item of this fuel lasts before expiring. + */ + @ZenMethod + public static void addFuel(IItemStack item, int fermentPerCycle, int burnDuration) { + MineTweakerAPI.apply(new AddFuel(new FermenterFuel(toStack(item), fermentPerCycle, burnDuration))); + } + + private static class AddFuel extends BaseMapAddition { + public AddFuel(FermenterFuel fuelEntry) { + super(Fermenter.name, FuelManager.fermenterFuel); + recipes.put(fuelEntry.item, fuelEntry); + } + + @Override + public String getRecipeInfo(Entry fuelEntry) { + return LogHelper.getStackDescription(fuelEntry.getKey()); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Removes a fermenter fuel. + * + * @param fermenterItem Item that is a valid fuel for the fermenter + */ + @ZenMethod + public static void removeFuel(IIngredient fermenterItem) { + Map fuelItems = new HashMap(); + + for(Entry fuelItem : FuelManager.fermenterFuel.entrySet()) { + if(fuelItem != null && matches(fermenterItem, toIItemStack(fuelItem.getValue().item))) { + fuelItems.put(fuelItem.getKey(), fuelItem.getValue()); + } + } + + if(!fuelItems.isEmpty()) { + MineTweakerAPI.apply(new RemoveFuel(fuelItems)); + } else { + LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Fermenter.name, fermenterItem.toString())); + } + } + + private static class RemoveFuel extends BaseMapRemoval { + public RemoveFuel(Map recipes) { + super(Fermenter.name, FuelManager.fermenterFuel, recipes); + } + + @Override + public String getRecipeInfo(Entry fuelEntry) { + return LogHelper.getStackDescription(fuelEntry.getKey()); + } + } } +