--- a/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java +++ b/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java @@ -48,6 +48,15 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start +import org.bukkit.Location; +import org.bukkit.entity.Vehicle; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; +import org.bukkit.util.Vector; +// CraftBukkit end + public abstract class EntityMinecartAbstract extends Entity { private static final DataWatcherObject DATA_ID_HURT = DataWatcher.defineId(EntityMinecartAbstract.class, DataWatcherRegistry.INT); @@ -90,6 +99,17 @@ private double lyd; private double lzd; + // CraftBukkit start + public boolean slowWhenEmpty = true; + private double derailedX = 0.5; + private double derailedY = 0.5; + private double derailedZ = 0.5; + private double flyingX = 0.95; + private double flyingY = 0.95; + private double flyingZ = 0.95; + public double maxSpeed = 0.4D; + // CraftBukkit end + protected EntityMinecartAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); this.blocksBuilding = true; @@ -216,6 +236,19 @@ if (this.isInvulnerableTo(damagesource)) { return false; } else { + // CraftBukkit start - fire VehicleDamageEvent + Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + org.bukkit.entity.Entity passenger = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity(); + + VehicleDamageEvent event = new VehicleDamageEvent(vehicle, passenger, f); + this.level.getCraftServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return false; + } + + f = (float) event.getDamage(); + // CraftBukkit end this.setHurtDir(-this.getHurtDir()); this.setHurtTime(10); this.markHurt(); @@ -224,6 +257,15 @@ boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).getAbilities().instabuild; if (flag || this.getDamage() > 40.0F) { + // CraftBukkit start + VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger); + this.level.getCraftServer().getPluginManager().callEvent(destroyEvent); + + if (destroyEvent.isCancelled()) { + this.setDamage(40); // Maximize damage so this doesn't get triggered again right away + return true; + } + // CraftBukkit end this.ejectPassengers(); if (flag && !this.hasCustomName()) { this.discard(); @@ -285,6 +327,14 @@ @Override public void tick() { + // CraftBukkit start + double prevX = this.getX(); + double prevY = this.getY(); + double prevZ = this.getZ(); + float prevYaw = this.getYRot(); + float prevPitch = this.getXRot(); + // CraftBukkit end + if (this.getHurtTime() > 0) { this.setHurtTime(this.getHurtTime() - 1); } @@ -294,7 +344,7 @@ } this.checkOutOfWorld(); - this.handleNetherPortal(); + // this.handleNetherPortal(); // CraftBukkit - handled in postTick double d0; if (this.level.isClientSide) { @@ -360,6 +410,18 @@ } this.setRot(this.getYRot(), this.getXRot()); + // CraftBukkit start + org.bukkit.World bworld = this.level.getWorld(); + Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch); + Location to = new Location(bworld, this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); + Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + + this.level.getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle)); + + if (!from.equals(to)) { + this.level.getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to)); + } + // CraftBukkit end if (this.getMinecartType() == EntityMinecartAbstract.EnumMinecartType.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) { List list = this.level.getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), IEntitySelector.pushableBy(this)); @@ -368,8 +430,26 @@ Entity entity = (Entity) list.get(l); if (!(entity instanceof EntityHuman) && !(entity instanceof EntityIronGolem) && !(entity instanceof EntityMinecartAbstract) && !this.isVehicle() && !entity.isPassenger()) { + // CraftBukkit start + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity()); + this.level.getCraftServer().getPluginManager().callEvent(collisionEvent); + + if (collisionEvent.isCancelled()) { + continue; + } + // CraftBukkit end entity.startRiding(this); } else { + // CraftBukkit start + if (!this.isPassengerOfSameVehicle(entity)) { + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity()); + this.level.getCraftServer().getPluginManager().callEvent(collisionEvent); + + if (collisionEvent.isCancelled()) { + continue; + } + } + // CraftBukkit end entity.push(this); } } @@ -381,6 +461,14 @@ Entity entity1 = (Entity) iterator.next(); if (!this.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof EntityMinecartAbstract) { + // CraftBukkit start + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity()); + this.level.getCraftServer().getPluginManager().callEvent(collisionEvent); + + if (collisionEvent.isCancelled()) { + continue; + } + // CraftBukkit end entity1.push(this); } } @@ -397,7 +485,7 @@ } protected double getMaxSpeed() { - return (this.isInWater() ? 4.0D : 8.0D) / 20.0D; + return (this.isInWater() ? this.maxSpeed / 2.0D: this.maxSpeed); // CraftBukkit } public void activateMinecart(int i, int j, int k, boolean flag) {} @@ -408,12 +496,16 @@ this.setDeltaMovement(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0)); if (this.onGround) { - this.setDeltaMovement(this.getDeltaMovement().scale(0.5D)); + // CraftBukkit start - replace magic numbers with our variables + this.setDeltaMovement(new Vec3D(this.getDeltaMovement().x * this.derailedX, this.getDeltaMovement().y * this.derailedY, this.getDeltaMovement().z * this.derailedZ)); + // CraftBukkit end } this.move(EnumMoveType.SELF, this.getDeltaMovement()); if (!this.onGround) { - this.setDeltaMovement(this.getDeltaMovement().scale(0.95D)); + // CraftBukkit start - replace magic numbers with our variables + this.setDeltaMovement(new Vec3D(this.getDeltaMovement().x * this.flyingX, this.getDeltaMovement().y * this.flyingY, this.getDeltaMovement().z * this.flyingZ)); + // CraftBukkit end } } @@ -604,7 +696,7 @@ } protected void applyNaturalSlowdown() { - double d0 = this.isVehicle() ? 0.997D : 0.96D; + double d0 = this.isVehicle() || !this.slowWhenEmpty ? 0.997D : 0.96D; // CraftBukkit - add !this.slowWhenEmpty Vec3D vec3d = this.getDeltaMovement(); vec3d = vec3d.multiply(d0, 0.0D, d0); @@ -743,6 +835,14 @@ if (!this.level.isClientSide) { if (!entity.noPhysics && !this.noPhysics) { if (!this.hasPassenger(entity)) { + // CraftBukkit start + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity()); + this.level.getCraftServer().getPluginManager().callEvent(collisionEvent); + + if (collisionEvent.isCancelled()) { + return; + } + // CraftBukkit end double d0 = entity.getX() - this.getX(); double d1 = entity.getZ() - this.getZ(); double d2 = d0 * d0 + d1 * d1; @@ -922,4 +1022,26 @@ private EnumMinecartType() {} } + + // CraftBukkit start - Methods for getting and setting flying and derailed velocity modifiers + public Vector getFlyingVelocityMod() { + return new Vector(flyingX, flyingY, flyingZ); + } + + public void setFlyingVelocityMod(Vector flying) { + flyingX = flying.getX(); + flyingY = flying.getY(); + flyingZ = flying.getZ(); + } + + public Vector getDerailedVelocityMod() { + return new Vector(derailedX, derailedY, derailedZ); + } + + public void setDerailedVelocityMod(Vector derailed) { + derailedX = derailed.getX(); + derailedY = derailed.getY(); + derailedZ = derailed.getZ(); + } + // CraftBukkit end }