diff --git a/Changelog.txt b/Changelog.txt index d0c3331a3..b5673ccee 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -164,6 +164,10 @@ Version 2.2.0 Added API method to grab the level cap of a skill by its PrimarySkillType ENUM definition Added API method to check if a skill was being level capped Added 'UndefinedSkillBehaviour' for trying to use a method that has no behaviour defined for the provided skill +Version 2.1.78 + Shovels no longer take more than 1 diamond to repair + Tools with the unbreaking enchantment no longer take extra damage from ability usage, they are still subject to the normal durability damage from breaking blocks though. + Version 2.1.77 Added minimum quantity back to Repair config diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java index 34d6ad731..de8a52e0a 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java @@ -57,6 +57,10 @@ public class RepairableSerializer implements TypeSerializer { Material repairItem = (Material) getEnum(repairConstant, TypeToken.of(Material.class));*/ int minimumQuantity = value.getNode(MINIMUM_QUANTITY_USED_TO_REPAIR).getValue(TypeToken.of(Integer.class)); + + if(minimumQuantity == 0) + minimumQuantity = -1; + int minimumLevel = value.getNode(OVERRIDE_LEVEL_REQUIREMENT).getValue(TypeToken.of(Integer.class)); double xpMultiplier = value.getNode(XP_MULTIPLIER).getValue(TypeToken.of(Double.class)); diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java index 8547964d5..6d5cb72fd 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.repair.repairables; import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory; import com.gmail.nossr50.datatypes.skills.ItemType; import com.gmail.nossr50.util.ItemUtils; +import com.gmail.nossr50.util.skills.SkillUtils; import org.bukkit.Material; import java.util.Collections; @@ -61,7 +62,10 @@ public class Repairable { } public int getMinimumQuantity() { - return minimumQuantity; + if(minimumQuantity == -1) + return Math.max(SkillUtils.getRepairAndSalvageQuantities(itemMaterial, repairMaterials), 1); + else + return minimumQuantity; } public short getMaximumDurability() { diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java index 46054fa3c..deeffe9ba 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -8,6 +8,7 @@ import com.gmail.nossr50.util.skills.SkillUtils; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -136,6 +137,11 @@ public final class Woodcutting { * @return True if the tool can sustain the durability loss */ protected static boolean handleDurabilityLoss(Set treeFellerBlocks, ItemStack inHand) { + + if(inHand.getItemMeta().getEnchants().get(Enchantment.DURABILITY) >= 1) { + return true; + } + short durabilityLoss = 0; Material type = inHand.getType(); diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 5d3245a21..b04ea6bc0 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -228,7 +228,7 @@ public class SkillUtils { * @param maxDamageModifier the amount to adjust the max damage by */ public static void handleDurabilityChange(ItemStack itemStack, double durabilityModifier, double maxDamageModifier) { - if (itemStack.hasItemMeta() && itemStack.getItemMeta().isUnbreakable()) { + if (itemStack.getEnchantments().get(Enchantment.DURABILITY) != null && itemStack.getEnchantments().get(Enchantment.DURABILITY) >= 1) { return; } @@ -303,4 +303,44 @@ public class SkillUtils { return quantity; } + + public static int getRepairAndSalvageQuantities(Material itemMaterial, List recipeMaterials) { + int quantity = 0; + + for(Iterator recipeIterator = Bukkit.getServer().recipeIterator(); recipeIterator.hasNext();) { + Recipe bukkitRecipe = recipeIterator.next(); + + if(bukkitRecipe.getResult().getType() != itemMaterial) + continue; + + boolean matchedIngredient = false; + + for(Material recipeMaterial : recipeMaterials) { + if(matchedIngredient) + break; + + if(bukkitRecipe instanceof ShapelessRecipe) { + for (ItemStack ingredient : ((ShapelessRecipe) bukkitRecipe).getIngredientList()) { + if (ingredient != null + && (recipeMaterial == null || ingredient.getType() == recipeMaterial) + && (ingredient.getType() == recipeMaterial)) { + quantity += ingredient.getAmount(); + matchedIngredient = true; + } + } + } else if(bukkitRecipe instanceof ShapedRecipe) { + for (ItemStack ingredient : ((ShapedRecipe) bukkitRecipe).getIngredientMap().values()) { + if (ingredient != null + && (recipeMaterial == null || ingredient.getType() == recipeMaterial) + && (ingredient.getType() == recipeMaterial)) { + quantity += ingredient.getAmount(); + matchedIngredient = true; + } + } + } + } + } + + return quantity; + } }