From c8e7e923ed8134fe25784300a15c7740258b0f9c Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 27 Aug 2015 09:04:41 +0100 Subject: [PATCH] Added more minetweaker support --- .../minetweaker/MTAssemblingMachine.java | 133 ++++++++++++++++++ .../compat/minetweaker/MTBlastFurnace.java | 132 +++++++++++++++++ .../compat/minetweaker/MTCentrifuge.java | 132 +++++++++++++++++ .../compat/minetweaker/MinetweakerCompat.java | 6 +- 4 files changed, 400 insertions(+), 3 deletions(-) create mode 100644 src/main/java/techreborn/compat/minetweaker/MTAssemblingMachine.java create mode 100644 src/main/java/techreborn/compat/minetweaker/MTBlastFurnace.java create mode 100644 src/main/java/techreborn/compat/minetweaker/MTCentrifuge.java diff --git a/src/main/java/techreborn/compat/minetweaker/MTAssemblingMachine.java b/src/main/java/techreborn/compat/minetweaker/MTAssemblingMachine.java new file mode 100644 index 000000000..f57467449 --- /dev/null +++ b/src/main/java/techreborn/compat/minetweaker/MTAssemblingMachine.java @@ -0,0 +1,133 @@ +package techreborn.compat.minetweaker; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import techreborn.api.recipe.IBaseRecipeType; +import techreborn.api.recipe.RecipeHandler; +import techreborn.api.recipe.machines.AssemblingMachineRecipe; +import techreborn.lib.Reference; +import techreborn.util.ItemUtils; + +import java.util.List; + +@ZenClass("mods.techreborn.assemblingMachine") +public class MTAssemblingMachine { + + @ZenMethod + public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) { + ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1); + if (oInput1 == null) + return; + + ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2); + if (oInput2 == null) + return; + + AssemblingMachineRecipe r = new AssemblingMachineRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick); + + MineTweakerAPI.apply(new Add(r)); + } + + private static class Add implements IUndoableAction { + private final AssemblingMachineRecipe recipe; + + public Add(AssemblingMachineRecipe recipe) { + this.recipe = recipe; + } + + @Override + public void apply() { + RecipeHandler.addRecipe(recipe); + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + RecipeHandler.recipeList.remove(recipe); + } + + @Override + public String describe() { + return "Adding Assembling Machine Recipe for " + recipe.getOutput(0).getDisplayName(); + } + + @Override + public String describeUndo() { + return "Removing Assembling Machine Recipe for " + recipe.getOutput(0).getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } + + @ZenMethod + public static void removeRecipe(IItemStack output) + { + MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output))); + } + private static class Remove implements IUndoableAction + { + private final ItemStack output; + List removedRecipes; + public Remove(ItemStack output) + { + this.output = output; + } + @Override + public void apply() + { + for(IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.assemblingMachineRecipe)){ + for(ItemStack stack : recipeType.getOutputs()){ + if(ItemUtils.isItemEqual(stack, output, true, false)){ + removedRecipes.add((AssemblingMachineRecipe) recipeType); + RecipeHandler.recipeList.remove(recipeType); + break; + } + } + } + } + @Override + public void undo() + { + if(removedRecipes!=null){ + for(AssemblingMachineRecipe recipe : removedRecipes){ + if(recipe!=null){ + RecipeHandler.addRecipe(recipe); + } + } + } + + } + @Override + public String describe() + { + return "Removing Assembling Machine Recipe for " + output.getDisplayName(); + } + @Override + public String describeUndo() + { + return "Re-Adding Assembling Machine Recipe for " + output.getDisplayName(); + } + @Override + public Object getOverrideKey() + { + return null; + } + @Override + public boolean canUndo() + { + return true; + } + } +} diff --git a/src/main/java/techreborn/compat/minetweaker/MTBlastFurnace.java b/src/main/java/techreborn/compat/minetweaker/MTBlastFurnace.java new file mode 100644 index 000000000..97b9e3adb --- /dev/null +++ b/src/main/java/techreborn/compat/minetweaker/MTBlastFurnace.java @@ -0,0 +1,132 @@ +package techreborn.compat.minetweaker; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import techreborn.api.recipe.IBaseRecipeType; +import techreborn.api.recipe.RecipeHandler; +import techreborn.api.recipe.machines.BlastFurnaceRecipe; +import techreborn.lib.Reference; +import techreborn.util.ItemUtils; + +import java.util.List; + +@ZenClass("mods.techreborn.blastFurnace") +public class MTBlastFurnace { + @ZenMethod + public static void addRecipe(IItemStack output1,IItemStack output2, IIngredient input1, IIngredient input2, int ticktime, int euTick, int neededHeat) { + ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1); + if (oInput1 == null) + return; + + ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2); + if (oInput2 == null) + return; + + BlastFurnaceRecipe r = new BlastFurnaceRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output1), MinetweakerCompat.toStack(output2), ticktime, euTick, neededHeat); + + MineTweakerAPI.apply(new Add(r)); + } + + private static class Add implements IUndoableAction { + private final BlastFurnaceRecipe recipe; + + public Add(BlastFurnaceRecipe recipe) { + this.recipe = recipe; + } + + @Override + public void apply() { + RecipeHandler.addRecipe(recipe); + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + RecipeHandler.recipeList.remove(recipe); + } + + @Override + public String describe() { + return "Adding Blast Furnace Recipe for " + recipe.getOutput(0).getDisplayName(); + } + + @Override + public String describeUndo() { + return "Removing Blast Furnace Recipe for " + recipe.getOutput(0).getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } + + @ZenMethod + public static void removeRecipe(IItemStack output) + { + MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output))); + } + private static class Remove implements IUndoableAction + { + private final ItemStack output; + List removedRecipes; + public Remove(ItemStack output) + { + this.output = output; + } + @Override + public void apply() + { + for(IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.blastFurnaceRecipe)){ + for(ItemStack stack : recipeType.getOutputs()){ + if(ItemUtils.isItemEqual(stack, output, true, false)){ + removedRecipes.add((BlastFurnaceRecipe) recipeType); + RecipeHandler.recipeList.remove(recipeType); + break; + } + } + } + } + @Override + public void undo() + { + if(removedRecipes!=null){ + for(BlastFurnaceRecipe recipe : removedRecipes){ + if(recipe!=null){ + RecipeHandler.addRecipe(recipe); + } + } + } + + } + @Override + public String describe() + { + return "Removing Blast Furnace Recipe for " + output.getDisplayName(); + } + @Override + public String describeUndo() + { + return "Re-Adding Blast Furnace Recipe for " + output.getDisplayName(); + } + @Override + public Object getOverrideKey() + { + return null; + } + @Override + public boolean canUndo() + { + return true; + } + } +} diff --git a/src/main/java/techreborn/compat/minetweaker/MTCentrifuge.java b/src/main/java/techreborn/compat/minetweaker/MTCentrifuge.java new file mode 100644 index 000000000..cb47f71a3 --- /dev/null +++ b/src/main/java/techreborn/compat/minetweaker/MTCentrifuge.java @@ -0,0 +1,132 @@ +package techreborn.compat.minetweaker; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import techreborn.api.recipe.IBaseRecipeType; +import techreborn.api.recipe.RecipeHandler; +import techreborn.api.recipe.machines.CentrifugeRecipe; +import techreborn.lib.Reference; +import techreborn.util.ItemUtils; + +import java.util.List; + +@ZenClass("mods.techreborn.centrifuge") +public class MTCentrifuge { + @ZenMethod + public static void addRecipe(IItemStack output1,IItemStack output2,IItemStack output3,IItemStack output4, IIngredient input1, IIngredient input2, int ticktime, int euTick) { + ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1); + if (oInput1 == null) + return; + + ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2); + if (oInput2 == null) + return; + + CentrifugeRecipe r = new CentrifugeRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output1), MinetweakerCompat.toStack(output2),MinetweakerCompat.toStack(output3), MinetweakerCompat.toStack(output4), ticktime, euTick); + + MineTweakerAPI.apply(new Add(r)); + } + + private static class Add implements IUndoableAction { + private final CentrifugeRecipe recipe; + + public Add(CentrifugeRecipe recipe) { + this.recipe = recipe; + } + + @Override + public void apply() { + RecipeHandler.addRecipe(recipe); + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + RecipeHandler.recipeList.remove(recipe); + } + + @Override + public String describe() { + return "Adding Centrifuge Recipe for " + recipe.getOutput(0).getDisplayName(); + } + + @Override + public String describeUndo() { + return "Removing Centrifuge Recipe for " + recipe.getOutput(0).getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } + + @ZenMethod + public static void removeRecipe(IItemStack output) + { + MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output))); + } + private static class Remove implements IUndoableAction + { + private final ItemStack output; + List removedRecipes; + public Remove(ItemStack output) + { + this.output = output; + } + @Override + public void apply() + { + for(IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.centrifugeRecipe)){ + for(ItemStack stack : recipeType.getOutputs()){ + if(ItemUtils.isItemEqual(stack, output, true, false)){ + removedRecipes.add((CentrifugeRecipe) recipeType); + RecipeHandler.recipeList.remove(recipeType); + break; + } + } + } + } + @Override + public void undo() + { + if(removedRecipes!=null){ + for(CentrifugeRecipe recipe : removedRecipes){ + if(recipe!=null){ + RecipeHandler.addRecipe(recipe); + } + } + } + + } + @Override + public String describe() + { + return "Removing Centrifuge Recipe for " + output.getDisplayName(); + } + @Override + public String describeUndo() + { + return "Re-Adding Centrifuge Recipe for " + output.getDisplayName(); + } + @Override + public Object getOverrideKey() + { + return null; + } + @Override + public boolean canUndo() + { + return true; + } + } +} diff --git a/src/main/java/techreborn/compat/minetweaker/MinetweakerCompat.java b/src/main/java/techreborn/compat/minetweaker/MinetweakerCompat.java index 190e16e7e..323413b2c 100644 --- a/src/main/java/techreborn/compat/minetweaker/MinetweakerCompat.java +++ b/src/main/java/techreborn/compat/minetweaker/MinetweakerCompat.java @@ -9,14 +9,11 @@ import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; import minetweaker.api.item.IngredientStack; -import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.oredict.IOreDictEntry; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; import techreborn.compat.ICompatModule; import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getLiquidStack; public class MinetweakerCompat implements ICompatModule { @@ -33,6 +30,9 @@ public class MinetweakerCompat implements ICompatModule { @Override public void postInit(FMLPostInitializationEvent event) { MineTweakerAPI.registerClass(MTAlloySmelter.class); + MineTweakerAPI.registerClass(MTAssemblingMachine.class); + MineTweakerAPI.registerClass(MTBlastFurnace.class); + MineTweakerAPI.registerClass(MTCentrifuge.class); } @Override