2011-04-25 23:23:42 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2011-10-01 19:31:28 +02:00
|
|
|
import org.bukkit.entity.Painting;
|
2011-04-25 23:23:42 +02:00
|
|
|
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
|
2011-10-01 19:31:28 +02:00
|
|
|
import org.bukkit.event.painting.PaintingBreakEvent.RemoveCause;
|
|
|
|
import org.bukkit.event.painting.PaintingBreakEvent;
|
2011-04-25 23:23:42 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public class EntityPainting extends Entity {
|
|
|
|
|
|
|
|
private int f;
|
2012-01-12 16:27:39 +01:00
|
|
|
public int direction;
|
|
|
|
public int x;
|
|
|
|
public int y;
|
|
|
|
public int z;
|
|
|
|
public EnumArt art;
|
2011-04-25 23:23:42 +02:00
|
|
|
|
|
|
|
public EntityPainting(World world) {
|
|
|
|
super(world);
|
|
|
|
this.f = 0;
|
2012-01-12 16:27:39 +01:00
|
|
|
this.direction = 0;
|
2011-04-25 23:23:42 +02:00
|
|
|
this.height = 0.0F;
|
|
|
|
this.b(0.5F, 0.5F);
|
2012-01-12 16:27:39 +01:00
|
|
|
this.art = EnumArt.values()[this.random.nextInt(EnumArt.values().length)]; // CraftBukkit - generate a non-null painting
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public EntityPainting(World world, int i, int j, int k, int l) {
|
|
|
|
this(world);
|
2012-01-12 16:27:39 +01:00
|
|
|
this.x = i;
|
|
|
|
this.y = j;
|
|
|
|
this.z = k;
|
2011-04-25 23:23:42 +02:00
|
|
|
ArrayList arraylist = new ArrayList();
|
|
|
|
EnumArt[] aenumart = EnumArt.values();
|
|
|
|
int i1 = aenumart.length;
|
|
|
|
|
|
|
|
for (int j1 = 0; j1 < i1; ++j1) {
|
|
|
|
EnumArt enumart = aenumart[j1];
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
this.art = enumart;
|
|
|
|
this.setDirection(l);
|
|
|
|
if (this.survives()) {
|
2011-04-25 23:23:42 +02:00
|
|
|
arraylist.add(enumart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arraylist.size() > 0) {
|
2012-01-12 16:27:39 +01:00
|
|
|
this.art = (EnumArt) arraylist.get(this.random.nextInt(arraylist.size()));
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
this.setDirection(l);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void b() {}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
public void setDirection(int i) {
|
|
|
|
this.direction = i;
|
2011-04-25 23:23:42 +02:00
|
|
|
this.lastYaw = this.yaw = (float) (i * 90);
|
2012-01-12 16:27:39 +01:00
|
|
|
float f = (float) this.art.B;
|
|
|
|
float f1 = (float) this.art.C;
|
|
|
|
float f2 = (float) this.art.B;
|
2011-04-25 23:23:42 +02:00
|
|
|
|
|
|
|
if (i != 0 && i != 2) {
|
|
|
|
f = 0.5F;
|
|
|
|
} else {
|
|
|
|
f2 = 0.5F;
|
|
|
|
}
|
|
|
|
|
|
|
|
f /= 32.0F;
|
|
|
|
f1 /= 32.0F;
|
|
|
|
f2 /= 32.0F;
|
2012-01-12 16:27:39 +01:00
|
|
|
float f3 = (float) this.x + 0.5F;
|
|
|
|
float f4 = (float) this.y + 0.5F;
|
|
|
|
float f5 = (float) this.z + 0.5F;
|
2011-04-25 23:23:42 +02:00
|
|
|
float f6 = 0.5625F;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
f5 -= f6;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 1) {
|
|
|
|
f3 -= f6;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 2) {
|
|
|
|
f5 += f6;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 3) {
|
|
|
|
f3 += f6;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
2012-01-12 16:27:39 +01:00
|
|
|
f3 -= this.c(this.art.B);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 1) {
|
2012-01-12 16:27:39 +01:00
|
|
|
f5 += this.c(this.art.B);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 2) {
|
2012-01-12 16:27:39 +01:00
|
|
|
f3 += this.c(this.art.B);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 3) {
|
2012-01-12 16:27:39 +01:00
|
|
|
f5 -= this.c(this.art.B);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
f4 += this.c(this.art.C);
|
2011-04-25 23:23:42 +02:00
|
|
|
this.setPosition((double) f3, (double) f4, (double) f5);
|
|
|
|
float f7 = -0.00625F;
|
|
|
|
|
|
|
|
this.boundingBox.c((double) (f3 - f - f7), (double) (f4 - f1 - f7), (double) (f5 - f2 - f7), (double) (f3 + f + f7), (double) (f4 + f1 + f7), (double) (f5 + f2 + f7));
|
|
|
|
}
|
|
|
|
|
|
|
|
private float c(int i) {
|
|
|
|
return i == 32 ? 0.5F : (i == 64 ? 0.5F : 0.0F);
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public void y_() {
|
2011-04-25 23:23:42 +02:00
|
|
|
if (this.f++ == 100 && !this.world.isStatic) {
|
|
|
|
this.f = 0;
|
2012-01-12 16:27:39 +01:00
|
|
|
if (!this.survives()) {
|
2011-04-25 23:23:42 +02:00
|
|
|
// CraftBukkit start
|
2012-01-14 23:02:10 +01:00
|
|
|
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ);
|
2011-10-01 19:31:28 +02:00
|
|
|
RemoveCause cause;
|
|
|
|
if (material.equals(Material.WATER)) {
|
|
|
|
cause = RemoveCause.WATER;
|
|
|
|
} else if (!material.equals(Material.AIR)) {
|
|
|
|
// TODO: This feels insufficient to catch 100% of suffocation cases
|
|
|
|
cause = RemoveCause.OBSTRUCTION;
|
|
|
|
} else {
|
|
|
|
cause = RemoveCause.PHYSICS;
|
|
|
|
}
|
|
|
|
PaintingBreakEvent event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), cause);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-04-25 23:23:42 +02:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-14 23:02:10 +01:00
|
|
|
if (!dead) {
|
2011-09-17 22:47:07 +02:00
|
|
|
this.die();
|
|
|
|
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
public boolean survives() {
|
|
|
|
if (this.world.a(this, this.boundingBox).size() > 0) {
|
2011-04-25 23:23:42 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
2012-01-12 16:27:39 +01:00
|
|
|
int i = this.art.B / 16;
|
|
|
|
int j = this.art.C / 16;
|
|
|
|
int k = this.x;
|
|
|
|
int l = this.y;
|
|
|
|
int i1 = this.z;
|
|
|
|
|
|
|
|
if (this.direction == 0) {
|
|
|
|
k = MathHelper.floor(this.locX - (double) ((float) this.art.B / 32.0F));
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
if (this.direction == 1) {
|
|
|
|
i1 = MathHelper.floor(this.locZ - (double) ((float) this.art.B / 32.0F));
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
if (this.direction == 2) {
|
|
|
|
k = MathHelper.floor(this.locX - (double) ((float) this.art.B / 32.0F));
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
if (this.direction == 3) {
|
|
|
|
i1 = MathHelper.floor(this.locZ - (double) ((float) this.art.B / 32.0F));
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
l = MathHelper.floor(this.locY - (double) ((float) this.art.C / 32.0F));
|
2011-04-25 23:23:42 +02:00
|
|
|
|
|
|
|
int j1;
|
|
|
|
|
|
|
|
for (int k1 = 0; k1 < i; ++k1) {
|
|
|
|
for (j1 = 0; j1 < j; ++j1) {
|
|
|
|
Material material;
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
if (this.direction != 0 && this.direction != 2) {
|
|
|
|
material = this.world.getMaterial(this.x, l + j1, i1 + k1);
|
2011-04-25 23:23:42 +02:00
|
|
|
} else {
|
2012-01-12 16:27:39 +01:00
|
|
|
material = this.world.getMaterial(k + k1, l + j1, this.z);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!material.isBuildable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
List list = this.world.getEntities(this, this.boundingBox);
|
2011-04-25 23:23:42 +02:00
|
|
|
|
|
|
|
for (j1 = 0; j1 < list.size(); ++j1) {
|
|
|
|
if (list.get(j1) instanceof EntityPainting) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public boolean e_() {
|
2011-04-25 23:23:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
public boolean damageEntity(DamageSource damagesource, int i) {
|
2011-04-25 23:23:42 +02:00
|
|
|
if (!this.dead && !this.world.isStatic) {
|
|
|
|
// CraftBukkit start
|
2011-10-01 19:31:28 +02:00
|
|
|
PaintingBreakEvent event = null;
|
|
|
|
if (damagesource.getEntity() != null) {
|
|
|
|
event = new PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
|
|
|
|
} else {
|
|
|
|
if (damagesource == DamageSource.FIRE) {
|
|
|
|
event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), RemoveCause.FIRE);
|
|
|
|
}
|
|
|
|
// TODO: Could put other stuff here?
|
|
|
|
}
|
|
|
|
if (event != null) {
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-10-01 19:31:28 +02:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (dead) return true;
|
2011-09-17 22:47:07 +02:00
|
|
|
// CraftBukkit end
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
this.die();
|
2012-01-12 23:10:13 +01:00
|
|
|
this.aM();
|
2011-11-20 09:01:14 +01:00
|
|
|
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
2012-01-12 16:27:39 +01:00
|
|
|
nbttagcompound.setByte("Dir", (byte) this.direction);
|
|
|
|
nbttagcompound.setString("Motive", this.art.A);
|
|
|
|
nbttagcompound.setInt("TileX", this.x);
|
|
|
|
nbttagcompound.setInt("TileY", this.y);
|
|
|
|
nbttagcompound.setInt("TileZ", this.z);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
2012-01-12 16:27:39 +01:00
|
|
|
this.direction = nbttagcompound.getByte("Dir");
|
|
|
|
this.x = nbttagcompound.getInt("TileX");
|
|
|
|
this.y = nbttagcompound.getInt("TileY");
|
|
|
|
this.z = nbttagcompound.getInt("TileZ");
|
2011-04-25 23:23:42 +02:00
|
|
|
String s = nbttagcompound.getString("Motive");
|
|
|
|
EnumArt[] aenumart = EnumArt.values();
|
|
|
|
int i = aenumart.length;
|
|
|
|
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
EnumArt enumart = aenumart[j];
|
|
|
|
|
|
|
|
if (enumart.A.equals(s)) {
|
2012-01-12 16:27:39 +01:00
|
|
|
this.art = enumart;
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
if (this.art == null) {
|
|
|
|
this.art = EnumArt.KEBAB;
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
this.setDirection(this.direction);
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|
2011-07-08 14:25:53 +02:00
|
|
|
|
2011-09-15 05:13:14 +02:00
|
|
|
public void move(double d0, double d1, double d2) {
|
2011-07-08 14:25:53 +02:00
|
|
|
if (!this.world.isStatic && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
|
2011-11-20 09:01:14 +01:00
|
|
|
if (dead) return; // CraftBukkit
|
2011-09-17 22:47:07 +02:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
this.die();
|
|
|
|
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
|
2011-07-08 14:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public void b_(double d0, double d1, double d2) {
|
2011-07-08 14:25:53 +02:00
|
|
|
if (!this.world.isStatic && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
|
2011-11-20 09:01:14 +01:00
|
|
|
if (dead) return; // CraftBukkit
|
2011-09-17 22:47:07 +02:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
this.die();
|
|
|
|
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
|
2011-07-08 14:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-25 23:23:42 +02:00
|
|
|
}
|