From f9d0fa11aa7c08e70b49866b933c48948d3a64fa Mon Sep 17 00:00:00 2001 From: primetoxinz Date: Thu, 19 Apr 2018 17:22:55 -0400 Subject: [PATCH] Improve logging for recipe removal. Fix removeAll functions. Fix addition of Turntable recipes (#626) --- .../compat/betterwithmods/Cauldron.java | 19 ++++++++++--------- .../compat/betterwithmods/Crucible.java | 19 ++++++++++--------- .../compat/betterwithmods/Kiln.java | 7 ++++++- .../compat/betterwithmods/Mill.java | 6 ++++++ .../blamejared/compat/betterwithmods/Saw.java | 4 ++++ .../compat/betterwithmods/Turntable.java | 10 +++++++--- .../compat/betterwithmods/base/RemoveAll.java | 6 +++++- .../base/blockrecipes/BlockRecipeRemove.java | 6 ++++-- .../base/blockrecipes/SawBuilder.java | 6 ++++++ .../base/bulkrecipes/BulkRecipeRemove.java | 6 ++++-- .../base/bulkrecipes/CookingPotBuilder.java | 2 +- test_scripts/bwm.zs | 7 ++++--- 12 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/blamejared/compat/betterwithmods/Cauldron.java b/src/main/java/com/blamejared/compat/betterwithmods/Cauldron.java index bda5384..bfd5037 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/Cauldron.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/Cauldron.java @@ -18,27 +18,23 @@ import java.util.function.Supplier; @ZenClass("mods.betterwithmods.Cauldron") @ModOnly("betterwithmods") @ZenRegister -public class Cauldron extends CookingPotBuilder { +public class Cauldron { - public static Cauldron INSTANCE = new Cauldron(() -> BWRegistry.CAULDRON, "Cauldron"); - - protected Cauldron(Supplier> registry, String name) { - super(registry, name); - } + public static CookingPotBuilder INSTANCE = new CookingPotBuilder(() -> BWRegistry.CAULDRON, "Cauldron"); @ZenMethod - public static Cauldron builder() { + public static CookingPotBuilder builder() { return INSTANCE; } @ZenMethod public static void addStoked(IIngredient[] inputs, IItemStack[] outputs) { - INSTANCE.buildRecipe(inputs, outputs).setHeat(STOKED).build(); + INSTANCE.buildRecipe(inputs, outputs).setHeat(CookingPotBuilder.STOKED).build(); } @ZenMethod public static void addUnstoked(IIngredient[] inputs, IItemStack[] outputs) { - INSTANCE.buildRecipe(inputs, outputs).setHeat(UNSTOKED).build(); + INSTANCE.buildRecipe(inputs, outputs).setHeat(CookingPotBuilder.UNSTOKED).build(); } @Deprecated @@ -57,4 +53,9 @@ public class Cauldron extends CookingPotBuilder { public static void remove(IItemStack[] output) { INSTANCE.removeRecipe(output); } + + @ZenMethod + public static void removeAll() { + builder().removeAll(); + } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/Crucible.java b/src/main/java/com/blamejared/compat/betterwithmods/Crucible.java index 33f3551..ed01550 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/Crucible.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/Crucible.java @@ -18,26 +18,22 @@ import java.util.function.Supplier; @ZenClass("mods.betterwithmods.Crucible") @ModOnly("betterwithmods") @ZenRegister -public class Crucible extends CookingPotBuilder { - public static Crucible INSTANCE = new Crucible(() -> BWRegistry.CRUCIBLE, "Crucible"); - - private Crucible(Supplier> registry, String name) { - super(registry, name); - } +public class Crucible { + public static CookingPotBuilder INSTANCE = new CookingPotBuilder(() -> BWRegistry.CRUCIBLE, "Crucible"); @ZenMethod - public static Crucible builder() { + public static CookingPotBuilder builder() { return INSTANCE; } @ZenMethod public static void addStoked(IIngredient[] inputs, IItemStack[] outputs) { - INSTANCE.buildRecipe(inputs, outputs).setHeat(STOKED).build(); + INSTANCE.buildRecipe(inputs, outputs).setHeat(CookingPotBuilder.STOKED).build(); } @ZenMethod public static void addUnstoked(IIngredient[] inputs, IItemStack[] outputs) { - INSTANCE.buildRecipe(inputs, outputs).setHeat(UNSTOKED).build(); + INSTANCE.buildRecipe(inputs, outputs).setHeat(CookingPotBuilder.UNSTOKED).build(); } @Deprecated @@ -56,4 +52,9 @@ public class Crucible extends CookingPotBuilder { public static void remove(IItemStack[] output) { INSTANCE.removeRecipe(output); } + + @ZenMethod + public static void removeAll() { + builder().removeAll(); + } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/Kiln.java b/src/main/java/com/blamejared/compat/betterwithmods/Kiln.java index 7fd8d32..dd00a75 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/Kiln.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/Kiln.java @@ -47,7 +47,7 @@ public class Kiln { @Deprecated @ZenMethod public static void remove(IItemStack input) { - LogHelper.logError("This operation has been removed, use mods.betterwithmods.Saw.remove(IItemStack[] outputs)"); + LogHelper.logError("This operation has been removed, use mods.betterwithmods.Kiln.remove(IItemStack[] outputs)"); } @ZenMethod @@ -55,6 +55,11 @@ public class Kiln { INSTANCE.removeRecipe(outputs); } + @ZenMethod + public static void removeAll() { + builder().removeAll(); + } + @ZenMethod public static void registerBlock(IItemStack block) { ModTweaker.LATE_ADDITIONS.add(new KilnBlock(BWMRecipes.getStateFromStack(InputHelper.toStack(block)))); diff --git a/src/main/java/com/blamejared/compat/betterwithmods/Mill.java b/src/main/java/com/blamejared/compat/betterwithmods/Mill.java index 9085a97..17fc80f 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/Mill.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/Mill.java @@ -48,4 +48,10 @@ public class Mill { public static void remove(IItemStack[] output) { INSTANCE.removeRecipe(output); } + + @ZenMethod + public static void removeAll() { + builder().removeAll(); + } + } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/Saw.java b/src/main/java/com/blamejared/compat/betterwithmods/Saw.java index b7aa138..885549d 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/Saw.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/Saw.java @@ -49,4 +49,8 @@ public class Saw { INSTANCE.removeRecipe(outputs); } + @ZenMethod + public static void removeAll() { + builder().removeAll(); + } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/Turntable.java b/src/main/java/com/blamejared/compat/betterwithmods/Turntable.java index be08446..7a89dc2 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/Turntable.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/Turntable.java @@ -25,18 +25,18 @@ public class Turntable { @ZenMethod public static void add(IIngredient inputBlock, IItemStack[] additionalOutput) { - builder().buildRecipe(inputBlock, additionalOutput); + builder().buildRecipe(inputBlock, additionalOutput).build(); } @ZenMethod public static void add(IIngredient inputBlock, IItemStack productState, IItemStack[] additionalOutput) { - builder().buildRecipe(inputBlock, additionalOutput).setProductState(productState); + builder().buildRecipe(inputBlock, additionalOutput).setProductState(productState).build(); } @Deprecated @ZenMethod public static void remove(IItemStack input) { - LogHelper.logError("This operation has been removed, use mods.betterwithmods.Saw.remove(IItemStack[] outputs)"); + LogHelper.logError("This operation has been removed, use mods.betterwithmods.Turntable.remove(IItemStack[] outputs)"); } @ZenMethod @@ -44,4 +44,8 @@ public class Turntable { INSTANCE.removeRecipe(outputs); } + @ZenMethod + public static void removeAll() { + builder().removeAll(); + } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/base/RemoveAll.java b/src/main/java/com/blamejared/compat/betterwithmods/base/RemoveAll.java index 74097b2..bf570ad 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/base/RemoveAll.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/base/RemoveAll.java @@ -12,9 +12,13 @@ public class RemoveAll extends BaseAction { this.list = list; } - @Override public void apply() { list.clear(); } + + @Override + protected String getRecipeInfo() { + return String.format("Removing all recipes for %s", name); + } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/BlockRecipeRemove.java b/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/BlockRecipeRemove.java index 2440504..e1f2cec 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/BlockRecipeRemove.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/BlockRecipeRemove.java @@ -30,11 +30,13 @@ public class BlockRecipeRemove extends BaseAction { @Override public void apply() { if (!manager.remove(outputs)) { - LogHelper.logError(String.format("Error removing %s Recipe for %s", name, getRecipeInfo(outputs))); + LogHelper.logWarning(String.format("No recipes were removed for output %s", getRecipeInfo(outputs))); + } else { + LogHelper.logInfo(String.format("Succesfully removed all recipes for %s", getRecipeInfo(outputs))); } } private String getRecipeInfo(List outputs) { - return outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")); + return String.format("%s - %s", name, outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(","))); } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/SawBuilder.java b/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/SawBuilder.java index 1d2697e..ce2b972 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/SawBuilder.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/base/blockrecipes/SawBuilder.java @@ -25,4 +25,10 @@ public class SawBuilder extends BlockRecipeBuilder { public void build() { addRecipe(new SawRecipe(input,outputs)); } + + @ZenMethod + @Override + public void removeAll() { + super.removeAll(); + } } diff --git a/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/BulkRecipeRemove.java b/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/BulkRecipeRemove.java index ea8b258..2ba81ad 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/BulkRecipeRemove.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/BulkRecipeRemove.java @@ -33,11 +33,13 @@ public class BulkRecipeRemove extends BaseAction { @Override public void apply() { if (!manager.remove(outputs)) { - LogHelper.logError(String.format("Error removing %s Recipe for %s", name, getRecipeInfo(outputs))); + LogHelper.logWarning(String.format("No recipes were removed for output %s", getRecipeInfo(outputs))); + } else { + LogHelper.logInfo(String.format("Succesfully removed all recipes for %s", getRecipeInfo(outputs))); } } private String getRecipeInfo(List outputs) { - return outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")); + return String.format("%s - %s", name, outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(","))); } } \ No newline at end of file diff --git a/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/CookingPotBuilder.java b/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/CookingPotBuilder.java index f15c870..5237839 100644 --- a/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/CookingPotBuilder.java +++ b/src/main/java/com/blamejared/compat/betterwithmods/base/bulkrecipes/CookingPotBuilder.java @@ -15,7 +15,7 @@ public class CookingPotBuilder extends BulkRecipeBuilder { private int heat = 1; private boolean ignoreHeat = false; - protected CookingPotBuilder(Supplier> registry, String name) { + public CookingPotBuilder(Supplier> registry, String name) { super(registry, name); } diff --git a/test_scripts/bwm.zs b/test_scripts/bwm.zs index 10a0f8b..13b9079 100644 --- a/test_scripts/bwm.zs +++ b/test_scripts/bwm.zs @@ -24,6 +24,8 @@ mods.betterwithmods.Anvil.addShaped(, [ //Cauldron +mods.betterwithmods.Cauldron.removeAll(); + mods.betterwithmods.Cauldron.builder() .buildRecipe([], []) .setHeat(2) @@ -65,9 +67,8 @@ mods.betterwithmods.Saw.builder() .build(); //Turntable - +mods.betterwithmods.Turntable.removeAll(); mods.betterwithmods.Turntable.add(, , []); - mods.betterwithmods.Turntable.add(, []); @@ -79,4 +80,4 @@ mods.betterwithmods.Kiln.builder() .build(); //Mini Block -recipes.addShaped("siding_test", ,[[mods.betterwithmods.MiniBlocks.getMiniBlock("siding", , 1)]]); \ No newline at end of file +recipes.addShaped("siding_test", ,[[mods.betterwithmods.MiniBlocks.getMiniBlock("siding", , 1)]]);