diff options
author | Genny <gen@nyble.dev> | 2020-06-14 03:23:23 -0500 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2020-06-14 03:23:23 -0500 |
commit | bd67ded0284e4a9f65c6938862d289801e7ce04b (patch) | |
tree | 1132fa12d8bd26195d30d86f80c51a8e9622e9a5 /src | |
parent | b9f26aa0c729fc1fe0864991366f10df3ab4945c (diff) | |
download | sunfright-bd67ded0284e4a9f65c6938862d289801e7ce04b.tar.gz sunfright-bd67ded0284e4a9f65c6938862d289801e7ce04b.zip |
Add fire prot above 1 acting as unbr
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/dev/genbyte/sunfright/Damager.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/main/java/dev/genbyte/sunfright/Damager.java b/src/main/java/dev/genbyte/sunfright/Damager.java index c84de86..83c57e7 100644 --- a/src/main/java/dev/genbyte/sunfright/Damager.java +++ b/src/main/java/dev/genbyte/sunfright/Damager.java @@ -1,6 +1,8 @@ package dev.genbyte.sunfright; import java.util.Collection; +import java.util.Random; +import java.util.logging.Level; import org.bukkit.Material; import org.bukkit.World; @@ -13,9 +15,11 @@ import org.bukkit.scheduler.BukkitRunnable; public class Damager extends BukkitRunnable { private final Sunfright sf; + private final Random rand; public Damager(Sunfright sf) { this.sf = sf; + this.rand = new Random(); } public void run() { @@ -76,9 +80,11 @@ public class Damager extends BukkitRunnable { if (helmetMeta instanceof Damageable) { Damageable helmetDamageable = (Damageable) helmetMeta; int helmetDamage = helmetDamageable.getDamage(); + int fireProtLevel = helmet.getEnchantmentLevel(Enchantment.PROTECTION_FIRE); + int unbrLevel = helmet.getEnchantmentLevel(Enchantment.DURABILITY); - if (helmet.getEnchantmentLevel(Enchantment.PROTECTION_FIRE) < 1) { - applyDamage(); + if (fireProtLevel < 1) { + damagePlayer(); return; } @@ -97,16 +103,23 @@ public class Damager extends BukkitRunnable { player.getInventory().setHelmet(new ItemStack(Material.AIR)); } else { - helmetDamageable.setDamage(helmetDamage + (damage/2)); - helmet.setItemMeta((ItemMeta) helmetDamageable); + // Formula from https://minecraft.gamepedia.com/Unbreaking + // Origintal is 60 + (40 / (level+1)) but we subtract one from fireProtLevel + // so the +1 cancels + int chanceToDamage = 60 + (40 / (fireProtLevel+unbrLevel)); + + if (rand.nextInt(99)+1 <= chanceToDamage) { + helmetDamageable.setDamage(helmetDamage + (damage/2)); + helmet.setItemMeta((ItemMeta) helmetDamageable); + } } } } else { - applyDamage(); + damagePlayer(); } } - private void applyDamage() { + private void damagePlayer() { player.damage(damage); } } |