diff --git a/java/ec3/common/mod/EssentialCraftCore.java b/java/ec3/common/mod/EssentialCraftCore.java index dcd4439d..7ae7c6f3 100755 --- a/java/ec3/common/mod/EssentialCraftCore.java +++ b/java/ec3/common/mod/EssentialCraftCore.java @@ -6,6 +6,7 @@ import net.minecraft.command.CommandHandler; import net.minecraft.server.MinecraftServer; import DummyCore.Core.Core; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -34,6 +35,7 @@ import ec3.common.registry.StructureRegistry; import ec3.common.registry.VillagersRegistry; import ec3.common.world.WorldGenManager; +import ec3.integration.minetweaker.MTRegistry; import ec3.integration.rotarycraft.RCLoadingHandler; import ec3.integration.versionChecker.Check; import ec3.integration.waila.WailaInitialiser; @@ -97,6 +99,23 @@ public void beforeMinecraftLoaded(FMLPreInitializationEvent event) Check.checkerCommit(); WailaInitialiser.sendIMC(); RCLoadingHandler.runPreInitChecks(); + + if(Loader.isModLoaded("MineTweaker3")) + { + try + { + MTRegistry.init(); + } + catch(Exception ex) + { + System.out.println("[EssentialCraft3]Unable to add MineTweaker3 integration!"); + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + } + else + System.out.println("[EssentialCraft3]Unable to add MineTweaker3 integration - mod not found"); + } @EventHandler diff --git a/java/ec3/integration/minetweaker/MTRegistry.java b/java/ec3/integration/minetweaker/MTRegistry.java new file mode 100644 index 00000000..3ee91b46 --- /dev/null +++ b/java/ec3/integration/minetweaker/MTRegistry.java @@ -0,0 +1,15 @@ +package ec3.integration.minetweaker; + +import minetweaker.MineTweakerAPI; + +public class MTRegistry { + + public static void init() + { + MineTweakerAPI.registerClass(MagicianTable.class); + MineTweakerAPI.registerClass(WindImbue.class); + MineTweakerAPI.registerClass(MithrilineFurnace.class); + MineTweakerAPI.registerClass(RadiatingChamber.class); + } + +} diff --git a/java/ec3/integration/minetweaker/MagicianTable.java b/java/ec3/integration/minetweaker/MagicianTable.java new file mode 100644 index 00000000..442daa05 --- /dev/null +++ b/java/ec3/integration/minetweaker/MagicianTable.java @@ -0,0 +1,175 @@ +package ec3.integration.minetweaker; + +import java.util.ArrayList; +import java.util.List; + +import DummyCore.Utils.UnformedItemStack; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.data.DataInt; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import ec3.api.MagicianTableRecipe; +import ec3.api.MagicianTableRecipes; +import scala.actors.threadpool.Arrays; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +/** + * + * @author Artem226 + * + * @Description Adding/removing MagicianTable recipes + * + */ +@ZenClass("mods.ec3.MagicianTable") +public class MagicianTable { + + public MagicianTable() { + // TODO Auto-generated constructor stub + } + + @ZenMethod + public static void add(IItemStack output, IIngredient[] ingredients, int mru) + { + List items = new ArrayList(); + + if(ingredients!=null && ingredients.length > 0) + { + for(IIngredient in : ingredients) + { + items.add(SomeMTUtils.toUnformedIS(in)); + } + + UnformedItemStack[] stack = new UnformedItemStack[items.size()]; + + for(int i = 0; i < items.size(); i++) + { + stack[i] = items.get(i); + } + + + + MineTweakerAPI.apply(new Add(new MagicianTableRecipe(stack, SomeMTUtils.toItem(output).copy(), mru))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void remove(IItemStack recipeOutput) + { + if(recipeOutput != null) + { + MineTweakerAPI.apply(new Remove(SomeMTUtils.toItem(recipeOutput))); + } + else + MineTweakerAPI.getLogger().logError("Target item can't be null!"); + } + + private static class Add implements IUndoableAction { + MagicianTableRecipe recipe; + + public Add(MagicianTableRecipe add){ + recipe = add; + } + + @Override + public void apply(){ + + MagicianTableRecipes.addRecipe(recipe); + } + + @Override + public boolean canUndo(){ + return true; + } + + @Override + public void undo(){ + MagicianTableRecipes.recipes.remove(Arrays.asList(recipe.requiredItems)); + ItemStack search = recipe.result.copy(); + search.stackSize = 0; + String searchStr = search.toString(); + search = null; + MagicianTableRecipes.recipesByIS.remove(searchStr); + MagicianTableRecipes.craftMatrixByID.remove(Arrays.asList(recipe.requiredItems)); + } + + @Override + public String describe(){ + return "Adding magician table recipe: "+recipe.getRecipeOutput().getDisplayName(); + + } + + @Override + public String describeUndo(){ + return "UnAdding magician table recipe: " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + } + + private static class Remove implements IUndoableAction { + MagicianTableRecipe recipe = null; + ItemStack ToRemove; + + public Remove(ItemStack rem){ + ToRemove = rem; + } + + @Override + public void apply(){ + MagicianTableRecipe rec = MagicianTableRecipes.getRecipeByResult(ToRemove); + + if(rec != null) + { + MagicianTableRecipes.recipes.remove(Arrays.asList(rec.requiredItems)); + ItemStack search = rec.result.copy(); + search.stackSize = 0; + String searchStr = search.toString(); + search = null; + MagicianTableRecipes.recipesByIS.remove(searchStr); + MagicianTableRecipes.craftMatrixByID.remove(Arrays.asList(rec.requiredItems)); + + recipe = rec; + } + else + MineTweakerAPI.getLogger().logError("Magician table recipe from "+ToRemove.getDisplayName()+" not found!"); + } + + @Override + public boolean canUndo(){ + return recipe != null; + } + + @Override + public void undo(){ + MagicianTableRecipes.addRecipe(recipe); + } + + @Override + public String describe(){ + return "Removing magician table recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public String describeUndo(){ + return "UnRemoving magician table recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + } +} diff --git a/java/ec3/integration/minetweaker/MithrilineFurnace.java b/java/ec3/integration/minetweaker/MithrilineFurnace.java new file mode 100644 index 00000000..94a379a1 --- /dev/null +++ b/java/ec3/integration/minetweaker/MithrilineFurnace.java @@ -0,0 +1,143 @@ +package ec3.integration.minetweaker; + +import net.minecraft.item.ItemStack; +import ec3.api.MagicianTableRecipe; +import ec3.api.MithrilineFurnaceRecipe; +import ec3.api.MithrilineFurnaceRecipes; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.data.DataFloat; +import minetweaker.api.data.DataInt; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.ec3.MithrilineFurnace") +/** + * + * @author Artem226 + * + * @Description Adding/removing MithrilineFurnace recipes + * + */ +public class MithrilineFurnace { + + public MithrilineFurnace() { + // TODO Auto-generated constructor stub + } + + @ZenMethod + public static void add(IItemStack output, IIngredient ingredient, int stackSizeOfIngr, int enderpower) + { + MineTweakerAPI.apply(new Add(new MithrilineFurnaceRecipe(SomeMTUtils.toUnformedIS(ingredient), SomeMTUtils.toItem(output), enderpower, stackSizeOfIngr))); + } + + @ZenMethod + public static void remove(IItemStack recipeOutput) + { + if(recipeOutput != null) + { + MineTweakerAPI.apply(new Remove(SomeMTUtils.toItem(recipeOutput))); + } + else + MineTweakerAPI.getLogger().logError("Target item can't be null!"); + } + + private static class Add implements IUndoableAction { + MithrilineFurnaceRecipe recipe; + + public Add(MithrilineFurnaceRecipe rec) + { + recipe = rec; + } + + @Override + public void apply() { + MithrilineFurnaceRecipes.addRecipe(recipe); + + } + + @Override + public boolean canUndo() { + + return recipe !=null; + } + + @Override + public void undo() { + MithrilineFurnaceRecipes.allRegisteredRecipes.remove(recipe); + + } + + @Override + public String describe() { + + return "Adding Mithriline Furnace recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public String describeUndo() { + + return "UnAdding Mithriline Furnace recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + + return null; + } + } + + private static class Remove implements IUndoableAction { + MithrilineFurnaceRecipe recipe = null; + ItemStack ToRemove; + + public Remove(ItemStack rem) + { + ToRemove = rem; + } + + @Override + public void apply() { + MithrilineFurnaceRecipe rec = MithrilineFurnaceRecipes.findRecipeByResult(ToRemove); + + if(rec != null) + { + MithrilineFurnaceRecipes.allRegisteredRecipes.remove(rec); + recipe = rec; + } + + } + + @Override + public boolean canUndo() { + + return recipe != null; + } + + @Override + public void undo() { + MithrilineFurnaceRecipes.addRecipe(recipe); + + } + + @Override + public String describe() { + + return "Removing Mithriline Furnace recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public String describeUndo() { + + return "UnRemoving Mithriline Furnace recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + + return null; + } + } +} diff --git a/java/ec3/integration/minetweaker/RadiatingChamber.java b/java/ec3/integration/minetweaker/RadiatingChamber.java new file mode 100644 index 00000000..971248c4 --- /dev/null +++ b/java/ec3/integration/minetweaker/RadiatingChamber.java @@ -0,0 +1,277 @@ +package ec3.integration.minetweaker; + +import java.util.ArrayList; +import java.util.List; + +import DummyCore.Utils.UnformedItemStack; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.data.DataFloat; +import minetweaker.api.data.DataInt; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import ec3.api.RadiatingChamberRecipe; +import ec3.api.RadiatingChamberRecipes; +import scala.actors.threadpool.Arrays; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +/** + * + * @author Artem226 + * + * @Description Adding/removing RadiatingChamber recipes + * + */ +@ZenClass("mods.ec3.RadiatingChamber") +public class RadiatingChamber { + + public RadiatingChamber() { + // TODO Auto-generated constructor stub + } + + @ZenMethod + public static void add(IItemStack output, IItemStack[] ingredients, int mru, float upperBalance, float lowerBalance, float modifier, int size) + { + + + if(ingredients!=null && ingredients.length > 0 ) + { + MineTweakerAPI.apply(new Add(new RadiatingChamberRecipe(SomeMTUtils.toItem(ingredients), SomeMTUtils.toItem(output), mru, new float[]{upperBalance,lowerBalance}, modifier, size))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void add(IItemStack output, IItemStack[] ingredients, int mru, float upperBalance, float lowerBalance, int size) + { + + + if(ingredients!=null && ingredients.length > 0 ) + { + MineTweakerAPI.apply(new Add(new RadiatingChamberRecipe(SomeMTUtils.toItem(ingredients), SomeMTUtils.toItem(output), mru, new float[]{upperBalance,lowerBalance}, 1, size))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void add(IItemStack output, IItemStack[] ingredients, int mru, float upperBalance, float lowerBalance) + { + + + if(ingredients!=null && ingredients.length > 0 ) + { + MineTweakerAPI.apply(new Add(new RadiatingChamberRecipe(SomeMTUtils.toItem(ingredients), SomeMTUtils.toItem(output), mru, new float[]{upperBalance,lowerBalance}, 1, 1))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void add(IItemStack output, IItemStack[] ingredients, int mru, float modifier, int size) + { + + + if(ingredients!=null && ingredients.length > 0 ) + { + MineTweakerAPI.apply(new Add(new RadiatingChamberRecipe(SomeMTUtils.toItem(ingredients), SomeMTUtils.toItem(output), mru, new float[]{Float.MAX_VALUE,Float.MIN_VALUE}, modifier, size))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void add(IItemStack output, IItemStack[] ingredients, int mru, float modifier) + { + + + if(ingredients!=null && ingredients.length > 0 ) + { + MineTweakerAPI.apply(new Add(new RadiatingChamberRecipe(SomeMTUtils.toItem(ingredients), SomeMTUtils.toItem(output), mru, new float[]{Float.MAX_VALUE,Float.MIN_VALUE}, modifier, 1))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void add(IItemStack output, IItemStack[] ingredients, int mru) + { + + + if(ingredients!=null && ingredients.length > 0 ) + { + MineTweakerAPI.apply(new Add(new RadiatingChamberRecipe(SomeMTUtils.toItem(ingredients), SomeMTUtils.toItem(output), mru, new float[]{Float.MAX_VALUE,Float.MIN_VALUE}, 1, 1))); + } + else + { + MineTweakerAPI.getLogger().logError("Ingredients can't be null!"); + } + + } + + @ZenMethod + public static void remove(IItemStack recipeOutput) + { + if(recipeOutput != null) + { + MineTweakerAPI.apply(new Remove(SomeMTUtils.toItem(recipeOutput))); + } + else + MineTweakerAPI.getLogger().logError("Target item can't be null!"); + } + + + private static class Add implements IUndoableAction { + RadiatingChamberRecipe recipe; + + public Add(RadiatingChamberRecipe add){ + recipe = add; + } + + @Override + public void apply(){ + + RadiatingChamberRecipes.addRecipe(recipe); + } + + @Override + public boolean canUndo(){ + return true; + } + + @Override + public void undo(){ + + ItemStack[] req = new ItemStack[recipe.recipeItems.length]; + for(int i = 0; i < req.length;++i) + { + if(recipe.recipeItems[i] != null) + req[i] = recipe.recipeItems[i].copy(); + else + req[i] = null; + } + for(int i = 0; i < req.length; ++i) + { + if(req[i] != null) + req[i].stackSize = 0; + } + if(RadiatingChamberRecipes.recipes.containsKey(Arrays.toString(req))) + RadiatingChamberRecipes.recipes.remove(Arrays.toString(req)); + + ItemStack search = recipe.result.copy(); + search.stackSize = 0; + String searchStr = search.toString(); + search = null; + + RadiatingChamberRecipes.recipesByIS.remove(searchStr); + RadiatingChamberRecipes.craftMatrixByID.remove(Arrays.toString(req)); + req = null; + } + + @Override + public String describe(){ + return "Adding Radiating Chamber recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public String describeUndo(){ + return "UnAdding Radiating Chamber recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + } + + private static class Remove implements IUndoableAction { + RadiatingChamberRecipe recipe = null; + ItemStack ToRemove; + + public Remove(ItemStack rem){ + ToRemove = rem; + } + + @Override + public void apply(){ + RadiatingChamberRecipe rec = RadiatingChamberRecipes.getRecipeByResult(ToRemove); + + if(rec != null) + { + ItemStack[] req = new ItemStack[rec.recipeItems.length]; + for(int i = 0; i < req.length;++i) + { + if(rec.recipeItems[i] != null) + req[i] = rec.recipeItems[i].copy(); + else + req[i] = null; + } + for(int i = 0; i < req.length; ++i) + { + if(req[i] != null) + req[i].stackSize = 0; + } + if(RadiatingChamberRecipes.recipes.containsKey(Arrays.toString(req))) + RadiatingChamberRecipes.recipes.remove(Arrays.toString(req)); + + ItemStack search = recipe.result.copy(); + search.stackSize = 0; + String searchStr = search.toString(); + search = null; + + RadiatingChamberRecipes.recipesByIS.remove(searchStr); + RadiatingChamberRecipes.craftMatrixByID.remove(Arrays.toString(req)); + req = null; + + recipe = rec; + } + else + MineTweakerAPI.getLogger().logError("Radiating Chamber Recipe from "+ToRemove.getDisplayName()+" not found!"); + } + + @Override + public boolean canUndo(){ + return recipe != null; + } + + @Override + public void undo(){ + RadiatingChamberRecipes.addRecipe(recipe); + } + + @Override + public String describe(){ + return "Removing Radiating Chamber recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public String describeUndo(){ + return "UnRemoving Radiating Chamber recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + } +} diff --git a/java/ec3/integration/minetweaker/SomeMTUtils.java b/java/ec3/integration/minetweaker/SomeMTUtils.java new file mode 100644 index 00000000..b5577891 --- /dev/null +++ b/java/ec3/integration/minetweaker/SomeMTUtils.java @@ -0,0 +1,104 @@ +package ec3.integration.minetweaker; + +import java.util.ArrayList; +import java.util.List; + +import DummyCore.Utils.UnformedItemStack; +import net.minecraft.item.ItemStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import minetweaker.api.oredict.IOreDictEntry; + +public class SomeMTUtils { + + public SomeMTUtils() { + // TODO Auto-generated constructor stub + } + + + public static ItemStack toItem(IItemStack item) + { + + if (item == null) + return null; + else + { + Object internal = item.getInternal(); + if (internal == null || !(internal instanceof ItemStack)) + { + MineTweakerAPI.getLogger().logError("Not a valid item stack: " + item); + } + return ((ItemStack)internal).copy(); + } + + + } + + public static ItemStack[] toItem(IItemStack[] item) + { + + if (item == null) + return null; + else + { + List internal = new ArrayList(); + for(IItemStack it : item) + { + internal.add(it.getInternal()); + } + + for(Object o : internal) + if (o == null || !(o instanceof ItemStack)) + { + MineTweakerAPI.getLogger().logError("Not a valid item stack: " + item); + } + + ItemStack[] stack = new ItemStack[internal.size()]; + + for(int i = 0; i < internal.size(); i++) + { + stack[i] = (ItemStack) internal.get(i); + } + + + return stack; + } + + + } + + public static String OreToString(IOreDictEntry entry) + { + return ((IOreDictEntry) entry).getName(); + } + + public static UnformedItemStack toUnformedIS(IIngredient ingredient){ + if (ingredient == null) + return null; + else { + if (ingredient instanceof IOreDictEntry) + { + return new UnformedItemStack((String)OreToString((IOreDictEntry) ingredient)); + } + else if (ingredient instanceof IItemStack) + { + return new UnformedItemStack(((ItemStack)toItem((IItemStack)ingredient)).copy()); + } + else return null; + } + } + + public static ItemStack ingrToItem(IIngredient ing) + { + if (ing == null) + return null; + else { + if (ing instanceof IItemStack) + { + return toItem((IItemStack) ing).copy(); + } + else return null; + } + } +} diff --git a/java/ec3/integration/minetweaker/WindImbue.java b/java/ec3/integration/minetweaker/WindImbue.java new file mode 100644 index 00000000..4b95751d --- /dev/null +++ b/java/ec3/integration/minetweaker/WindImbue.java @@ -0,0 +1,129 @@ +package ec3.integration.minetweaker; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.data.DataInt; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import ec3.api.MagicianTableRecipe; +import ec3.api.MagicianTableRecipes; +import ec3.api.WindImbueRecipe; +import scala.actors.threadpool.Arrays; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.ec3.WindImbue") +public class WindImbue { + + public WindImbue() { + // TODO Auto-generated constructor stub + } + + @ZenMethod + public static void add(IItemStack output, IItemStack input, int energy) + { + MineTweakerAPI.apply(new Add(SomeMTUtils.toItem(input), SomeMTUtils.toItem(output), energy)); + } + + @ZenMethod + public static void remove(IItemStack output) + { + MineTweakerAPI.apply(new Remove(SomeMTUtils.toItem(output))); + } + + + + private static class Add implements IUndoableAction { + WindImbueRecipe recipe; + ItemStack input; + ItemStack output; + int energy; + + public Add(ItemStack in, ItemStack out, int energy){ + input = in; + output = out; + this.energy = energy; + } + + @Override + public void apply(){ + + recipe = new WindImbueRecipe(input, output, energy); + } + + @Override + public boolean canUndo(){ + return recipe != null; + } + + @Override + public void undo(){ + WindImbueRecipe.recipes.remove(recipe); + } + + @Override + public String describe(){ + return "Adding wind imbue recipe for " + output.getDisplayName(); + } + + @Override + public String describeUndo(){ + return "UnAdding wind imbue recipe for " + output.getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + } + + private static class Remove implements IUndoableAction { + WindImbueRecipe recipe = null; + ItemStack ToRemove; + + public Remove(ItemStack rem){ + ToRemove = rem; + } + + @Override + public void apply(){ + WindImbueRecipe rec = WindImbueRecipe.findRecipeByResult(ToRemove); + + if(rec != null) + { + WindImbueRecipe.recipes.remove(rec); + recipe = rec; + } + else + MineTweakerAPI.getLogger().logError("Wind Imbue recipe from "+ToRemove.getDisplayName()+" not found!"); + } + + @Override + public boolean canUndo(){ + return recipe != null; + } + + @Override + public void undo(){ + WindImbueRecipe.recipes.add(recipe); + } + + @Override + public String describe(){ + return "Removing wind imbue recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public String describeUndo(){ + return "UnRemoving wind imbue recipe for " + recipe.getRecipeOutput().getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + } +}