From 1ca53da0e2d9947b1a583d97ffa0647bb9b459ab Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 27 Sep 2013 13:42:50 +0200 Subject: [PATCH] Also try to count recipe ingredients regardless of repairMaterial when the normal counting and the config value result in 0 Fixes #1484 --- .../java/com/gmail/nossr50/skills/repair/Repair.java | 10 +++++++--- .../nossr50/skills/repair/config/RepairConfig.java | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index 5b663220d..1c3d187b9 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -116,21 +116,25 @@ public class Repair { return getRepairAndSalvageQuantities(inHand, getSalvagedItem(inHand), (byte) -1); } + public static int getRepairAndSalvageQuantities(ItemStack item) { + return getRepairAndSalvageQuantities(item, null, (byte) -1); + } + public static int getRepairAndSalvageQuantities(ItemStack item, Material repairMaterial, byte repairMetadata) { int quantity = 0; - MaterialData repairData = new MaterialData(repairMaterial, repairMetadata); + MaterialData repairData = repairMaterial != null ? new MaterialData(repairMaterial, repairMetadata) : null; Recipe recipe = mcMMO.p.getServer().getRecipesFor(item).get(0); if (recipe instanceof ShapelessRecipe) { for (ItemStack ingredient : ((ShapelessRecipe) recipe).getIngredientList()) { - if (ingredient != null && ingredient.getType() == repairMaterial && (repairMetadata == -1 || ingredient.getData() == repairData)) { + if (ingredient != null && (repairMaterial == null || ingredient.getType() == repairMaterial) && (repairMetadata == -1 || ingredient.getData() == repairData)) { quantity += ingredient.getAmount(); } } } else if (recipe instanceof ShapedRecipe) { for (ItemStack ingredient : ((ShapedRecipe) recipe).getIngredientMap().values()) { - if (ingredient != null && ingredient.getType() == repairMaterial && (repairMetadata == -1 || ingredient.getData() == repairData)) { + if (ingredient != null && (repairMaterial == null || ingredient.getType() == repairMaterial) && (repairMetadata == -1 || ingredient.getData() == repairData)) { quantity += ingredient.getAmount(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java b/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java index 325653365..ccdd237ce 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java @@ -136,6 +136,10 @@ public class RepairConfig extends ConfigLoader { // Minimum Quantity int minimumQuantity = (itemMaterial != null && repairMaterial != null ? Repair.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), repairMaterial, repairMetadata) : config.getInt("Repairables." + key + ".MinimumQuantity")); + if (minimumQuantity <= 0 && itemMaterial != null) { + minimumQuantity = Repair.getRepairAndSalvageQuantities(new ItemStack(itemMaterial)); + } + if (minimumQuantity <= 0) { reason.add("Minimum quantity of " + key + " must be greater than 0!"); }