diff options
author | Erik Broes <erikbroes@grum.nl> | 2011-01-29 22:50:29 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-01-30 13:24:39 +0100 |
commit | df69047324abc54f5d5b8d069bb69b1061b20cce (patch) | |
tree | 76f8d13addf80730deea9285f4bd9a1ffbe45f80 /src/main/java/net/minecraft/server/Explosion.java | |
parent | d0cd8c6cc7d1aaf38934996e7e5d3e03272e4ff1 (diff) | |
download | craftbukkit-df69047324abc54f5d5b8d069bb69b1061b20cce.tar craftbukkit-df69047324abc54f5d5b8d069bb69b1061b20cce.tar.gz craftbukkit-df69047324abc54f5d5b8d069bb69b1061b20cce.tar.lz craftbukkit-df69047324abc54f5d5b8d069bb69b1061b20cce.tar.xz craftbukkit-df69047324abc54f5d5b8d069bb69b1061b20cce.zip |
Port to new mc-dev format.
Diffstat (limited to 'src/main/java/net/minecraft/server/Explosion.java')
-rw-r--r-- | src/main/java/net/minecraft/server/Explosion.java | 320 |
1 files changed, 160 insertions, 160 deletions
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index 3344eb35..3dd9a4fd 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -1,127 +1,127 @@ package net.minecraft.server; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + // CraftBukkit start import org.bukkit.Server; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; - import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; - import org.bukkit.Location; - // CraftBukkit end -import java.util.*; - public class Explosion { - public boolean a; - private Random h; + public boolean a = false; + private Random h = new Random(); private World i; public double b; public double c; public double d; public Entity e; public float f; - public Set g; - - public Explosion(World world, Entity entity, double d1, double d2, double d3, float f1) { - a = false; - h = new Random(); - g = ((Set) (new HashSet())); - i = world; - e = entity; - f = f1; - b = d1; - c = d2; - d = d3; - + public Set g = new HashSet(); + + public Explosion(World world, Entity entity, double d0, double d1, double d2, float f) { + this.i = world; + this.e = entity; + this.f = f; + this.b = d0; + this.c = d1; + this.d = d2; } public void a() { - float f1 = f; - int j = 16; - - for (int k = 0; k < j; k++) { - for (int i1 = 0; i1 < j; i1++) { - label0: - for (int k1 = 0; k1 < j; k1++) { - if (k != 0 && k != j - 1 && i1 != 0 && i1 != j - 1 && k1 != 0 && k1 != j - 1) { - continue; - } - double d1 = ((float) k / ((float) j - 1.0F)) * 2.0F - 1.0F; - double d2 = ((float) i1 / ((float) j - 1.0F)) * 2.0F - 1.0F; - double d3 = ((float) k1 / ((float) j - 1.0F)) * 2.0F - 1.0F; - double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3); - - d1 /= d4; - d2 /= d4; - d3 /= d4; - float f2 = f * (0.7F + i.l.nextFloat() * 0.6F); - double d5 = b; - double d7 = c; - double d9 = d; - float f3 = 0.3F; - - do { - if (f2 <= 0.0F) { - continue label0; + float f = this.f; + byte b0 = 16; + + int i; + int j; + int k; + double d0; + double d1; + double d2; + + for (i = 0; i < b0; ++i) { + for (j = 0; j < b0; ++j) { + for (k = 0; k < b0; ++k) { + if (i == 0 || i == b0 - 1 || j == 0 || j == b0 - 1 || k == 0 || k == b0 - 1) { + double d3 = (double) ((float) i / ((float) b0 - 1.0F) * 2.0F - 1.0F); + double d4 = (double) ((float) j / ((float) b0 - 1.0F) * 2.0F - 1.0F); + double d5 = (double) ((float) k / ((float) b0 - 1.0F) * 2.0F - 1.0F); + double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5); + + d3 /= d6; + d4 /= d6; + d5 /= d6; + float f1 = this.f * (0.7F + this.i.l.nextFloat() * 0.6F); + + d0 = this.b; + d1 = this.c; + d2 = this.d; + + for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) { + int l = MathHelper.b(d0); + int i1 = MathHelper.b(d1); + int j1 = MathHelper.b(d2); + int k1 = this.i.getTypeId(l, i1, j1); + + if (k1 > 0) { + f1 -= (Block.byId[k1].a(this.e) + 0.3F) * f2; + } + + if (f1 > 0.0F) { + this.g.add(new ChunkPosition(l, i1, j1)); + } + + d0 += d3 * (double) f2; + d1 += d4 * (double) f2; + d2 += d5 * (double) f2; } - int j2 = MathHelper.b(d5); - int k2 = MathHelper.b(d7); - int l2 = MathHelper.b(d9); - int i3 = i.a(j2, k2, l2); - - if (i3 > 0) { - f2 -= (Block.m[i3].a(e) + 0.3F) * f3; - } - if (f2 > 0.0F) { - g.add(((new ChunkPosition(j2, k2, l2)))); - } - d5 += d1 * (double) f3; - d7 += d2 * (double) f3; - d9 += d3 * (double) f3; - f2 -= f3 * 0.75F; - } while (true); + } } } } - f *= 2.0F; - int l = MathHelper.b(b - (double) f - 1.0D); - int j1 = MathHelper.b(b + (double) f + 1.0D); - int l1 = MathHelper.b(c - (double) f - 1.0D); - int j3 = MathHelper.b(c + (double) f + 1.0D); - int k3 = MathHelper.b(d - (double) f - 1.0D); - int l3 = MathHelper.b(d + (double) f + 1.0D); - List list = i.b(e, AxisAlignedBB.b(l, l1, k3, j1, j3, l3)); - Vec3D vec3d = Vec3D.b(b, c, d); - - for (int i4 = 0; i4 < list.size(); i4++) { - Entity entity = (Entity) list.get(i4); - double d11 = entity.e(b, c, d) / (double) f; - - if (d11 <= 1.0D) { - double d6 = entity.p - b; - double d8 = entity.q - c; - double d10 = entity.r - d; - double d12 = MathHelper.a(d6 * d6 + d8 * d8 + d10 * d10); - - d6 /= d12; - d8 /= d12; - d10 /= d12; - double d13 = i.a(vec3d, entity.z); - double d14 = (1.0D - d11) * d13; + this.f *= 2.0F; + i = MathHelper.b(this.b - (double) this.f - 1.0D); + j = MathHelper.b(this.b + (double) this.f + 1.0D); + k = MathHelper.b(this.c - (double) this.f - 1.0D); + int l1 = MathHelper.b(this.c + (double) this.f + 1.0D); + int i2 = MathHelper.b(this.d - (double) this.f - 1.0D); + int j2 = MathHelper.b(this.d + (double) this.f + 1.0D); + List list = this.i.b(this.e, AxisAlignedBB.b((double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2)); + Vec3D vec3d = Vec3D.b(this.b, this.c, this.d); + + for (int k2 = 0; k2 < list.size(); ++k2) { + Entity entity = (Entity) list.get(k2); + double d7 = entity.e(this.b, this.c, this.d) / (double) this.f; + + if (d7 <= 1.0D) { + d0 = entity.locX - this.b; + d1 = entity.locY - this.c; + d2 = entity.locZ - this.d; + double d8 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2); + + d0 /= d8; + d1 /= d8; + d2 /= d8; + double d9 = (double) this.i.a(vec3d, entity.boundingBox); + double d10 = (1.0D - d7) * d9; // CraftBukkit start - explosion damage hook - CraftServer server = ((WorldServer) i).getServer(); - org.bukkit.entity.Entity damagee = (entity == null)?null:entity.getBukkitEntity(); + CraftServer server = ((WorldServer) this.i).getServer(); + org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); DamageCause damageType; - int damageDone = (int) (((d14 * d14 + d14) / 2D) * 8D * (double) f + 1.0D); + int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.f + 1.0D); if(damagee == null){ // nothing was hurt @@ -129,62 +129,61 @@ public class Explosion { // TODO: get the x/y/z of the tnt block? // does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION; - EntityDamageByBlockEvent edbbe = new EntityDamageByBlockEvent(null, damagee, damageType, damageDone); - server.getPluginManager().callEvent(edbbe); - if (!edbbe.isCancelled()) { - entity.a(e, edbbe.getDamage()); + EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(null, damagee, damageType, damageDone); + server.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + entity.a(this.e, event.getDamage()); } } else { - org.bukkit.entity.Entity damager = e.getBukkitEntity(); + org.bukkit.entity.Entity damager = this.e.getBukkitEntity(); damageType = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION; - - EntityDamageByEntityEvent edbbe = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone); - server.getPluginManager().callEvent(edbbe); - if (!edbbe.isCancelled()) { - entity.a(e, edbbe.getDamage()); - double d15 = d14; + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone); + server.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + entity.a(this.e, event.getDamage()); - entity.s += d6 * d15; - entity.t += d8 * d15; - entity.u += d10 * d15; + entity.motX += d0 * d10; + entity.motY += d1 * d10; + entity.motZ += d2 * d10; } } // CraftBukkit end } } - f = f1; + this.f = f; ArrayList arraylist = new ArrayList(); - ((List) (arraylist)).addAll(((java.util.Collection) (g))); - if (a) { - for (int j4 = ((List) (arraylist)).size() - 1; j4 >= 0; j4--) { - ChunkPosition chunkposition = (ChunkPosition) ((List) (arraylist)).get(j4); - int i2 = chunkposition.a; - int k4 = chunkposition.b; - int l4 = chunkposition.c; - int i5 = i.a(i2, k4, l4); - int j5 = i.a(i2, k4 - 1, l4); - - if (i5 == 0 && Block.o[j5] && h.nextInt(3) == 0) { - i.e(i2, k4, l4, Block.ar.bi); + arraylist.addAll(this.g); + if (this.a) { + for (int l2 = arraylist.size() - 1; l2 >= 0; --l2) { + ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l2); + int i3 = chunkposition.a; + int j3 = chunkposition.b; + int k3 = chunkposition.c; + int l3 = this.i.getTypeId(i3, j3, k3); + int i4 = this.i.getTypeId(i3, j3 - 1, k3); + + if (l3 == 0 && Block.o[i4] && this.h.nextInt(3) == 0) { + this.i.e(i3, j3, k3, Block.FIRE.id); } } } } public void b() { - i.a(b, c, d, "random.explode", 4F, (1.0F + (i.l.nextFloat() - i.l.nextFloat()) * 0.2F) * 0.7F); + this.i.a(this.b, this.c, this.d, "random.explode", 4.0F, (1.0F + (this.i.l.nextFloat() - this.i.l.nextFloat()) * 0.2F) * 0.7F); ArrayList arraylist = new ArrayList(); - ((List) (arraylist)).addAll(((java.util.Collection) (g))); + arraylist.addAll(this.g); // CraftBukkit start - Server server = ((WorldServer) i).getServer(); - CraftWorld world = ((WorldServer) i).getWorld(); - org.bukkit.entity.Entity splode = (e == null) ? null : e.getBukkitEntity(); - Location location = new Location(world, b, c, d); + Server server = ((WorldServer) this.i).getServer(); + CraftWorld world = ((WorldServer) this.i).getWorld(); + org.bukkit.entity.Entity splode = (this.e == null) ? null : this.e.getBukkitEntity(); + Location location = new Location(world, this.b, this.c, this.d); List<org.bukkit.block.Block> blocklist = new ArrayList<org.bukkit.block.Block>(); for (int j = arraylist.size() - 1; j >= 0; j--) { @@ -194,48 +193,49 @@ public class Explosion { blocklist.add(blox); } } - + org.bukkit.event.Event.Type eventType = EntityExplodeEvent.Type.ENTITY_EXPLODE; - EntityExplodeEvent eee = new EntityExplodeEvent(eventType, splode, location, blocklist); - server.getPluginManager().callEvent(eee); - - if (eee.isCancelled()) { + EntityExplodeEvent event = new EntityExplodeEvent(eventType, splode, location, blocklist); + server.getPluginManager().callEvent(event); + + if (event.isCancelled()) { return; } // CraftBukkit end - for (int j = ((List) (arraylist)).size() - 1; j >= 0; j--) { - ChunkPosition chunkposition = (ChunkPosition) ((List) (arraylist)).get(j); - int k = chunkposition.a; - int l = chunkposition.b; - int i1 = chunkposition.c; - int j1 = i.a(k, l, i1); - - for (int k1 = 0; k1 < 1; k1++) { - double d1 = (float) k + i.l.nextFloat(); - double d2 = (float) l + i.l.nextFloat(); - double d3 = (float) i1 + i.l.nextFloat(); - double d4 = d1 - b; - double d5 = d2 - c; - double d6 = d3 - d; - double d7 = MathHelper.a(d4 * d4 + d5 * d5 + d6 * d6); - - d4 /= d7; - d5 /= d7; - d6 /= d7; - double d8 = 0.5D / (d7 / (double) f + 0.10000000000000001D); - - d8 *= i.l.nextFloat() * i.l.nextFloat() + 0.3F; - d4 *= d8; - d5 *= d8; - d6 *= d8; - i.a("explode", (d1 + b * 1.0D) / 2D, (d2 + c * 1.0D) / 2D, (d3 + d * 1.0D) / 2D, d4, d5, d6); - i.a("smoke", d1, d2, d3, d4, d5, d6); + + for (int i = arraylist.size() - 1; i >= 0; --i) { + ChunkPosition chunkposition = (ChunkPosition) arraylist.get(i); + int j = chunkposition.a; + int k = chunkposition.b; + int l = chunkposition.c; + int i1 = this.i.getTypeId(j, k, l); + + for (int j1 = 0; j1 < 1; ++j1) { + double d0 = (double) ((float) j + this.i.l.nextFloat()); + double d1 = (double) ((float) k + this.i.l.nextFloat()); + double d2 = (double) ((float) l + this.i.l.nextFloat()); + double d3 = d0 - this.b; + double d4 = d1 - this.c; + double d5 = d2 - this.d; + double d6 = (double) MathHelper.a(d3 * d3 + d4 * d4 + d5 * d5); + + d3 /= d6; + d4 /= d6; + d5 /= d6; + double d7 = 0.5D / (d6 / (double) this.f + 0.1D); + + d7 *= (double) (this.i.l.nextFloat() * this.i.l.nextFloat() + 0.3F); + d3 *= d7; + d4 *= d7; + d5 *= d7; + this.i.a("explode", (d0 + this.b * 1.0D) / 2.0D, (d1 + this.c * 1.0D) / 2.0D, (d2 + this.d * 1.0D) / 2.0D, d3, d4, d5); + this.i.a("smoke", d0, d1, d2, d3, d4, d5); } - if (j1 > 0) { - Block.m[j1].a(i, k, l, i1, i.b(k, l, i1), 0.3F); - i.e(k, l, i1, 0); - Block.m[j1].a_(i, k, l, i1); + if (i1 > 0) { + Block.byId[i1].a(this.i, j, k, l, this.i.getData(j, k, l), 0.3F); + this.i.e(j, k, l, 0); + Block.byId[i1].a_(this.i, j, k, l); } } } |