diff --git a/CHANGELOG.md b/CHANGELOG.md index a21c1da8f..623c0b218 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ * (1.16+) Added Nether Gold Ore recipe to the Ore Crusher * (1.16+) Added Shroomlights to the fuel list for the Bio Generator * (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator +* Added an AoE damage effect to the Explosive Bow #### Changes * Coolant Cells now last twice as long diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index 6c283dcd0..92bda6202 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -17,17 +17,31 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import java.util.Collection; +/** + * The {@link ExplosiveBow} is a {@link SlimefunBow} which creates a fake explosion when it hits + * a {@link LivingEntity}. Any nearby {@link LivingEntity LivingEntities} get pushed away and + * take a little bit of damage, similar to an "Area of Effect" damage. + * + * @author TheBusyBiscuit + * @author Linox + * + * @see SlimefunBow + * + */ public class ExplosiveBow extends SlimefunBow { private final ItemSetting range = new ItemSetting("explosion-range", 3) { + @Override public boolean validateInput(Integer input) { - return input != null && input > 0; + return super.validateInput(input) && input > 0; } + }; public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) { super(category, item, recipe); + addItemSetting(range); } @@ -35,27 +49,29 @@ public class ExplosiveBow extends SlimefunBow { public BowShootHandler onShoot() { return (e, target) -> { target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1); - target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1); Collection entites = target.getWorld().getNearbyEntities(target.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid()); - for (Entity entity : entites) { - LivingEntity entityL = (LivingEntity) entity; + for (Entity nearby : entites) { + LivingEntity entity = (LivingEntity) nearby; - Vector distanceVector = entityL.getLocation().toVector().subtract(target.getLocation().toVector()); - distanceVector.setY(distanceVector.getY() + 0.6D); - Vector entityVelocity = entityL.getVelocity(); + Vector distanceVector = entity.getLocation().toVector().subtract(target.getLocation().toVector()); + distanceVector.setY(distanceVector.getY() + 0.6); + + Vector velocity = entity.getVelocity(); double distanceSquared = distanceVector.lengthSquared(); double damage = calculateDamage(distanceSquared, e.getDamage()); - Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage))); - entityL.setVelocity(knockback); + Vector knockback = velocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage))); + entity.setVelocity(knockback); - if (!entityL.getUniqueId().equals(target.getUniqueId())) { - EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); - Bukkit.getPluginManager().callEvent(damageEvent); - if (!damageEvent.isCancelled()) { - entityL.damage(damageEvent.getDamage()); + if (!entity.getUniqueId().equals(target.getUniqueId())) { + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(e.getDamager(), entity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + entity.damage(event.getDamage()); } } } @@ -63,7 +79,10 @@ public class ExplosiveBow extends SlimefunBow { } private double calculateDamage(double distanceSquared, double originalDamage) { - if (distanceSquared <= 0.05D) return originalDamage; + if (distanceSquared <= 0.05) { + return originalDamage; + } + double damage = originalDamage * (1 - (distanceSquared / (range.getValue() * range.getValue()))); return Math.min(Math.max(1, damage), originalDamage); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index b4fffe314..1a541a456 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -180,6 +180,7 @@ public final class PostSetup { if (input[0] != null && recipe[0] != null) { grinderRecipes.add(new ItemStack[] { input[0], recipe[0] }); } + input = null; } }