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 | |
parent | b9f26aa0c729fc1fe0864991366f10df3ab4945c (diff) | |
download | sunfright-bd67ded0284e4a9f65c6938862d289801e7ce04b.tar.gz sunfright-bd67ded0284e4a9f65c6938862d289801e7ce04b.zip |
Add fire prot above 1 acting as unbr
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | pom.xml | 2 | ||||
-rw-r--r-- | src/main/java/dev/genbyte/sunfright/Damager.java | 25 |
3 files changed, 27 insertions, 7 deletions
diff --git a/README.md b/README.md index 360583b..5d53542 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,13 @@ this time of day. | Raining | 12733 - 23266 | ![](docs/stormy_safe.png) | | Thunder Storm | 12299 - 23699 | ![](docs/thunder_safe.png) | +In addition to these conditions, your helmet may not take damage if you have +Unbreaking or a level of Fire Protection higher than 1. There is a +`(60 + (40 รท (Unbreaking level + Fire Protection level) ) )%` chance that your +helmet will take damage. Which means if you have Fire Protection I and +Unbreaking III, there is a 30% chance your helmet won't take damage. With +Fire Protection IV and Unbreaking III, there is a 35% chance your helmet won't +take damage. ### Notes - Respawn helmets disappear when you are safe. diff --git a/pom.xml b/pom.xml index b35b461..d0d5811 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ <groupId>dev.genbyte.sunfright</groupId> <artifactId>sunfright</artifactId> <packaging>jar</packaging> - <version>0.5.0</version> + <version>0.6.0</version> <name>sunfright</name> <description>Burn me to a crisp, large glowing orb!</description> 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); } } |