2011-01-03 12:24:25 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-01-19 09:07:56 +01:00
|
|
|
import org.bukkit.Server;
|
2011-01-03 12:24:25 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
2011-01-15 21:26:05 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2011-01-17 21:11:06 +01:00
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
2011-01-18 00:48:02 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
2011-01-21 17:39:58 +01:00
|
|
|
import org.bukkit.Location;
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-03 12:24:25 +01:00
|
|
|
|
|
|
|
public class Explosion {
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public boolean a = false;
|
|
|
|
private Random h = new Random();
|
2011-01-03 12:24:25 +01:00
|
|
|
private World i;
|
|
|
|
public double b;
|
|
|
|
public double c;
|
|
|
|
public double d;
|
|
|
|
public Entity e;
|
|
|
|
public float f;
|
2011-01-29 22:50:29 +01:00
|
|
|
public Set g = new HashSet();
|
2011-02-20 17:40:40 +01:00
|
|
|
|
|
|
|
public boolean wasCanceled = false; // Craftbukkit
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
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;
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a() {
|
2011-01-29 22:50:29 +01:00
|
|
|
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;
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
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;
|
2011-01-03 12:24:25 +01:00
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start - explosion damage hook
|
2011-01-29 22:50:29 +01:00
|
|
|
CraftServer server = ((WorldServer) this.i).getServer();
|
|
|
|
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
|
2011-01-18 00:48:02 +01:00
|
|
|
DamageCause damageType;
|
2011-01-29 22:50:29 +01:00
|
|
|
int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.f + 1.0D);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-02-09 03:52:06 +01:00
|
|
|
if(damagee == null) {
|
2011-01-19 09:07:56 +01:00
|
|
|
// nothing was hurt
|
|
|
|
} else if (e == null) { // Block explosion
|
|
|
|
// TODO: get the x/y/z of the tnt block?
|
|
|
|
// does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever
|
2011-01-18 00:48:02 +01:00
|
|
|
damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
|
2011-01-29 22:50:29 +01:00
|
|
|
EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(null, damagee, damageType, damageDone);
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
entity.a(this.e, event.getDamage());
|
2011-02-09 02:28:10 +01:00
|
|
|
entity.motX += d0 * d10;
|
|
|
|
entity.motY += d1 * d10;
|
|
|
|
entity.motZ += d2 * d10;
|
2011-01-17 21:11:06 +01:00
|
|
|
}
|
2011-01-03 12:24:25 +01:00
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
org.bukkit.entity.Entity damager = this.e.getBukkitEntity();
|
2011-01-19 09:07:56 +01:00
|
|
|
damageType = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
entity.a(this.e, event.getDamage());
|
2011-01-19 09:07:56 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
entity.motX += d0 * d10;
|
|
|
|
entity.motY += d1 * d10;
|
|
|
|
entity.motZ += d2 * d10;
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
2011-01-19 09:07:56 +01:00
|
|
|
// CraftBukkit end
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.f = f;
|
2011-01-03 12:24:25 +01:00
|
|
|
ArrayList arraylist = new ArrayList();
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
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);
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b() {
|
2011-01-29 22:50:29 +01:00
|
|
|
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);
|
2011-01-03 12:24:25 +01:00
|
|
|
ArrayList arraylist = new ArrayList();
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
arraylist.addAll(this.g);
|
2011-01-17 21:11:06 +01:00
|
|
|
|
2011-01-19 09:07:56 +01:00
|
|
|
// CraftBukkit start
|
2011-01-29 22:50:29 +01:00
|
|
|
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);
|
2011-01-19 09:07:56 +01:00
|
|
|
|
|
|
|
List<org.bukkit.block.Block> blocklist = new ArrayList<org.bukkit.block.Block>();
|
|
|
|
for (int j = arraylist.size() - 1; j >= 0; j--) {
|
|
|
|
ChunkPosition cpos = (ChunkPosition) arraylist.get(j);
|
|
|
|
org.bukkit.block.Block blox = world.getBlockAt(cpos.a, cpos.b, cpos.c);
|
2011-01-17 21:11:06 +01:00
|
|
|
if (!blox.getType().equals(org.bukkit.Material.AIR)) {
|
|
|
|
blocklist.add(blox);
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
2011-01-17 21:11:06 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-19 09:07:56 +01:00
|
|
|
org.bukkit.event.Event.Type eventType = EntityExplodeEvent.Type.ENTITY_EXPLODE;
|
2011-01-29 22:50:29 +01:00
|
|
|
EntityExplodeEvent event = new EntityExplodeEvent(eventType, splode, location, blocklist);
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
2011-02-07 19:37:08 +01:00
|
|
|
wasCanceled = true;
|
2011-01-19 09:07:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
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);
|
2011-01-19 09:07:56 +01:00
|
|
|
}
|
2011-01-03 12:24:25 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (i1 > 0) {
|
2011-02-20 17:40:40 +01:00
|
|
|
Block.byId[i1].a(this.i, j, k, l, this.i.getData(j, k, l), event.getYield()); // Craftbukkit
|
2011-01-29 22:50:29 +01:00
|
|
|
this.i.e(j, k, l, 0);
|
|
|
|
Block.byId[i1].a_(this.i, j, k, l);
|
2011-01-03 12:24:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|