From dc988b7c805bae053f42be43d652a6a0b1e2bf77 Mon Sep 17 00:00:00 2001 From: Lightling Date: Tue, 17 Sep 2019 16:35:16 -0400 Subject: [PATCH] implemented chance-checking to unbreaking tools with same % chance as for vanilla tools --- .../gibsoniacraft/util/BlockListener.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java b/plugin/src/lightling/gibsoniacraft/util/BlockListener.java index 1c8d389..107fbb3 100644 --- a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java +++ b/plugin/src/lightling/gibsoniacraft/util/BlockListener.java @@ -125,7 +125,13 @@ public class BlockListener implements Listener else if (item.getEnchantments().containsKey(Enchantment.DURABILITY)) { - addToDamage = 0; + double level = item.getEnchantmentLevel(Enchantment.DURABILITY); + double chance = 100 / (level + 1); + double rng = (Math.random() * 100) + 1; + if (rng >= chance) + { + addToDamage = 0; + } } // Update durability @@ -207,7 +213,13 @@ public class BlockListener implements Listener else if (item.getEnchantments().containsKey(Enchantment.DURABILITY)) { - addToDamage = 0; + double level = item.getEnchantmentLevel(Enchantment.DURABILITY); + double chance = 100 / (level + 1); + double rng = (Math.random() * 100) + 1; + if (rng >= chance) + { + addToDamage = 0; + } } // Update durability