From 7571f526d703b7423c71cf03dff01f85b6aa927a Mon Sep 17 00:00:00 2001 From: Zixxl Date: Fri, 10 Jul 2015 16:27:02 +0200 Subject: [PATCH] ExNihilo rework finished --- .../exnihilo/commands/ExNihiloLogger.java | 30 ++ .../mods/exnihilo/handlers/Hammer.java | 281 +++++++++---- .../mods/exnihilo/handlers/Sieve.java | 388 ++++++++++-------- 3 files changed, 451 insertions(+), 248 deletions(-) diff --git a/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java b/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java index e39f202..0c27f30 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java +++ b/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java @@ -1,5 +1,6 @@ package modtweaker2.mods.exnihilo.commands; +import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -16,8 +17,12 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import exnihilo.registries.CompostRegistry; import exnihilo.registries.CrucibleRegistry; +import exnihilo.registries.HammerRegistry; +import exnihilo.registries.SieveRegistry; import exnihilo.registries.helpers.Compostable; import exnihilo.registries.helpers.Meltable; +import exnihilo.registries.helpers.SiftingResult; +import exnihilo.registries.helpers.Smashable; import exnihilo.utils.ItemInfo; public class ExNihiloLogger implements ICommandFunction { @@ -27,6 +32,8 @@ public class ExNihiloLogger implements ICommandFunction { static { validArguments.add("compost"); validArguments.add("crucible"); + validArguments.add("hammer"); + validArguments.add("sieve"); } @Override @@ -61,6 +68,29 @@ public class ExNihiloLogger implements ICommandFunction { } } + if(args.isEmpty() || args.contains("hammer")) { + for(Entry> entry : HammerRegistry.getRewards().entrySet()) { + for(Smashable recipe : entry.getValue()) { + MineTweakerAPI.logCommand(String.format("mods.exnihilo.Hammer.addRecipe(%s, %s, %s, %s);", + LogHelper.getStackDescription(entry.getKey().getStack()), + LogHelper.getStackDescription(new ItemStack(recipe.item, 1, recipe.meta)), + recipe.chance, + recipe.luckMultiplier)); + } + } + } + + if(args.isEmpty() || args.contains("sieve")) { + for(Entry> entry : SieveRegistry.getSiftables().entrySet()) { + for(SiftingResult recipe : entry.getValue()) { + MineTweakerAPI.logCommand(String.format("mods.exnihilo.Sieve.addRecipe(%s, %s, %s);", + LogHelper.getStackDescription(entry.getKey().getStack()), + LogHelper.getStackDescription(new ItemStack(recipe.item, 1, recipe.meta)), + recipe.rarity)); + } + } + } + if (player != null) { player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir")); } diff --git a/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java index cb25307..03be181 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Hammer.java @@ -1,118 +1,249 @@ package modtweaker2.mods.exnihilo.handlers; import static modtweaker2.helpers.InputHelper.isABlock; +import static modtweaker2.helpers.InputHelper.toIItemStack; import static modtweaker2.helpers.InputHelper.toStack; -import minetweaker.IUndoableAction; +import static modtweaker2.helpers.StackHelper.matches; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; +import minetweaker.api.item.IngredientAny; +import modtweaker2.helpers.LogHelper; +import modtweaker2.utils.BaseMapAddition; +import modtweaker2.utils.BaseMapRemoval; import net.minecraft.block.Block; -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.HammerRegistry; +import exnihilo.registries.helpers.Smashable; +import exnihilo.utils.ItemInfo; @ZenClass("mods.exnihilo.Hammer") public class Hammer { - // Adding a Ex Nihilo Hammer recipe + + public static final String name = "ExNihilo Hammer"; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + @ZenMethod public static void addRecipe(IItemStack input, IItemStack output, double chance, double luck) { - if (isABlock(input)) { - Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); - int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new Add(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), (float) chance, (float) luck)); - } + if(input == null || output == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", name)); + return; + } + + addRecipe(input, new IItemStack[] { output }, new double[] { chance }, new double[] { luck }); + } + + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack[] output, double[] chance, double[] luck) { + if(input == null || output == null || chance == null || luck == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", name)); + return; + } + + if(!isABlock(input)) { + LogHelper.logError(String.format("Input item for %s recipe must be a block.", name)); + return; + } + + if(output.length == 0 || output.length != chance.length || output.length != luck.length) { + LogHelper.logError(String.format("Number of items in arrays are different or null (%d, %d, %d)", output.length, chance.length, luck.length)); + return; + } + + Map> recipes = new HashMap>(); + ArrayList list = new ArrayList(); + ItemInfo itemInfo = new ItemInfo(toStack(input)); + recipes.put(itemInfo, list); + + for(int i = 0; i < output.length; i++) { + ItemStack out = toStack(output[i]); + list.add(new Smashable(Block.getBlockFromItem(itemInfo.getItem()), itemInfo.getMeta(), out.getItem(), out.getItemDamage(), (float)chance[i], (float)luck[i])); + } + + MineTweakerAPI.apply(new Add(recipes)); } - // Passes the list to the base list implementation, and adds the 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; + private static class Add extends BaseMapAddition> { + public Add(Map> recipes) { + super(Hammer.name, HammerRegistry.getRewards(), recipes); } 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; + for(Entry> entry : recipes.entrySet()) { + if(!map.containsKey(entry.getKey())) { + // no recipe for input available, add new entry + map.put(entry.getKey(), entry.getValue()); + } else { + // recipes already available, add to present list + ArrayList list = map.get(entry.getKey()); + + // store old Smashable objects if present + ArrayList backup = new ArrayList(); + for(Smashable recipe : entry.getValue()) { + backup.addAll(removeFromList(list, recipe)); + } + + if(!backup.isEmpty()) { + LogHelper.logWarning(String.format("Overwritten %d %s recipe outputs for %s.", backup.size(), Hammer.name, LogHelper.getStackDescription(entry.getKey().getStack()))); + overwritten.put(entry.getKey(), backup); + } + + // add new Smashable objects + list.addAll(entry.getValue()); + } + + successful.put(entry.getKey(), entry.getValue()); + } } public void undo() { + // remove all recipes + for(Entry> entry : successful.entrySet()) { + ArrayList list = map.get(entry.getKey()); + for(Smashable recipe : entry.getValue()) { + removeFromList(list, recipe); + } + } + + // re-add overwritten recipes + for(Entry> entry : overwritten.entrySet()) { + map.get(entry.getKey()).addAll(entry.getValue()); + } + + // remove empty entries + for(Iterator>> it = map.entrySet().iterator(); it.hasNext(); ) { + Entry> entry = it.next(); + if(entry.getValue().isEmpty()) { + it.remove(); + } + } + } + + @Override + protected String getRecipeInfo(Entry> recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()) + " (" + recipe.getValue().size() + " entries)"; } } - // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Removing a Ex Nihilo Hammer recipe + @Deprecated @ZenMethod public static void removeRecipe(IItemStack inputBlock, int inputBlockMeta, IItemStack outputItem, int outputItemMeta) { - MineTweakerAPI.apply(new Remove(Block.getBlockFromItem(toStack(inputBlock).getItem()), inputBlockMeta, toStack(outputItem).getItem(), outputItemMeta)); + removeRecipe(toIItemStack(new ItemStack(toStack(inputBlock).getItem(), 1, inputBlockMeta)), toIItemStack(new ItemStack(toStack(outputItem).getItem(), 1, outputItemMeta))); + } + + @ZenMethod + public static void removeRecipe(IIngredient input, @Optional IIngredient output) { + if(input == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", name)); + return; + } + + if(output == null) { + output = IngredientAny.INSTANCE; + } + + Map> recipes = new HashMap>(); + + for(Entry> entry : HammerRegistry.getRewards().entrySet()) { + if(input.matches(toIItemStack(entry.getKey().getStack()))) { + ArrayList list = entry.getValue(); + ArrayList toRemove = new ArrayList(); + + for(Smashable recipe : list) { + ItemStack item = new ItemStack(recipe.item, 1, recipe.meta); + + if(matches(output, toIItemStack(item))) { + toRemove.add(recipe); + } + } + + if(!toRemove.isEmpty()) { + recipes.put(entry.getKey(), toRemove); + } + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new Remove(recipes)); + } else { + LogHelper.logWarning(String.format("No %s recipes found for %s and %s. Command ignored!", input.toString(), output.toString())); + } } // Removes a recipe, apply is never the same for anything, so will always // need to override it - private static class Remove implements IUndoableAction { - Block block; - int inputBlockMeta; - Item output; - int outputItemMeta; - + private static class Remove extends BaseMapRemoval> { - public Remove(Block block, int inputBlockMeta, Item output, int outputItemMeta) { - this.block = block; - this.inputBlockMeta = inputBlockMeta; - this.output = output; - this.outputItemMeta = outputItemMeta; + public Remove(Map> recipes) { + super(Hammer.name, HammerRegistry.getRewards(), recipes); } - // Loops through the registry, to find the item that matches, saves that - // recipe then removes it + @Override public void apply() { - HammerRegistry.remove(block, inputBlockMeta, output, outputItemMeta); - } - - public boolean canUndo() { - return false; - } - - public String describe() { - return "Removing ExNihilo Hammer recipe"; - } - - public String describeUndo() { - return null; - } - - public Object getOverrideKey() { - return null; + for(Entry> entry : recipes.entrySet()) { + ArrayList list = map.get(entry.getKey()); + + for(Smashable recipe : entry.getValue()) { + removeFromList(list, recipe); + } + + successful.put(entry.getKey(), entry.getValue()); + } + + // remove empty entries + for(Iterator>> it = map.entrySet().iterator(); it.hasNext(); ) { + Entry> entry = it.next(); + if(entry.getValue().isEmpty()) { + it.remove(); + } + } } + @Override public void undo() { + for(Entry> entry : successful.entrySet()) { + if(!map.containsKey(entry.getKey())) { + map.put(entry.getKey(), entry.getValue()); + } else { + map.get(entry.getKey()).addAll(entry.getValue()); + } + } } + + @Override + protected String getRecipeInfo(Entry> recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()) + " (" + recipe.getValue().size() + " entries)"; + } } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + public static ArrayList removeFromList(ArrayList list, Smashable s) { + ArrayList removed = new ArrayList(); + ItemInfo toRemove = new ItemInfo(s.item, s.meta); + for(Iterator it = list.iterator(); it.hasNext(); ) { + Smashable itS = it.next(); + ItemInfo item = new ItemInfo(itS.item, itS.meta); + + if(item.equals(toRemove)) { + removed.add(itS); + it.remove(); + } + } + + return removed; + } } diff --git a/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java index d9c8863..48acd00 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Sieve.java @@ -1,224 +1,266 @@ package modtweaker2.mods.exnihilo.handlers; import static modtweaker2.helpers.InputHelper.isABlock; +import static modtweaker2.helpers.InputHelper.toIItemStack; import static modtweaker2.helpers.InputHelper.toStack; +import static modtweaker2.helpers.StackHelper.matches; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; -import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; -import net.minecraft.block.Block; -import net.minecraft.item.Item; +import minetweaker.api.item.IngredientAny; +import modtweaker2.helpers.LogHelper; +import modtweaker2.utils.BaseMapAddition; +import modtweaker2.utils.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import exnihilo.registries.SieveRegistry; import exnihilo.registries.helpers.SiftingResult; +import exnihilo.utils.ItemInfo; @ZenClass("mods.exnihilo.Sieve") public class Sieve { + + public static final String name = "ExNihilo Sieve"; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Adding a Ex Nihilo Sieve recipe @ZenMethod public static void addRecipe(IItemStack input, IItemStack output, int rarity) { - if (isABlock(input)) { - Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); - int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new Add(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), rarity)); - } + if(input == null || output == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", name)); + return; + } + + addRecipe(input, new IItemStack[] { output }, new int[] { rarity }); + } + + public static void addRecipe(IItemStack input, IItemStack[] output, int[] rarity) { + if(input == null || output == null || rarity == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", name)); + return; + } + + if(!isABlock(input)) { + LogHelper.logError(String.format("Input item for %s recipe must be a block.", name)); + return; + } + + if(output.length == 0 || output.length != rarity.length) { + LogHelper.logError(String.format("Number of items in arrays are different or null (%d, %d)", output.length, rarity.length)); + return; + } + + Map> recipes = new HashMap>(); + ArrayList list = new ArrayList(); + ItemInfo itemInfo = new ItemInfo(toStack(input)); + recipes.put(itemInfo, list); + + for(int i = 0; i < output.length; i++) { + ItemStack out = toStack(output[i]); + list.add(new SiftingResult(out.getItem(), out.getItemDamage(), rarity[i])); + } + + MineTweakerAPI.apply(new Add(recipes)); } - // Passes the list to the base list implementation, and adds the recipe - private static class Add implements IUndoableAction { - Block source; - int sourceMeta; - Item output; - int outputMeta; - int rarity; + private static class Add extends BaseMapAddition> { - public Add(Block source, int sourceMeta, Item output, int outputMeta, int rarity) { - this.source = source; - this.sourceMeta = sourceMeta; - this.output = output; - this.outputMeta = outputMeta; - this.rarity = rarity; + public Add(Map> recipes) { + super(Sieve.name, SieveRegistry.getSiftables(), recipes); } - + + @Override public void apply() { - SieveRegistry.register(source, sourceMeta, output, outputMeta, rarity); - + for(Entry> entry : recipes.entrySet()) { + if(!map.containsKey(entry.getKey())) { + // no recipe for input available, add new entry + map.put(entry.getKey(), entry.getValue()); + } else { + // recipes already available, add to present list + ArrayList list = map.get(entry.getKey()); + + // store old SiftingResult objects if present + ArrayList backup = new ArrayList(); + for(SiftingResult recipe : entry.getValue()) { + backup.addAll(removeFromList(list, recipe)); + } + + if(!backup.isEmpty()) { + LogHelper.logWarning(String.format("Overwritten %d %s recipe outputs for %s.", backup.size(), Hammer.name, LogHelper.getStackDescription(entry.getKey().getStack()))); + overwritten.put(entry.getKey(), backup); + } + + // add new SiftingResult objects + list.addAll(entry.getValue()); + } + + successful.put(entry.getKey(), entry.getValue()); + } } - - public boolean canUndo() { - return source != null && output != null; - } - - public String describe() { - return "Adding ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); - - } - - public String describeUndo() { - return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); - } - - public Object getOverrideKey() { - return null; - } - + + @Override public void undo() { - if (this.canUndo()) - SieveRegistry.unregisterReward(this.source, this.sourceMeta, this.output, this.outputMeta); + // remove all recipes + for(Entry> entry : successful.entrySet()) { + ArrayList list = map.get(entry.getKey()); + for(SiftingResult recipe : entry.getValue()) { + removeFromList(list, recipe); + } + } + + // re-add overwritten recipes + for(Entry> entry : overwritten.entrySet()) { + map.get(entry.getKey()).addAll(entry.getValue()); + } + + // remove empty entries + for(Iterator>> it = map.entrySet().iterator(); it.hasNext(); ) { + Entry> entry = it.next(); + if(entry.getValue().isEmpty()) { + it.remove(); + } + } } + + @Override + protected String getRecipeInfo(Entry> recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()) + " (" + recipe.getValue().size() + " entries)"; + } } - // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Removing a Ex Nihilo Sieve recipe + @Deprecated @ZenMethod public static void removeRecipe(IItemStack input, IItemStack output) { - if (isABlock(input)) { - Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); - int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new Remove(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage())); - } + removeRecipe((IIngredient)input, (IIngredient)output); } - + @Deprecated @ZenMethod public static void removeRewardFromAllBlocks(IItemStack output) { - Item theItem = toStack(output).getItem(); - int theMeta = toStack(output).getItemDamage(); - MineTweakerAPI.apply(new RemoveRewardFromAllBlocks(theItem, theMeta)); + removeRecipe(IngredientAny.INSTANCE, (IIngredient)output); } + @Deprecated @ZenMethod public static void removeAllRewardsFromBlock(IItemStack output) { - if (isABlock(output)) { - Block theBlock = Block.getBlockFromItem(toStack(output).getItem()); - int theMeta = toStack(output).getItemDamage(); - MineTweakerAPI.apply(new RemoveAllRewardsFromBlock(theBlock, theMeta)); - } + removeRecipe((IIngredient)output, IngredientAny.INSTANCE); + } + + @ZenMethod + public static void removeRecipe(IIngredient input, @Optional IIngredient output) { + if(input == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", name)); + return; + } + + if(output == null) { + output = IngredientAny.INSTANCE; + } + + Map> recipes = new HashMap>(); + + for(Entry> entry : SieveRegistry.getSiftables().entrySet()) { + if(input.matches(toIItemStack(entry.getKey().getStack()))) { + ArrayList list = entry.getValue(); + ArrayList toRemove = new ArrayList(); + + for(SiftingResult recipe : list) { + ItemStack item = new ItemStack(recipe.item, 1, recipe.meta); + + if(matches(output, toIItemStack(item))) { + toRemove.add(recipe); + } + } + + if(!toRemove.isEmpty()) { + recipes.put(entry.getKey(), toRemove); + } + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new Remove(recipes)); + } else { + LogHelper.logWarning(String.format("No %s recipes found for %s and %s. Command ignored!", input.toString(), output.toString())); + } } // Removes a recipe, apply is never the same for anything, so will always // need to override it - private static class Remove implements IUndoableAction { - Block source; - int sourceMeta; - Item output; - int outputMeta; - int rarity; + private static class Remove extends BaseMapRemoval> { + public Remove(Map> recipes) { + super(Sieve.name, SieveRegistry.getSiftables(), recipes); + } + + @Override + public void apply() { + for(Entry> entry : recipes.entrySet()) { + ArrayList list = map.get(entry.getKey()); + + for(SiftingResult recipe : entry.getValue()) { + removeFromList(list, recipe); + } + + successful.put(entry.getKey(), entry.getValue()); + } + + // remove empty entries + for(Iterator>> it = map.entrySet().iterator(); it.hasNext(); ) { + Entry> entry = it.next(); + if(entry.getValue().isEmpty()) { + it.remove(); + } + } + } - public Remove(Block source, int sourceMeta, Item output, int outputMeta) { - this.source = source; - this.sourceMeta = sourceMeta; - this.output = output; - this.outputMeta = outputMeta; - } - - public void apply() { - ArrayList results = SieveRegistry.getSiftingOutput(this.source, this.sourceMeta); - - for (SiftingResult res : results) { - if (res.item.equals(this.source) && res.meta == this.outputMeta) - this.rarity = res.rarity; - } - - SieveRegistry.unregisterReward(source, sourceMeta, output, outputMeta); - } - - public boolean canUndo() { - return output != null && source != null; - } - - public String describe() { - return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); - - } - - public String describeUndo() { - return "Restoring ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName(); - } - - public Object getOverrideKey() { - return null; - } - - public void undo() { - if (this.canUndo()) - SieveRegistry.register(this.source, this.sourceMeta, this.output, this.outputMeta, rarity); - } - } - - private static class RemoveAllRewardsFromBlock implements IUndoableAction { - Block block; - int blockMeta; - - public RemoveAllRewardsFromBlock(Block block, int blockMeta) { - this.block = block; - this.blockMeta = blockMeta; - } - - public void apply() { - SieveRegistry.unregisterAllRewardsFromBlock(block, blockMeta); - } - - public boolean canUndo() { - return false; - } - - public String describe() { - return "Removing All ExNihilo Sieve rewards from " + block.getLocalizedName(); - - } - - public String describeUndo() { - return ""; - } - - public Object getOverrideKey() { - return null; - } - - public void undo() { - } - } - - private static class RemoveRewardFromAllBlocks implements IUndoableAction { - Item reward; - int rewardMeta; - - public RemoveRewardFromAllBlocks(Item reward, int rewardMeta) { - this.reward = reward; - this.rewardMeta = rewardMeta; - } - - public void apply() { - SieveRegistry.unregisterRewardFromAllBlocks(reward, rewardMeta); - } - - public boolean canUndo() { - return false; - } - - public String describe() { - return "Removing ExNihilo Sieve reward of " + reward.getUnlocalizedName() + " from all Blocks"; - - } - - public String describeUndo() { - return ""; - } - - public Object getOverrideKey() { - return null; - } - - public void undo() { - } + @Override + public void undo() { + for(Entry> entry : successful.entrySet()) { + if(!map.containsKey(entry.getKey())) { + map.put(entry.getKey(), entry.getValue()); + } else { + map.get(entry.getKey()).addAll(entry.getValue()); + } + } + } + + @Override + protected String getRecipeInfo(Entry> recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()) + " (" + recipe.getValue().size() + " entries)"; + } } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + public static ArrayList removeFromList(ArrayList list, SiftingResult s) { + ArrayList removed = new ArrayList(); + ItemInfo toRemove = new ItemInfo(s.item, s.meta); + for(Iterator it = list.iterator(); it.hasNext(); ) { + SiftingResult itS = it.next(); + ItemInfo item = new ItemInfo(itS.item, itS.meta); + + if(item.equals(toRemove)) { + removed.add(itS); + it.remove(); + } + } + + return removed; + } }