diff --git a/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java index e96c3b6..5b8d225 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java @@ -1,17 +1,16 @@ package modtweaker2.mods.exnihilo.handlers; import static modtweaker2.helpers.InputHelper.toStack; +import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; -import modtweaker2.utils.BaseMapAddition; -import modtweaker2.utils.BaseMapRemoval; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import exnihilo.registries.CompostRegistry; import exnihilo.registries.helpers.Color; -import exnihilo.registries.helpers.Compostable; @ZenClass("mods.exnihilo.Composting") public class Compost { @@ -19,19 +18,54 @@ public class Compost { @ZenMethod public static void addRecipe(IItemStack input, double value, @Optional String hex) { hex = (hex == null || hex.equals("")) ? "35A82A" : hex; - MineTweakerAPI.apply(new Add(new Compostable(toStack(input).getItem(), toStack(input).getItemDamage(), Math.min(1.0F, (float) value), new Color(hex)))); + MineTweakerAPI.apply(new Add(toStack(input).getItem(), toStack(input).getItemDamage(), Math.min(1.0F, (float) value), new Color(hex))); } //Passes the list to the map list implementation, and adds the recipe - private static class Add extends BaseMapAddition { - public Add(Compostable recipe) { - super("ExNihilo Composting", CompostRegistry.entries, recipe.item + ":" + recipe.meta, recipe); + private static class Add implements IUndoableAction + { + private Item item; + private int meta; + private float value; + private Color color; + + public Add(Item item, int meta, float value, Color color) { + this.item = item; + this.meta = meta; + this.value = value; + this.color = color; } - @Override - public String getRecipeInfo() { - return new ItemStack(((Compostable) recipe).item, 1, ((Compostable) recipe).meta).getDisplayName(); - } + @Override + public void apply() { + CompostRegistry.register(item, meta, value, color); + } + + @Override + public boolean canUndo() { + return false; + } + + @Override + public String describe() { + return "Adding Composting Recipe using " + item.getUnlocalizedName(); + } + + @Override + public String describeUndo() { + return null; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public void undo() { + + } + } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -43,14 +77,41 @@ public class Compost { } //Removes a recipe, will always remove the key, so all should be good - private static class Remove extends BaseMapRemoval { + private static class Remove implements IUndoableAction + { + private ItemStack stack; + public Remove(ItemStack stack) { - super("ExNihilo Composting", CompostRegistry.entries, stack.getItem() + ":" + stack.getItemDamage(), stack); + this.stack = stack; } - @Override - public String getRecipeInfo() { - return ((ItemStack) stack).getDisplayName(); - } + @Override + public void apply() { + CompostRegistry.unregister(stack.getItem(), stack.getItemDamage()); + } + + @Override + public boolean canUndo() { + return false; + } + + @Override + public String describe() { + return "Removing Composting Recipe using " + stack.getUnlocalizedName(); + } + + @Override + public String describeUndo() { + return null; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public void undo() { + } } } diff --git a/src/main/java/modtweaker2/mods/exnihilo/handlers/Crucible.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Crucible.java index fce6f57..b0a3f32 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Crucible.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Crucible.java @@ -3,6 +3,7 @@ package modtweaker2.mods.exnihilo.handlers; import static modtweaker2.helpers.InputHelper.isABlock; import static modtweaker2.helpers.InputHelper.toFluid; import static modtweaker2.helpers.InputHelper.toStack; +import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; import minetweaker.api.liquid.ILiquidStack; @@ -14,7 +15,6 @@ import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import exnihilo.registries.CrucibleRegistry; import exnihilo.registries.HeatRegistry; -import exnihilo.registries.helpers.HeatSource; import exnihilo.registries.helpers.Meltable; @ZenClass("mods.exnihilo.Crucible") @@ -72,21 +72,47 @@ public class Crucible { if (isABlock(input)) { Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new AddHeatSource(new HeatSource(theBlock, theMeta, (float) value))); + MineTweakerAPI.apply(new AddHeatSource(theBlock, theMeta, (float) value)); } } //Passes the list to the base map implementation, and adds the recipe - private static class AddHeatSource extends BaseMapAddition { - public AddHeatSource(HeatSource recipe) { - super("ExNihilo Crucible - Heat Source", HeatRegistry.entries, recipe.block + ":" + recipe.meta, recipe); - } + private static class AddHeatSource implements IUndoableAction + { + Block source; + int sourceMeta; + float value; + + public AddHeatSource(Block source, int sourceMeta, float value) { + this.source = source; + this.sourceMeta = sourceMeta; + this.value = value; + } + + public void apply() { + HeatRegistry.register(source, sourceMeta, value); + } + + public boolean canUndo() { + return false; + } + + public String describe() { + return "Adding ExNihilo Heat source of " + source.getLocalizedName(); + } + + public String describeUndo() { + return null; + } + + public Object getOverrideKey() { + return null; + } + + public void undo() { + } + } - @Override - public String getRecipeInfo() { - return new ItemStack(((HeatSource) recipe).block, 1, ((HeatSource) recipe).meta).getDisplayName(); - } - } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -94,19 +120,41 @@ public class Crucible { @ZenMethod public static void removeHeatSource(IItemStack output) { if (isABlock(output)) { - MineTweakerAPI.apply(new RemoveHeatSource(toStack(output))); + Block block = Block.getBlockFromItem(toStack(output).getItem()); + MineTweakerAPI.apply(new RemoveHeatSource(block)); } } //Removes a recipe, will always remove the key, so all should be good - private static class RemoveHeatSource extends BaseMapRemoval { - public RemoveHeatSource(ItemStack stack) { - super("ExNihilo Crucible - Heat Source", HeatRegistry.entries, Block.getBlockFromItem(stack.getItem()) + ":" + stack.getItemDamage(), stack); + private static class RemoveHeatSource implements IUndoableAction + { + Block block; + + public RemoveHeatSource(Block block) { + this.block = block; } - @Override - public String getRecipeInfo() { - return ((ItemStack) stack).getDisplayName(); - } - } + public void apply() { + HeatRegistry.unregister(block); + } + + public boolean canUndo() { + return false; + } + + public String describe() { + return "Removing ExNihilo Heat source of " + block.getLocalizedName(); + } + + public String describeUndo() { + return null; + } + + public Object getOverrideKey() { + return null; + } + + public void undo() { + } + } } diff --git a/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java index 72268ed..e3e4f0d 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java @@ -3,14 +3,13 @@ package modtweaker2.mods.exnihilo.handlers; import static modtweaker2.helpers.InputHelper.isABlock; import static modtweaker2.helpers.InputHelper.toStack; -import java.util.Iterator; +import java.util.List; +import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; -import modtweaker2.utils.BaseListAddition; -import modtweaker2.utils.BaseListRemoval; import net.minecraft.block.Block; -import net.minecraft.init.Blocks; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @@ -25,19 +24,50 @@ public class Hammer { if (isABlock(input)) { Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new Add(new Smashable(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), (float) chance, (float) luck))); + MineTweakerAPI.apply(new Add(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), (float) chance, (float) luck)); } } // Passes the list to the base list implementation, and adds the recipe - private static class Add extends BaseListAddition { - public Add(Smashable recipe) { - super("ExNihilo Hammer", HammerRegistry.rewards, recipe); + private static class Add implements IUndoableAction { + + Block block; + int blockMeta; + Item output; + int outputMeta; + float chance; + float luck; + + public Add(Block block, int blockMeta, Item output, int outputMeta, float chance, float luck) { + this.block = block; + this.blockMeta = blockMeta; + this.output = output; + this.outputMeta = outputMeta; + this.chance = chance; + this.luck = luck; } - @Override - public String getRecipeInfo() { - return new ItemStack(((Smashable) recipe).source, 1, ((Smashable) recipe).sourceMeta).getDisplayName(); + public void apply() { + HammerRegistry.register(block, blockMeta, output, outputMeta, chance, luck); + } + + public boolean canUndo() { + return false; + } + + public String describe() { + return "Adding ExNihilo Hammer recipe by mining " + block.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); + } + + public String describeUndo() { + return ""; + } + + public Object getOverrideKey() { + return null; + } + + public void undo() { } } @@ -51,40 +81,44 @@ public class Hammer { // Removes a recipe, apply is never the same for anything, so will always // need to override it - private static class Remove extends BaseListRemoval { + private static class Remove implements IUndoableAction { + ItemStack stack; + public Remove(ItemStack stack) { - super("ExNihilo Hammer", HammerRegistry.rewards, stack); + this.stack = stack; } // Loops through the registry, to find the item that matches, saves that // recipe then removes it - @Override - public void apply() { - boolean found = false; - Iterator smashables = HammerRegistry.rewards.iterator(); - while (!found && smashables.hasNext()) { - - Smashable reward = smashables.next(); - if (reward != null && reward.source != null && Block.getBlockFromItem(stack.getItem()) != null) - if (reward.source == Block.getBlockFromItem(stack.getItem())) { - reward.source = Blocks.air; - found = true; + public void apply(){ + List smashables = HammerRegistry.rewards; + for(int i = 0; i < smashables.size(); i++){ + Smashable smash = smashables.get(i); + if (smash != null && smash.source != null && Block.getBlockFromItem(stack.getItem()) != null) + if (smash.source == Block.getBlockFromItem(stack.getItem())){ + HammerRegistry.rewards.remove(smash); + return; } } - - // for (Smashable r : HammerRegistry.rewards.) { - // ItemStack check = new ItemStack(r.item, 1, r.meta); - // if (check != null && areEqual(check, stack)) { - // recipe = r; - // break; - // } - // } - } - @Override - public String getRecipeInfo() { - return stack.getDisplayName(); + public boolean canUndo() { + return false; + } + + public String describe() { + return "Removing ExNihilo Hammer recipe of obtaining " + stack.getUnlocalizedName(); + } + + public String describeUndo() { + return null; + } + + public Object getOverrideKey() { + return null; + } + + public void undo() { } } } diff --git a/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java index 77f27c4..fa76ff1 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java @@ -47,20 +47,17 @@ public class Sieve { public void apply() { SieveRegistry.register(source, sourceMeta, output, outputMeta, rarity); - } public boolean canUndo() { - return source != null && output != null; + return false; } public String describe() { return "Adding ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); - } - public String describeUndo() - { + public String describeUndo() { return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); } @@ -69,8 +66,6 @@ public class Sieve { } public void undo() { - if(this.canUndo()) - SieveRegistry.unregisterReward(this.source, this.sourceMeta, this.output, this.outputMeta); } } @@ -79,7 +74,7 @@ public class Sieve { //Removing a Ex Nihilo Sieve recipe @ZenMethod public static void removeRecipe(IItemStack input, IItemStack output) { - if (isABlock(input)) + if (isABlock(input)) { Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); int theMeta = toStack(input).getItemDamage(); @@ -129,12 +124,11 @@ public class Sieve { } public boolean canUndo() { - return false; + return true; } public String describe() { return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); - } public String describeUndo() {