From aa9cd8ce473ce28ea272d1316b66feb39d05901e Mon Sep 17 00:00:00 2001 From: Tobias Wohlfarth Date: Sun, 18 Jan 2015 04:34:02 +0100 Subject: [PATCH] add: Centrifuge, ThermiionicFabricator(Smelting & Casting) support modified: src/main/java/modtweaker/mods/forestry/Forestry.java modified: src/main/java/modtweaker/mods/forestry/handlers/Carpenter.java new file: src/main/java/modtweaker/mods/forestry/handlers/Centrifuge.java new file: src/main/java/modtweaker/mods/forestry/handlers/ThermionicFabricator.java --- .../modtweaker/mods/forestry/Forestry.java | 5 +- .../mods/forestry/handlers/Carpenter.java | 7 +- .../mods/forestry/handlers/Centrifuge.java | 80 +++++++++++ .../handlers/ThermionicFabricator.java | 133 ++++++++++++++++++ 4 files changed, 218 insertions(+), 7 deletions(-) create mode 100644 src/main/java/modtweaker/mods/forestry/handlers/Centrifuge.java create mode 100644 src/main/java/modtweaker/mods/forestry/handlers/ThermionicFabricator.java diff --git a/src/main/java/modtweaker/mods/forestry/Forestry.java b/src/main/java/modtweaker/mods/forestry/Forestry.java index 2b67751..02ac25c 100644 --- a/src/main/java/modtweaker/mods/forestry/Forestry.java +++ b/src/main/java/modtweaker/mods/forestry/Forestry.java @@ -2,10 +2,12 @@ package modtweaker.mods.forestry; import minetweaker.MineTweakerAPI; import modtweaker.mods.forestry.handlers.Carpenter; +import modtweaker.mods.forestry.handlers.Centrifuge; import modtweaker.mods.forestry.handlers.Fermenter; import modtweaker.mods.forestry.handlers.Moistener; import modtweaker.mods.forestry.handlers.Squeezer; import modtweaker.mods.forestry.handlers.Still; +import modtweaker.mods.forestry.handlers.ThermionicFabricator; public class Forestry { public Forestry() { @@ -14,6 +16,7 @@ public class Forestry { MineTweakerAPI.registerClass(Moistener.class); MineTweakerAPI.registerClass(Carpenter.class); MineTweakerAPI.registerClass(Squeezer.class); - + MineTweakerAPI.registerClass(Centrifuge.class); + MineTweakerAPI.registerClass(ThermionicFabricator.class); } } diff --git a/src/main/java/modtweaker/mods/forestry/handlers/Carpenter.java b/src/main/java/modtweaker/mods/forestry/handlers/Carpenter.java index 39dc9c6..7ad58cd 100644 --- a/src/main/java/modtweaker/mods/forestry/handlers/Carpenter.java +++ b/src/main/java/modtweaker/mods/forestry/handlers/Carpenter.java @@ -55,11 +55,6 @@ public class Carpenter { public Add(Recipe recipe) { super("Forestry Carpenter", MachineCarpenter.RecipeManager.recipes, recipe); } - - @Override - public String getRecipeInfo() { - return ((Recipe) recipe).getCraftingResult().getDisplayName(); - } } @ZenMethod @@ -70,7 +65,7 @@ public class Carpenter { private static class Remove extends BaseListRemoval { public Remove(List list, ItemStack stack) { - super(list, stack); + super("Forestry Carpenter", list, stack); } diff --git a/src/main/java/modtweaker/mods/forestry/handlers/Centrifuge.java b/src/main/java/modtweaker/mods/forestry/handlers/Centrifuge.java new file mode 100644 index 0000000..340309c --- /dev/null +++ b/src/main/java/modtweaker/mods/forestry/handlers/Centrifuge.java @@ -0,0 +1,80 @@ +package modtweaker.mods.forestry.handlers; + +import java.util.List; +import java.util.HashMap; +import net.minecraft.item.ItemStack; + +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.InputHelper.toStacks; + +import forestry.factory.gadgets.MachineCentrifuge; +import forestry.factory.gadgets.MachineCentrifuge.Recipe; +import forestry.factory.gadgets.MachineCentrifuge.RecipeManager; + + +@ZenClass("mods.forestry.Centrifuge") +public class Centrifuge { + + @ZenMethod + public static void addRecipe(IItemStack[] output, int[] chances, int timePerItem, IItemStack itemInput) { + HashMap products = new HashMap(); + // products.put(toStack(output[0]), chances[0]); + int i = 0; + for (IItemStack product : output) { + products.put(toStack(product), chances[i]); + i++; + } + MineTweakerAPI.apply(new Add(new Recipe(timePerItem, toStack(itemInput), products))); + } + + @ZenMethod + public static void removeRecipe(IItemStack itemInput) { + MineTweakerAPI.apply(new Remove(RecipeManager.recipes, toStack(itemInput))); + } + + /* + Implements the actions to add the recipe + */ + private static class Add extends BaseListAddition { + + public Add(Recipe recipe) { + super("Forestry Centrifuge", RecipeManager.recipes, recipe); + } + @Override + public String getRecipeInfo() { + return " Input:" + ((Recipe) recipe).resource.getDisplayName(); + } + } + + /* + Implements the actions to remove the recipe + */ + private static class Remove extends BaseListRemoval { + + public Remove(List list, ItemStack input) { + super("Forestry Centrifuge", RecipeManager.recipes, input); + } + + @Override + public void apply() { + for (Recipe r : RecipeManager.recipes) { + if (r.matches(stack)) { + recipe = r; + RecipeManager.recipes.remove(r); + break; + } + } + } + + @Override + public String getRecipeInfo() { + return " Input:" + stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/forestry/handlers/ThermionicFabricator.java b/src/main/java/modtweaker/mods/forestry/handlers/ThermionicFabricator.java new file mode 100644 index 0000000..ac4b6f1 --- /dev/null +++ b/src/main/java/modtweaker/mods/forestry/handlers/ThermionicFabricator.java @@ -0,0 +1,133 @@ +package modtweaker.mods.forestry.handlers; + +import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidRegistry; + +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import minetweaker.api.item.IIngredient; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.InputHelper.toObject; + +import forestry.core.utils.ShapedRecipeCustom; +import forestry.factory.gadgets.MachineFabricator; +import forestry.factory.gadgets.MachineFabricator.RecipeManager; +import forestry.factory.gadgets.MachineFabricator.Recipe; +import forestry.factory.gadgets.MachineFabricator.Smelting; + + +@ZenClass("mods.forestry.ThermionicFabricator") +public class ThermionicFabricator { + + //first production step: smelting item into liquid + @ZenMethod + public static void addSmelting(IItemStack itemInput, int fluidOutput, int meltingPoint) { + //The machines internal tank accept only liquid glass, therefor this function only accept the amount and hardcode the fluid to glass + MineTweakerAPI.apply(new Add(new Smelting(toStack(itemInput), FluidRegistry.getFluidStack("glass", fluidOutput), meltingPoint))); + } + + @ZenMethod + public static void removeSmelting(IItemStack itemInput) { + MineTweakerAPI.apply(new RemoveSmelting(toStack(itemInput))); + } + + //second step: casting liquid + objetcs + plan into result + @ZenMethod + public static void addCast(ILiquidStack fluidInput, IItemStack[][] ingredients, IItemStack plan, IItemStack product) { + ItemStack[] flatList = new ItemStack[9]; + for ( int i = 0; i < 3; i++) { + for ( int j = 0; j < 3; j++) { + flatList[i*3 + j] = toStack(ingredients[i][j]); + } + } + + MineTweakerAPI.apply(new Add(new Recipe(toStack(plan), toFluid(fluidInput), new ShapedRecipeCustom(3, 3, flatList, toStack(product))))); + } + + @ZenMethod + public static void removeCasts(IItemStack product) { + MineTweakerAPI.apply(new RemoveCastings(toStack(product))); + } + + /* + Implements the actions to add a recipe + Since the machine has two crafting Steps, this is a constructors for both + */ + private static class Add extends BaseListAddition { + + public Add(Smelting recipe) { + super("Forestry Thermionic Fabricator (Smelting)", RecipeManager.smeltings, recipe); + } + + public Add(Recipe recipe) { + super("Forestry Thermionic Fabricator (Casting)", RecipeManager.recipes, recipe); + } + + @Override + public String getRecipeInfo() { + if (recipe instanceof Smelting) + return " Input:" + ((Smelting) recipe).getResource().getDisplayName(); + else + return "Output: " + ((Recipe) recipe).asIRecipe().getRecipeOutput().getDisplayName(); + } + } + + /* + Implements the actions to remove a smelting recipe + */ + private static class RemoveSmelting extends BaseListRemoval { + + public RemoveSmelting(ItemStack input) { + super("Forestry Thermionic Fabricator (Smelting)", RecipeManager.smeltings, input); + } + + @Override + public void apply() { + for (Smelting r : RecipeManager.smeltings) { + if (r.getResource() != null && r.getResource().isItemEqual(stack)) { + RecipeManager.smeltings.remove(r); + recipe = r; + break; + } + } + } + + @Override + public String getRecipeInfo() { + return " Input:" + stack.getDisplayName(); // + " -- Output:" + ((Smelting) recipe).getProduct().getLocalizedName(); + } + } + + /* + Implements the actions to remove a casting recipe + */ + private static class RemoveCastings extends BaseListRemoval { + + public RemoveCastings(ItemStack output) { + super("Forestry Thermionic Fabricator (Casting)", RecipeManager.recipes, output); + } + + @Override + public void apply() { + for (Recipe r : RecipeManager.recipes) { + if (r.asIRecipe().getRecipeOutput() != null && r.asIRecipe().getRecipeOutput().isItemEqual(stack)) { + RecipeManager.recipes.remove(r); + recipe = r; + } + } + } + + @Override + public String getRecipeInfo() { + return " Output:" + stack.getDisplayName(); // + " -- Output:" + ((Recipe) recipe).asIRecipe().getIngredients()[0].getDisplayName(); + } + } +}