diff --git a/src/main/java/modtweaker2/Commands.java b/src/main/java/modtweaker2/Commands.java index 81fe35d..425393a 100644 --- a/src/main/java/modtweaker2/Commands.java +++ b/src/main/java/modtweaker2/Commands.java @@ -14,6 +14,7 @@ import modtweaker2.mods.botania.lexicon.commands.LexiconKnowledgeTypesLogger; import modtweaker2.mods.botania.lexicon.commands.LexiconPageLogger; import modtweaker2.mods.chisel.commands.ChiselGroupLogger; import modtweaker2.mods.chisel.commands.ChiselVariationLogger; +import modtweaker2.mods.exnihilo.commands.ExNihiloLogger; import modtweaker2.mods.factorization.commands.FactorizationLogger; import modtweaker2.mods.mekanism.gas.GasLogger; import modtweaker2.mods.railcraft.commands.RailcraftLogger; @@ -85,6 +86,10 @@ public class Commands { if (TweakerPlugin.isLoaded("Railcraft")) { MineTweakerAPI.server.addMineTweakerCommand("railcraft", new String[] {"/minetweaker railcraft [FILTER]", " Outputs a list of all Railcraft recipes."}, new RailcraftLogger()); } + + if (TweakerPlugin.isLoaded("exnihilo")) { + MineTweakerAPI.server.addMineTweakerCommand("exnihilo", new String[] {"/minetweaker exnihilo [FILTER]", " Outputs a list of all ExNihilo recipes."}, new ExNihiloLogger()); + } } } diff --git a/src/main/java/modtweaker2/mods/exnihilo/ExNihiloHelper.java b/src/main/java/modtweaker2/mods/exnihilo/ExNihiloHelper.java new file mode 100644 index 0000000..d4eca5b --- /dev/null +++ b/src/main/java/modtweaker2/mods/exnihilo/ExNihiloHelper.java @@ -0,0 +1,13 @@ +package modtweaker2.mods.exnihilo; + +import java.util.Map; + +import modtweaker2.helpers.ReflectionHelper; +import exnihilo.registries.HeatRegistry; +import exnihilo.utils.ItemInfo; + +public class ExNihiloHelper { + public static Map getHeatMap() { + return ReflectionHelper.>getStaticObject(HeatRegistry.class, "heatmap"); + } +} diff --git a/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java b/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java new file mode 100644 index 0000000..e39f202 --- /dev/null +++ b/src/main/java/modtweaker2/mods/exnihilo/commands/ExNihiloLogger.java @@ -0,0 +1,69 @@ +package modtweaker2.mods.exnihilo.commands; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; + +import minetweaker.MineTweakerAPI; +import minetweaker.MineTweakerImplementationAPI; +import minetweaker.api.player.IPlayer; +import minetweaker.api.server.ICommandFunction; +import modtweaker2.helpers.LogHelper; +import modtweaker2.helpers.StringHelper; +import modtweaker2.mods.exnihilo.ExNihiloHelper; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import exnihilo.registries.CompostRegistry; +import exnihilo.registries.CrucibleRegistry; +import exnihilo.registries.helpers.Compostable; +import exnihilo.registries.helpers.Meltable; +import exnihilo.utils.ItemInfo; + +public class ExNihiloLogger implements ICommandFunction { + + private static final List validArguments = new LinkedList(); + + static { + validArguments.add("compost"); + validArguments.add("crucible"); + } + + @Override + public void execute(String[] arguments, IPlayer player) { + List args = StringHelper.toLowerCase(Arrays.asList(arguments)); + + if(!validArguments.containsAll(args)) { + if(player != null) { + player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", "))); + } + } else { + if(args.isEmpty() || args.contains("compost")) { + for(Entry recipe : CompostRegistry.entries.entrySet()) { + MineTweakerAPI.logCommand(String.format("mods.exnihilo.Composting.addRecipe(%s, %s, \"%s\");", + LogHelper.getStackDescription(recipe.getKey().getStack()), + recipe.getValue().value, + Integer.toHexString(recipe.getValue().color.toInt()).substring(2))); + } + } + + if(args.isEmpty() || args.contains("crucible")) { + for(Meltable recipe : CrucibleRegistry.entries.values()) { + MineTweakerAPI.logCommand(String.format("mods.exnihilo.Crucible.addRecipe(%s, %s);", + LogHelper.getStackDescription(new ItemStack(recipe.block, 1, recipe.meta)), + LogHelper.getStackDescription(new FluidStack(recipe.fluid, (int)recipe.fluidVolume)))); + } + + for(Entry recipe : ExNihiloHelper.getHeatMap().entrySet()) { + MineTweakerAPI.logCommand(String.format("mods.exnihilo.Crucible.addHeatSource(%s, %s);", + LogHelper.getStackDescription(recipe.getKey().getStack()), + recipe.getValue())); + } + } + + 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/Compost.java b/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java index 5b8d225..04c4457 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Compost.java @@ -1,117 +1,92 @@ package modtweaker2.mods.exnihilo.handlers; +import static modtweaker2.helpers.InputHelper.toIItemStack; import static modtweaker2.helpers.InputHelper.toStack; -import minetweaker.IUndoableAction; +import static modtweaker2.helpers.StackHelper.matches; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import modtweaker2.helpers.LogHelper; +import modtweaker2.utils.BaseMapAddition; +import modtweaker2.utils.BaseMapRemoval; 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; +import exnihilo.utils.ItemInfo; + @ZenClass("mods.exnihilo.Composting") public class Compost { - //Adding a Ex Nihilo Composting recipe + + public static final String name = "ExNihilo Composting"; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + @ZenMethod public static void addRecipe(IItemStack input, double value, @Optional String hex) { - hex = (hex == null || hex.equals("")) ? "35A82A" : 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 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; + if(input == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); + return; + } + + hex = (hex == null || hex.equals("")) ? "35A82A" : hex; + + Map recipes = new HashMap(); + + recipes.put( + new ItemInfo(toStack(input)), + new Compostable(Math.min(1.0F, (float)value), new Color(hex))); + + MineTweakerAPI.apply(new Add(recipes)); + } + + private static class Add extends BaseMapAddition { + public Add(Map recipes) { + super(Compost.name, CompostRegistry.entries, recipes); + } + + @Override + protected String getRecipeInfo(Entry recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()); } - - @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() { - - } - } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //Removing a Ex Nihilo Composting recipe @ZenMethod - public static void removeRecipe(IItemStack input) { - MineTweakerAPI.apply(new Remove(toStack(input))); - } - - //Removes a recipe, will always remove the key, so all should be good - private static class Remove implements IUndoableAction - { - private ItemStack stack; - - public Remove(ItemStack stack) { - this.stack = stack; + public static void removeRecipe(IIngredient input) { + Map recipes = new HashMap(); + + for(Entry recipe : CompostRegistry.entries.entrySet()) { + if(matches(input, toIItemStack(recipe.getKey().getStack()))) { + recipes.put(recipe.getKey(), recipe.getValue()); + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new Remove(recipes)); + } else { + LogHelper.logWarning(String.format("No %s recipes found for %s. Command ignored!", Compost.name, input.toString())); + } + + } + + private static class Remove extends BaseMapRemoval { + public Remove(Map recipes) { + super(Compost.name, CompostRegistry.entries, recipes); + } + + @Override + protected String getRecipeInfo(Entry recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()); } - - @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 492ea57..dff1082 100644 --- a/src/main/java/modtweaker2/mods/exnihilo/handlers/Crucible.java +++ b/src/main/java/modtweaker2/mods/exnihilo/handlers/Crucible.java @@ -2,45 +2,69 @@ package modtweaker2.mods.exnihilo.handlers; import static modtweaker2.helpers.InputHelper.isABlock; import static modtweaker2.helpers.InputHelper.toFluid; +import static modtweaker2.helpers.InputHelper.toIItemStack; +import static modtweaker2.helpers.InputHelper.toILiquidStack; import static modtweaker2.helpers.InputHelper.toStack; +import static modtweaker2.helpers.StackHelper.matches; +import java.util.HashMap; +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 minetweaker.api.liquid.ILiquidStack; import modtweaker2.helpers.LogHelper; +import modtweaker2.mods.exnihilo.ExNihiloHelper; import modtweaker2.utils.BaseMapAddition; import modtweaker2.utils.BaseMapRemoval; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import exnihilo.registries.CrucibleRegistry; -import exnihilo.registries.HeatRegistry; import exnihilo.registries.helpers.Meltable; +import exnihilo.utils.ItemInfo; @ZenClass("mods.exnihilo.Crucible") public class Crucible { + public static final String nameMelting = "ExNihilo Crucible (Melting)"; + public static final String nameHeatSource = "ExNihilo Crucible (Heat source)"; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /************************************************ Crucible Melting ************************************************/ //Adding a Ex Nihilo Crucible recipe @ZenMethod public static void addRecipe(IItemStack input, ILiquidStack fluid) { - if (isABlock(input)) { - Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); - int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new AddRecipe(new Meltable(theBlock, theMeta, 2000, toFluid(fluid).getFluid(), toFluid(fluid).amount, theBlock))); + if(input == null || fluid == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", nameMelting)); + return; } + + if(!isABlock(input)) { + LogHelper.logError(String.format("Input item for %s recipe must be a block.", nameMelting)); + return; + } + + Map recipes = new HashMap(); + Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); + int theMeta = toStack(input).getItemDamage(); + + recipes.put( + theBlock + ":" + theMeta, + new Meltable(theBlock, theMeta, 2000, toFluid(fluid).getFluid(), toFluid(fluid).amount, theBlock)); + + MineTweakerAPI.apply(new AddRecipe(recipes)); } //Passes the list to the map list implementation, and adds the recipe private static class AddRecipe extends BaseMapAddition { - public AddRecipe(Meltable recipe) { - super("ExNihilo Crucible", CrucibleRegistry.entries); - recipes.put(recipe.block + ":" + recipe.meta, recipe); + public AddRecipe(Map recipes) { + super(nameMelting, CrucibleRegistry.entries, recipes); } @Override @@ -53,23 +77,27 @@ public class Crucible { //Removing a Ex Nihilo Crucible recipe @ZenMethod - public static void removeRecipe(IItemStack output) { - if (isABlock(output)) { - MineTweakerAPI.apply(new RemoveRecipe(toStack(output))); + public static void removeRecipe(IIngredient output) { + Map recipes = new HashMap(); + + for(Entry entry : CrucibleRegistry.entries.entrySet()) { + FluidStack fluid = new FluidStack(entry.getValue().fluid, (int)entry.getValue().fluidVolume); + if(matches(output, toILiquidStack(fluid))) { + recipes.put(entry.getKey(), entry.getValue()); + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new RemoveRecipe(recipes)); + } else { + LogHelper.logWarning(String.format("No %s recipe found for %s. Command ignored!", Crucible.nameMelting, output.toString())); } } //Removes a recipe, will always remove the key, so all should be good private static class RemoveRecipe extends BaseMapRemoval { - public RemoveRecipe(ItemStack stack) { - super("ExNihilo Crucible", CrucibleRegistry.entries); - - String key = Block.getBlockFromItem(stack.getItem()) + ":" + stack.getItemDamage(); - - for(Entry entry : map.entrySet()) { - if(entry.getKey().equals(key)) - recipes.put(entry.getKey(), entry.getValue()); - } + public RemoveRecipe(Map recipes) { + super(nameMelting, CrucibleRegistry.entries, recipes); } @Override @@ -82,92 +110,67 @@ public class Crucible { //Adding a Ex Nihilo Crucible heat source @ZenMethod public static void addHeatSource(IItemStack input, double value) { - if (isABlock(input)) { - Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); - int theMeta = toStack(input).getItemDamage(); - MineTweakerAPI.apply(new AddHeatSource(theBlock, theMeta, (float) value)); + if(input == null) { + LogHelper.logError(String.format("Required parameters missing for %s recipe.", nameMelting)); + return; + } + + if(!isABlock(input)) { + LogHelper.logError(String.format("Input item for %s recipe must be a block.", nameMelting)); + return; + } + + Map recipes = new HashMap(); + recipes.put(new ItemInfo(toStack(input)), (float)value); + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new AddHeatSource(recipes)); } } //Passes the list to the base map implementation, and adds the recipe - private static class AddHeatSource implements IUndoableAction + private static class AddHeatSource extends BaseMapAddition { - Block source; - int sourceMeta; - float value; - - public AddHeatSource(Block source, int sourceMeta, float value) { - this.source = source; - this.sourceMeta = sourceMeta; - this.value = value; + public AddHeatSource(Map recipes) { + super(Crucible.nameHeatSource, ExNihiloHelper.getHeatMap(), recipes); } - 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 + protected String getRecipeInfo(Entry recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()); } } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Removing a Ex Nihilo Crucible heat source @ZenMethod - public static void removeHeatSource(IItemStack output) { - if (isABlock(output)) { - Block block = Block.getBlockFromItem(toStack(output).getItem()); - MineTweakerAPI.apply(new RemoveHeatSource(block)); + public static void removeHeatSource(IIngredient output) { + Map recipes = new HashMap(); + + for(Entry entry : ExNihiloHelper.getHeatMap().entrySet()) { + if(matches(output, toIItemStack(entry.getKey().getStack()))) { + recipes.put(entry.getKey(), entry.getValue()); + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new RemoveHeatSource(recipes)); + } else { + LogHelper.logWarning(String.format("No %s recipe found for %s. Command ignored!", Crucible.nameMelting, output.toString())); } } //Removes a recipe, will always remove the key, so all should be good - private static class RemoveHeatSource implements IUndoableAction + private static class RemoveHeatSource extends BaseMapAddition { - Block block; - - public RemoveHeatSource(Block block) { - this.block = block; + public RemoveHeatSource(Map recipes) { + super(Crucible.nameHeatSource, ExNihiloHelper.getHeatMap(), recipes); } - 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() { - } + @Override + protected String getRecipeInfo(Entry recipe) { + return LogHelper.getStackDescription(recipe.getKey().getStack()); + } } } diff --git a/src/main/java/modtweaker2/mods/tconstruct/MaterialLogger.java b/src/main/java/modtweaker2/mods/tconstruct/MaterialLogger.java index 0f0d568..2f66b28 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/MaterialLogger.java +++ b/src/main/java/modtweaker2/mods/tconstruct/MaterialLogger.java @@ -13,9 +13,9 @@ import tconstruct.library.TConstructRegistry; import tconstruct.library.tools.ToolMaterial; public class MaterialLogger implements ICommandFunction { - private static ArrayList materials = new ArrayList(); + private static ArrayList materials = new ArrayList(); static { - materials = new ArrayList(); + materials = new ArrayList(); for (Map.Entry entry : TConstructRegistry.toolMaterialStrings.entrySet()) { materials.add(entry.getKey()); }