From f5b6abfae1377905e6fc2c46e36dfe2279c48b2b Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Sat, 23 Jun 2012 08:31:01 -0500 Subject: [PATCH] Fix double overflow/underflow calculations with explosions. Fixes BUKKIT-1865 --- .../java/net/minecraft/server/Explosion.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index e4ba32070e..c1582f66bf 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -108,17 +108,26 @@ public class Explosion { for (int k2 = 0; k2 < list.size(); ++k2) { Entity entity = (Entity) list.get(k2); - double d7 = entity.f(this.posX, this.posY, this.posZ) / (double) this.size; + // CraftBukkit - start + d0 = entity.locX - this.posX; + d1 = entity.locY - this.posY; + d2 = entity.locZ - this.posZ; + double d8 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); + + double d7 = d8 / this.size; // Don't call sub-method and sqrt again if (d7 <= 1.0D) { - d0 = entity.locX - this.posX; - d1 = entity.locY - this.posY; - d2 = entity.locZ - this.posZ; - double d8 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); // CraftBukkit - - d0 /= d8; - d1 /= d8; - d2 /= d8; + // Moved calculations up + if (d8 != 0) { + d0 /= d8; + d1 /= d8; + d2 /= d8; + } else { // Compensate for underflow + d0 = 0d; + d1 = 0d; + d2 = 0d; + } + // CraftBukkit - end double d9 = (double) this.world.a(vec3d, entity.boundingBox); double d10 = (1.0D - d7) * d9;