3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 14:28:09 +01:00
Paper/src/main/java/net/minecraft/server/EntityMinecart.java

789 Zeilen
26 KiB
Java

2011-01-05 23:56:31 +01:00
package net.minecraft.server;
import java.util.List;
// CraftBukkit start
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftWorld;
2011-01-05 23:56:31 +01:00
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Vehicle;
2011-01-05 23:56:31 +01:00
import org.bukkit.event.vehicle.*;
// CraftBukkit end
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
public class EntityMinecart extends Entity implements IInventory {
2011-01-05 23:56:31 +01:00
2011-02-23 03:37:56 +01:00
private ItemStack[] h;
2011-01-05 23:56:31 +01:00
public int a;
public int b;
public int c;
2011-02-23 03:37:56 +01:00
private boolean i;
2011-01-05 23:56:31 +01:00
public int d;
public int e;
public double f;
2011-02-23 03:37:56 +01:00
public double g;
private static final int[][][] j = new int[][][] { { { 0, 0, -1}, { 0, 0, 1}}, { { -1, 0, 0}, { 1, 0, 0}}, { { -1, -1, 0}, { 1, 0, 0}}, { { -1, 0, 0}, { 1, -1, 0}}, { { 0, 0, -1}, { 0, -1, 1}}, { { 0, -1, -1}, { 0, 0, 1}}, { { 0, 0, 1}, { 1, 0, 0}}, { { 0, 0, 1}, { -1, 0, 0}}, { { 0, 0, -1}, { -1, 0, 0}}, { { 0, 0, -1}, { 1, 0, 0}}};
private int k;
private double l;
private double m;
private double n;
private double o;
private double p;
// CraftBukkit start
public boolean slowWhenEmpty = true;
public double derailedX = 0.5;
public double derailedY = 0.5;
public double derailedZ = 0.5;
public double flyingX = 0.95;
public double flyingY = 0.95;
public double flyingZ = 0.95;
public double maxSpeed = 0.4D;
2011-01-05 23:56:31 +01:00
public ItemStack[] getContents() {
2011-02-23 03:37:56 +01:00
return this.h;
}
// CraftBukkit end
2011-01-05 23:56:31 +01:00
public EntityMinecart(World world) {
super(world);
2011-02-23 13:56:36 +01:00
this.h = new ItemStack[27]; // CraftBukkit
2011-01-29 22:50:29 +01:00
this.a = 0;
this.b = 0;
this.c = 1;
2011-02-23 03:37:56 +01:00
this.i = false;
this.aC = true;
2011-01-29 22:50:29 +01:00
this.a(0.98F, 0.7F);
this.height = this.width / 2.0F;
2011-02-23 03:37:56 +01:00
this.bg = false;
2011-01-05 23:56:31 +01:00
}
2011-01-14 14:31:10 +01:00
protected void a() {}
2011-02-23 03:37:56 +01:00
public AxisAlignedBB a_(Entity entity) {
2011-01-29 22:50:29 +01:00
return entity.boundingBox;
2011-01-05 23:56:31 +01:00
}
2011-02-23 03:37:56 +01:00
public AxisAlignedBB d() {
2011-01-05 23:56:31 +01:00
return null;
}
2011-02-23 03:37:56 +01:00
public boolean e_() {
2011-01-05 23:56:31 +01:00
return true;
}
2011-01-29 22:50:29 +01:00
public EntityMinecart(World world, double d0, double d1, double d2, int i) {
2011-01-05 23:56:31 +01:00
this(world);
2011-01-29 22:50:29 +01:00
this.a(d0, d1 + (double) this.height, d2);
this.motX = 0.0D;
this.motY = 0.0D;
this.motZ = 0.0D;
this.lastX = d0;
this.lastY = d1;
this.lastZ = d2;
this.d = i;
// CraftBukkit start
CraftServer server = ((WorldServer) this.world).getServer();
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
VehicleCreateEvent event = new VehicleCreateEvent(vehicle);
server.getPluginManager().callEvent(event);
// CraftBukkit end
2011-01-05 23:56:31 +01:00
}
public double k() {
2011-01-29 22:50:29 +01:00
return (double) this.width * 0.0D - 0.30000001192092896D;
2011-01-05 23:56:31 +01:00
}
public boolean a(Entity entity, int i) {
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic && !this.dead) {
// CraftBukkit start
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity passenger = (entity == null) ? null : entity.getBukkitEntity();
int damage = i;
VehicleDamageEvent event = new VehicleDamageEvent(vehicle, passenger, damage);
2011-02-23 13:56:36 +01:00
((WorldServer) this.world).getServer().getPluginManager().callEvent(event);
2011-01-29 22:50:29 +01:00
if (event.isCancelled()) {
return true;
}
2011-02-23 13:56:36 +01:00
2011-01-29 22:50:29 +01:00
i = event.getDamage();
// CraftBukkit end
this.c = -this.c;
this.b = 10;
2011-02-23 03:37:56 +01:00
this.R();
2011-01-29 22:50:29 +01:00
this.a += i * 10;
if (this.a > 40) {
this.a(Item.MINECART.id, 1, 0.0F);
if (this.d == 1) {
this.a(Block.CHEST.id, 1, 0.0F);
} else if (this.d == 2) {
this.a(Block.FURNACE.id, 1, 0.0F);
}
2011-02-23 03:37:56 +01:00
this.C();
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
return true;
} else {
return true;
2011-01-05 23:56:31 +01:00
}
}
2011-02-23 03:37:56 +01:00
public boolean d_() {
2011-01-29 22:50:29 +01:00
return !this.dead;
2011-01-05 23:56:31 +01:00
}
2011-02-23 03:37:56 +01:00
public void C() {
for (int i = 0; i < this.m_(); ++i) {
ItemStack itemstack = this.c_(i);
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (itemstack != null) {
float f = this.random.nextFloat() * 0.8F + 0.1F;
float f1 = this.random.nextFloat() * 0.8F + 0.1F;
float f2 = this.random.nextFloat() * 0.8F + 0.1F;
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
while (itemstack.count > 0) {
int j = this.random.nextInt(21) + 10;
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (j > itemstack.count) {
j = itemstack.count;
}
itemstack.count -= j;
EntityItem entityitem = new EntityItem(this.world, this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, new ItemStack(itemstack.id, j, itemstack.h()));
float f3 = 0.05F;
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
entityitem.motX = (double) ((float) this.random.nextGaussian() * f3);
entityitem.motY = (double) ((float) this.random.nextGaussian() * f3 + 0.2F);
entityitem.motZ = (double) ((float) this.random.nextGaussian() * f3);
this.world.a((Entity) entityitem);
}
}
2011-01-05 23:56:31 +01:00
}
2011-02-23 03:37:56 +01:00
super.C();
2011-01-05 23:56:31 +01:00
}
2011-02-23 03:37:56 +01:00
public void f_() {
// CraftBukkit start
2011-01-29 22:50:29 +01:00
double prevX = this.locX;
double prevY = this.locY;
double prevZ = this.locZ;
float prevYaw = this.yaw;
float prevPitch = this.pitch;
// CraftBukkit end
2011-01-29 22:50:29 +01:00
if (this.b > 0) {
--this.b;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
if (this.a > 0) {
--this.a;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
double d0;
2011-02-23 03:37:56 +01:00
if (this.world.isStatic && this.k > 0) {
if (this.k > 0) {
double d1 = this.locX + (this.l - this.locX) / (double) this.k;
double d2 = this.locY + (this.m - this.locY) / (double) this.k;
double d3 = this.locZ + (this.n - this.locZ) / (double) this.k;
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
for (d0 = this.o - (double) this.yaw; d0 < -180.0D; d0 += 360.0D) {
2011-01-05 23:56:31 +01:00
;
}
2011-01-29 22:50:29 +01:00
while (d0 >= 180.0D) {
d0 -= 360.0D;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
this.yaw = (float) ((double) this.yaw + d0 / (double) this.k);
this.pitch = (float) ((double) this.pitch + (this.p - (double) this.pitch) / (double) this.k);
--this.k;
2011-01-29 22:50:29 +01:00
this.a(d1, d2, d3);
2011-02-23 03:37:56 +01:00
this.c(this.yaw, this.pitch);
2011-01-05 23:56:31 +01:00
} else {
2011-01-29 22:50:29 +01:00
this.a(this.locX, this.locY, this.locZ);
2011-02-23 03:37:56 +01:00
this.c(this.yaw, this.pitch);
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
} else {
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
this.motY -= 0.03999999910593033D;
int i = MathHelper.b(this.locX);
int j = MathHelper.b(this.locY);
int k = MathHelper.b(this.locZ);
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (this.world.getTypeId(i, j - 1, k) == Block.RAILS.id) {
--j;
2011-01-05 23:56:31 +01:00
}
2011-02-23 13:56:36 +01:00
// CraftBukkit
double d4 = this.maxSpeed;
2011-01-29 22:50:29 +01:00
boolean flag = false;
d0 = 0.0078125D;
if (this.world.getTypeId(i, j, k) == Block.RAILS.id) {
Vec3D vec3d = this.g(this.locX, this.locY, this.locZ);
int l = this.world.getData(i, j, k);
this.locY = (double) j;
if (l >= 2 && l <= 5) {
this.locY = (double) (j + 1);
}
if (l == 2) {
this.motX -= d0;
}
if (l == 3) {
this.motX += d0;
}
if (l == 4) {
this.motZ += d0;
}
if (l == 5) {
this.motZ -= d0;
}
2011-02-23 13:56:36 +01:00
// CraftBukkit -- be explicit.
int[][] aint = EntityMinecart.j[l];
2011-01-29 22:50:29 +01:00
double d5 = (double) (aint[1][0] - aint[0][0]);
double d6 = (double) (aint[1][2] - aint[0][2]);
double d7 = Math.sqrt(d5 * d5 + d6 * d6);
double d8 = this.motX * d5 + this.motZ * d6;
if (d8 < 0.0D) {
d5 = -d5;
d6 = -d6;
}
double d9 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
this.motX = d9 * d5 / d7;
this.motZ = d9 * d6 / d7;
double d10 = 0.0D;
double d11 = (double) i + 0.5D + (double) aint[0][0] * 0.5D;
double d12 = (double) k + 0.5D + (double) aint[0][2] * 0.5D;
double d13 = (double) i + 0.5D + (double) aint[1][0] * 0.5D;
double d14 = (double) k + 0.5D + (double) aint[1][2] * 0.5D;
d5 = d13 - d11;
d6 = d14 - d12;
double d15;
double d16;
double d17;
if (d5 == 0.0D) {
this.locX = (double) i + 0.5D;
d10 = this.locZ - (double) k;
} else if (d6 == 0.0D) {
this.locZ = (double) k + 0.5D;
d10 = this.locX - (double) i;
} else {
d15 = this.locX - d11;
d17 = this.locZ - d12;
d16 = (d15 * d5 + d17 * d6) * 2.0D;
d10 = d16;
}
this.locX = d11 + d5 * d10;
this.locZ = d12 + d6 * d10;
this.a(this.locX, this.locY + (double) this.height, this.locZ);
d15 = this.motX;
d17 = this.motZ;
if (this.passenger != null) {
d15 *= 0.75D;
d17 *= 0.75D;
}
if (d15 < -d4) {
d15 = -d4;
}
if (d15 > d4) {
d15 = d4;
}
if (d17 < -d4) {
d17 = -d4;
}
if (d17 > d4) {
d17 = d4;
}
this.c(d15, 0.0D, d17);
if (aint[0][1] != 0 && MathHelper.b(this.locX) - i == aint[0][0] && MathHelper.b(this.locZ) - k == aint[0][2]) {
this.a(this.locX, this.locY + (double) aint[0][1], this.locZ);
} else if (aint[1][1] != 0 && MathHelper.b(this.locX) - i == aint[1][0] && MathHelper.b(this.locZ) - k == aint[1][2]) {
this.a(this.locX, this.locY + (double) aint[1][1], this.locZ);
}
2011-02-23 13:56:36 +01:00
// CraftBukkit
if (this.passenger != null || !slowWhenEmpty) {
2011-01-29 22:50:29 +01:00
this.motX *= 0.996999979019165D;
this.motY *= 0.0D;
this.motZ *= 0.996999979019165D;
} else {
if (this.d == 2) {
2011-02-23 03:37:56 +01:00
d16 = (double) MathHelper.a(this.f * this.f + this.g * this.g);
2011-01-29 22:50:29 +01:00
if (d16 > 0.01D) {
flag = true;
this.f /= d16;
2011-02-23 03:37:56 +01:00
this.g /= d16;
2011-01-29 22:50:29 +01:00
double d18 = 0.04D;
this.motX *= 0.800000011920929D;
this.motY *= 0.0D;
this.motZ *= 0.800000011920929D;
this.motX += this.f * d18;
2011-02-23 03:37:56 +01:00
this.motZ += this.g * d18;
2011-01-29 22:50:29 +01:00
} else {
this.motX *= 0.8999999761581421D;
this.motY *= 0.0D;
this.motZ *= 0.8999999761581421D;
}
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
this.motX *= 0.9599999785423279D;
this.motY *= 0.0D;
this.motZ *= 0.9599999785423279D;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
Vec3D vec3d1 = this.g(this.locX, this.locY, this.locZ);
if (vec3d1 != null && vec3d != null) {
double d19 = (vec3d.b - vec3d1.b) * 0.05D;
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
d9 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
if (d9 > 0.0D) {
this.motX = this.motX / d9 * (d9 + d19);
this.motZ = this.motZ / d9 * (d9 + d19);
}
this.a(this.locX, vec3d1.b, this.locZ);
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
int i1 = MathHelper.b(this.locX);
int j1 = MathHelper.b(this.locZ);
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (i1 != i || j1 != k) {
d9 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
this.motX = d9 * (double) (i1 - i);
this.motZ = d9 * (double) (j1 - k);
}
if (this.d == 2) {
2011-02-23 03:37:56 +01:00
double d20 = (double) MathHelper.a(this.f * this.f + this.g * this.g);
2011-01-29 22:50:29 +01:00
if (d20 > 0.01D && this.motX * this.motX + this.motZ * this.motZ > 0.0010D) {
this.f /= d20;
2011-02-23 03:37:56 +01:00
this.g /= d20;
if (this.f * this.motX + this.g * this.motZ < 0.0D) {
2011-01-29 22:50:29 +01:00
this.f = 0.0D;
2011-02-23 03:37:56 +01:00
this.g = 0.0D;
2011-01-29 22:50:29 +01:00
} else {
this.f = this.motX;
2011-02-23 03:37:56 +01:00
this.g = this.motZ;
2011-01-29 22:50:29 +01:00
}
2011-01-05 23:56:31 +01:00
}
}
2011-01-29 22:50:29 +01:00
} else {
if (this.motX < -d4) {
this.motX = -d4;
}
if (this.motX > d4) {
this.motX = d4;
}
if (this.motZ < -d4) {
this.motZ = -d4;
}
if (this.motZ > d4) {
this.motZ = d4;
}
if (this.onGround) {
// CraftBukkit start
this.motX *= this.derailedX;
this.motY *= this.derailedY;
this.motZ *= this.derailedZ;
// CraftBukkit start
2011-01-29 22:50:29 +01:00
}
this.c(this.motX, this.motY, this.motZ);
if (!this.onGround) {
// CraftBukkit start
this.motX *= flyingX;
this.motY *= flyingY;
this.motZ *= flyingZ;
// CraftBukkit start
2011-01-29 22:50:29 +01:00
}
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
this.pitch = 0.0F;
double d21 = this.lastX - this.locX;
double d22 = this.lastZ - this.locZ;
if (d21 * d21 + d22 * d22 > 0.0010D) {
this.yaw = (float) (Math.atan2(d22, d21) * 180.0D / 3.141592653589793D);
2011-02-23 03:37:56 +01:00
if (this.i) {
2011-01-29 22:50:29 +01:00
this.yaw += 180.0F;
}
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
double d23;
for (d23 = (double) (this.yaw - this.lastYaw); d23 >= 180.0D; d23 -= 360.0D) {
;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
while (d23 < -180.0D) {
d23 += 360.0D;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
if (d23 < -170.0D || d23 >= 170.0D) {
this.yaw += 180.0F;
2011-02-23 03:37:56 +01:00
this.i = !this.i;
2011-01-05 23:56:31 +01:00
}
2011-02-23 03:37:56 +01:00
this.c(this.yaw, this.pitch);
2011-02-01 11:20:18 +01:00
// CraftBukkit start
2011-01-29 22:50:29 +01:00
CraftServer server = ((WorldServer) this.world).getServer();
CraftWorld world = ((WorldServer) this.world).getWorld();
Location from = new Location(world, prevX, prevY, prevZ, prevYaw, prevPitch);
Location to = new Location(world, this.locX, this.locY, this.locZ, this.yaw, this.pitch);
2011-02-01 11:20:18 +01:00
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
2011-02-23 13:56:36 +01:00
server.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle));
2011-02-23 13:56:36 +01:00
2011-02-01 11:14:59 +01:00
if (!from.equals(to)) {
VehicleMoveEvent event = new VehicleMoveEvent(vehicle, from, to);
2011-02-01 11:14:59 +01:00
server.getPluginManager().callEvent(event);
}
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
List list = this.world.b((Entity) this, this.boundingBox.b(0.20000000298023224D, 0.0D, 0.20000000298023224D));
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (list != null && list.size() > 0) {
for (int k1 = 0; k1 < list.size(); ++k1) {
Entity entity = (Entity) list.get(k1);
2011-02-23 03:37:56 +01:00
if (entity != this.passenger && entity.e_() && entity instanceof EntityMinecart) {
entity.h(this);
2011-01-29 22:50:29 +01:00
}
2011-01-05 23:56:31 +01:00
}
}
2011-01-29 22:50:29 +01:00
if (this.passenger != null && this.passenger.dead) {
this.passenger = null;
}
if (flag && this.random.nextInt(4) == 0) {
--this.e;
if (this.e < 0) {
2011-02-23 03:37:56 +01:00
this.f = this.g = 0.0D;
2011-01-29 22:50:29 +01:00
}
this.world.a("largesmoke", this.locX, this.locY + 0.8D, this.locZ, 0.0D, 0.0D, 0.0D);
2011-01-05 23:56:31 +01:00
}
}
}
2011-01-29 22:50:29 +01:00
public Vec3D g(double d0, double d1, double d2) {
int i = MathHelper.b(d0);
int j = MathHelper.b(d1);
int k = MathHelper.b(d2);
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (this.world.getTypeId(i, j - 1, k) == Block.RAILS.id) {
--j;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
if (this.world.getTypeId(i, j, k) == Block.RAILS.id) {
int l = this.world.getData(i, j, k);
d1 = (double) j;
if (l >= 2 && l <= 5) {
d1 = (double) (j + 1);
}
2011-02-23 03:37:56 +01:00
int[][] aint = EntityMinecart.j[l]; // CraftBukkit -- be explicit
2011-01-29 22:50:29 +01:00
double d3 = 0.0D;
double d4 = (double) i + 0.5D + (double) aint[0][0] * 0.5D;
double d5 = (double) j + 0.5D + (double) aint[0][1] * 0.5D;
double d6 = (double) k + 0.5D + (double) aint[0][2] * 0.5D;
double d7 = (double) i + 0.5D + (double) aint[1][0] * 0.5D;
double d8 = (double) j + 0.5D + (double) aint[1][1] * 0.5D;
double d9 = (double) k + 0.5D + (double) aint[1][2] * 0.5D;
double d10 = d7 - d4;
double d11 = (d8 - d5) * 2.0D;
double d12 = d9 - d6;
if (d10 == 0.0D) {
d0 = (double) i + 0.5D;
d3 = d2 - (double) k;
} else if (d12 == 0.0D) {
d2 = (double) k + 0.5D;
d3 = d0 - (double) i;
2011-01-05 23:56:31 +01:00
} else {
2011-01-29 22:50:29 +01:00
double d13 = d0 - d4;
double d14 = d2 - d6;
double d15 = (d13 * d10 + d14 * d12) * 2.0D;
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
d3 = d15;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
d0 = d4 + d10 * d3;
d1 = d5 + d11 * d3;
d2 = d6 + d12 * d3;
if (d11 < 0.0D) {
++d1;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
if (d11 > 0.0D) {
d1 += 0.5D;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
return Vec3D.b(d0, d1, d2);
2011-01-05 23:56:31 +01:00
} else {
return null;
}
}
protected void a(NBTTagCompound nbttagcompound) {
2011-01-29 22:50:29 +01:00
nbttagcompound.a("Type", this.d);
if (this.d == 2) {
nbttagcompound.a("PushX", this.f);
2011-02-23 03:37:56 +01:00
nbttagcompound.a("PushZ", this.g);
2011-01-29 22:50:29 +01:00
nbttagcompound.a("Fuel", (short) this.e);
} else if (this.d == 1) {
2011-01-05 23:56:31 +01:00
NBTTagList nbttaglist = new NBTTagList();
2011-02-23 03:37:56 +01:00
for (int i = 0; i < this.h.length; ++i) {
if (this.h[i] != null) {
2011-01-05 23:56:31 +01:00
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.a("Slot", (byte) i);
2011-02-23 03:37:56 +01:00
this.h[i].a(nbttagcompound1);
2011-01-29 22:50:29 +01:00
nbttaglist.a((NBTBase) nbttagcompound1);
2011-01-05 23:56:31 +01:00
}
}
2011-01-29 22:50:29 +01:00
nbttagcompound.a("Items", (NBTBase) nbttaglist);
2011-01-05 23:56:31 +01:00
}
}
protected void b(NBTTagCompound nbttagcompound) {
2011-02-23 03:37:56 +01:00
this.d = nbttagcompound.e("Type");
2011-01-29 22:50:29 +01:00
if (this.d == 2) {
2011-02-23 03:37:56 +01:00
this.f = nbttagcompound.h("PushX");
this.g = nbttagcompound.h("PushZ");
this.e = nbttagcompound.d("Fuel");
2011-01-29 22:50:29 +01:00
} else if (this.d == 1) {
2011-02-23 03:37:56 +01:00
NBTTagList nbttaglist = nbttagcompound.l("Items");
2011-01-05 23:56:31 +01:00
2011-02-23 03:37:56 +01:00
this.h = new ItemStack[this.m_()];
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
for (int i = 0; i < nbttaglist.c(); ++i) {
2011-01-05 23:56:31 +01:00
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i);
2011-02-23 03:37:56 +01:00
int j = nbttagcompound1.c("Slot") & 255;
2011-01-05 23:56:31 +01:00
2011-02-23 03:37:56 +01:00
if (j >= 0 && j < this.h.length) {
this.h[j] = new ItemStack(nbttagcompound1);
2011-01-05 23:56:31 +01:00
}
}
}
}
2011-02-23 03:37:56 +01:00
public void h(Entity entity) {
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic) {
if (entity != this.passenger) {
// CraftBukkit start
CraftServer server = ((WorldServer) world).getServer();
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity hitEntity = (entity == null) ? null : entity.getBukkitEntity();
VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent(vehicle, hitEntity);
server.getPluginManager().callEvent(collsionEvent);
if (collsionEvent.isCancelled()) {
return;
}
2011-01-29 22:50:29 +01:00
if (entity instanceof EntityLiving && !(entity instanceof EntityHuman) && this.d == 0 && this.motX * this.motX + this.motZ * this.motZ > 0.01D && this.passenger == null && entity.vehicle == null) {
if (!collsionEvent.isPickupCancelled()) {
VehicleEnterEvent enterEvent = new VehicleEnterEvent(vehicle, hitEntity);
server.getPluginManager().callEvent(enterEvent);
if (!enterEvent.isCancelled()) {
2011-02-23 03:37:56 +01:00
entity.b((Entity) this);
}
}
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
double d0 = entity.locX - this.locX;
double d1 = entity.locZ - this.locZ;
double d2 = d0 * d0 + d1 * d1;
2011-01-05 23:56:31 +01:00
// CraftBukkit - Collision
if (d2 >= 9.9999997473787516E-005D && !collsionEvent.isCollisionCancelled()) {
2011-01-29 22:50:29 +01:00
d2 = (double) MathHelper.a(d2);
d0 /= d2;
d1 /= d2;
double d3 = 1.0D / d2;
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (d3 > 1.0D) {
d3 = 1.0D;
}
d0 *= d3;
d1 *= d3;
d0 *= 0.10000000149011612D;
d1 *= 0.10000000149011612D;
2011-02-23 03:37:56 +01:00
d0 *= (double) (1.0F - this.bo);
d1 *= (double) (1.0F - this.bo);
2011-01-29 22:50:29 +01:00
d0 *= 0.5D;
d1 *= 0.5D;
if (entity instanceof EntityMinecart) {
double d4 = entity.motX + this.motX;
double d5 = entity.motZ + this.motZ;
if (((EntityMinecart) entity).d == 2 && this.d != 2) {
this.motX *= 0.20000000298023224D;
this.motZ *= 0.20000000298023224D;
this.f(entity.motX - d0, 0.0D, entity.motZ - d1);
entity.motX *= 0.699999988079071D;
entity.motZ *= 0.699999988079071D;
} else if (((EntityMinecart) entity).d != 2 && this.d == 2) {
entity.motX *= 0.20000000298023224D;
entity.motZ *= 0.20000000298023224D;
entity.f(this.motX + d0, 0.0D, this.motZ + d1);
this.motX *= 0.699999988079071D;
this.motZ *= 0.699999988079071D;
} else {
d4 /= 2.0D;
d5 /= 2.0D;
this.motX *= 0.20000000298023224D;
this.motZ *= 0.20000000298023224D;
this.f(d4 - d0, 0.0D, d5 - d1);
entity.motX *= 0.20000000298023224D;
entity.motZ *= 0.20000000298023224D;
entity.f(d4 + d0, 0.0D, d5 + d1);
}
} else {
this.f(-d0, 0.0D, -d1);
entity.f(d0 / 4.0D, 0.0D, d1 / 4.0D);
}
2011-01-05 23:56:31 +01:00
}
}
}
}
2011-02-23 03:37:56 +01:00
public int m_() {
2011-01-05 23:56:31 +01:00
return 27;
}
2011-02-23 03:37:56 +01:00
public ItemStack c_(int i) {
return this.h[i];
2011-01-05 23:56:31 +01:00
}
2011-02-23 03:37:56 +01:00
public ItemStack a(int i, int j) {
if (this.h[i] != null) {
2011-01-29 22:50:29 +01:00
ItemStack itemstack;
2011-01-05 23:56:31 +01:00
2011-02-23 03:37:56 +01:00
if (this.h[i].count <= j) {
itemstack = this.h[i];
this.h[i] = null;
2011-01-05 23:56:31 +01:00
return itemstack;
2011-01-29 22:50:29 +01:00
} else {
2011-02-23 03:37:56 +01:00
itemstack = this.h[i].a(j);
if (this.h[i].count == 0) {
this.h[i] = null;
2011-01-29 22:50:29 +01:00
}
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
return itemstack;
2011-01-05 23:56:31 +01:00
}
} else {
return null;
}
}
public void a(int i, ItemStack itemstack) {
2011-02-23 03:37:56 +01:00
this.h[i] = itemstack;
if (itemstack != null && itemstack.count > this.n_()) {
itemstack.count = this.n_();
2011-01-05 23:56:31 +01:00
}
}
2011-02-23 03:37:56 +01:00
public String c() {
2011-01-05 23:56:31 +01:00
return "Minecart";
}
2011-02-23 03:37:56 +01:00
public int n_() {
2011-01-05 23:56:31 +01:00
return 64;
}
2011-02-23 03:37:56 +01:00
public void h() {}
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
public boolean a(EntityHuman entityhuman) {
if (this.d == 0) {
if (this.passenger != null && this.passenger instanceof EntityHuman && this.passenger != entityhuman) {
2011-01-05 23:56:31 +01:00
return true;
}
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic) {
// CraftBukkit start
2011-01-29 22:50:29 +01:00
CraftServer server = ((WorldServer) this.world).getServer();
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
2011-01-29 22:50:29 +01:00
org.bukkit.entity.Entity player = (entityhuman == null) ? null : entityhuman.getBukkitEntity();
VehicleEnterEvent event = new VehicleEnterEvent(vehicle, player);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
// CraftBukkit end
2011-02-23 03:37:56 +01:00
entityhuman.b((Entity) this);
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
} else if (this.d == 1) {
if (!this.world.isStatic) {
entityhuman.a((IInventory) this);
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
} else if (this.d == 2) {
2011-02-23 03:37:56 +01:00
ItemStack itemstack = entityhuman.inventory.b();
2011-01-05 23:56:31 +01:00
2011-01-29 22:50:29 +01:00
if (itemstack != null && itemstack.id == Item.COAL.id) {
if (--itemstack.count == 0) {
entityhuman.inventory.a(entityhuman.inventory.c, (ItemStack) null);
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
this.e += 1200;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
this.f = this.locX - entityhuman.locX;
2011-02-23 03:37:56 +01:00
this.g = this.locZ - entityhuman.locZ;
2011-01-05 23:56:31 +01:00
}
2011-01-29 22:50:29 +01:00
2011-01-05 23:56:31 +01:00
return true;
}
2011-01-29 22:50:29 +01:00
public boolean a_(EntityHuman entityhuman) {
2011-02-23 03:37:56 +01:00
return this.dead ? false : entityhuman.g(this) <= 64.0D;
2011-01-05 23:56:31 +01:00
}
}