2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/EntityMinecartAbstract.java
|
|
|
|
+++ b/net/minecraft/server/EntityMinecartAbstract.java
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -4,6 +4,15 @@
|
2018-12-25 22:00:00 +01:00
|
|
|
import java.util.List;
|
2016-05-10 13:47:39 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// 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
|
|
|
|
+
|
2019-04-23 04:00:00 +02:00
|
|
|
public abstract class EntityMinecartAbstract extends Entity {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
private static final DataWatcherObject<Integer> b = DataWatcher.a(EntityMinecartAbstract.class, DataWatcherRegistry.b);
|
|
|
|
@@ -21,6 +30,17 @@
|
|
|
|
private double ax;
|
|
|
|
private double ay;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // 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
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2018-07-15 02:00:00 +02:00
|
|
|
protected EntityMinecartAbstract(EntityTypes<?> entitytypes, World world) {
|
|
|
|
super(entitytypes, world);
|
2019-04-23 04:00:00 +02:00
|
|
|
this.i = true;
|
|
|
|
@@ -76,6 +96,19 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
if (this.isInvulnerable(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.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
+
|
|
|
|
+ if (event.isCancelled()) {
|
2019-03-05 06:42:23 +01:00
|
|
|
+ return false;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ f = (float) event.getDamage();
|
|
|
|
+ // CraftBukkit end
|
2019-04-23 04:00:00 +02:00
|
|
|
this.d(-this.n());
|
|
|
|
this.c(10);
|
|
|
|
this.velocityChanged();
|
|
|
|
@@ -83,6 +116,15 @@
|
2015-04-13 13:01:55 +02:00
|
|
|
boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild;
|
|
|
|
|
|
|
|
if (flag || this.getDamage() > 40.0F) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger);
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(destroyEvent);
|
|
|
|
+
|
|
|
|
+ if (destroyEvent.isCancelled()) {
|
|
|
|
+ this.setDamage(40); // Maximize damage so this doesn't get triggered again right away
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2017-05-30 13:25:59 +02:00
|
|
|
this.ejectPassengers();
|
2016-02-29 22:32:46 +01:00
|
|
|
if (flag && !this.hasCustomName()) {
|
|
|
|
this.die();
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -124,6 +166,14 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2018-07-15 02:00:00 +02:00
|
|
|
public void tick() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ double prevX = this.locX;
|
|
|
|
+ double prevY = this.locY;
|
|
|
|
+ double prevZ = this.locZ;
|
|
|
|
+ float prevYaw = this.yaw;
|
|
|
|
+ float prevPitch = this.pitch;
|
|
|
|
+ // CraftBukkit end
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
if (this.getType() > 0) {
|
2019-04-23 04:00:00 +02:00
|
|
|
this.c(this.getType() - 1);
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -136,7 +186,7 @@
|
|
|
|
this.ae();
|
2018-02-09 08:02:53 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
- this.doPortalTick();
|
|
|
|
+ // this.doPortalTick(); // CraftBukkit - handled in postTick
|
2018-02-09 08:02:53 +01:00
|
|
|
if (this.world.isClientSide) {
|
2019-04-23 04:00:00 +02:00
|
|
|
if (this.at > 0) {
|
|
|
|
double d0 = this.locX + (this.au - this.locX) / (double) this.at;
|
|
|
|
@@ -202,6 +252,18 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setYawPitch(this.yaw, this.pitch);
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ org.bukkit.World bworld = this.world.getWorld();
|
|
|
|
+ Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
|
|
|
|
+ Location to = new Location(bworld, this.locX, this.locY, this.locZ, this.yaw, this.pitch);
|
|
|
|
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
|
|
|
|
+
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
|
|
|
|
+
|
|
|
|
+ if (!from.equals(to)) {
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to));
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2019-04-23 04:00:00 +02:00
|
|
|
if (this.getMinecartType() == EntityMinecartAbstract.EnumMinecartType.RIDEABLE && b(this.getMot()) > 0.01D) {
|
2018-12-25 22:00:00 +01:00
|
|
|
List<Entity> list = this.world.getEntities(this, this.getBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D), IEntitySelector.a(this));
|
2016-06-09 03:43:49 +02:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -210,8 +272,24 @@
|
2016-06-09 03:43:49 +02:00
|
|
|
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.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
entity.startRiding(this);
|
|
|
|
} else {
|
2016-06-12 02:45:03 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity());
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2016-06-09 03:43:49 +02:00
|
|
|
entity.collide(this);
|
2016-06-12 02:45:03 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -223,6 +301,14 @@
|
2016-06-12 02:45:03 +02:00
|
|
|
Entity entity1 = (Entity) iterator.next();
|
|
|
|
|
|
|
|
if (!this.w(entity1) && entity1.isCollidable() && entity1 instanceof EntityMinecartAbstract) {
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity());
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
entity1.collide(this);
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -233,7 +319,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
protected double getMaxSpeed() {
|
2014-11-25 22:32:16 +01:00
|
|
|
- return 0.4D;
|
|
|
|
+ return this.maxSpeed; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(int i, int j, int k, boolean flag) {}
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -244,12 +330,16 @@
|
|
|
|
|
|
|
|
this.setMot(MathHelper.a(vec3d.x, -d0, d0), vec3d.y, MathHelper.a(vec3d.z, -d0, d0));
|
2014-11-25 22:32:16 +01:00
|
|
|
if (this.onGround) {
|
2019-04-23 04:00:00 +02:00
|
|
|
- this.setMot(this.getMot().a(0.5D));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - replace magic numbers with our variables
|
2019-04-23 04:00:00 +02:00
|
|
|
+ this.setMot(new Vec3D(this.getMot().x * this.derailedX, this.getMot().y * this.derailedY, this.getMot().z * this.derailedZ));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
this.move(EnumMoveType.SELF, this.getMot());
|
2014-11-25 22:32:16 +01:00
|
|
|
if (!this.onGround) {
|
2019-04-23 04:00:00 +02:00
|
|
|
- this.setMot(this.getMot().a(0.95D));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - replace magic numbers with our variables
|
2019-04-23 04:00:00 +02:00
|
|
|
+ this.setMot(new Vec3D(this.getMot().x * this.flyingX, this.getMot().y * this.flyingY, this.getMot().z * this.flyingZ));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -433,7 +523,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
protected void decelerate() {
|
|
|
|
- double d0 = this.isVehicle() ? 0.997D : 0.96D;
|
|
|
|
+ double d0 = this.isVehicle() || !this.slowWhenEmpty ? 0.997D : 0.96D; // CraftBukkit - add !this.slowWhenEmpty
|
|
|
|
|
|
|
|
this.setMot(this.getMot().d(d0, 0.0D, d0));
|
|
|
|
}
|
|
|
|
@@ -516,6 +606,14 @@
|
2018-04-02 04:55:28 +02:00
|
|
|
if (!this.world.isClientSide) {
|
|
|
|
if (!entity.noclip && !this.noclip) {
|
|
|
|
if (!this.w(entity)) {
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
double d0 = entity.locX - this.locX;
|
|
|
|
double d1 = entity.locZ - this.locZ;
|
|
|
|
double d2 = d0 * d0 + d1 * d1;
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -651,4 +749,26 @@
|
|
|
|
|
|
|
|
private EnumMinecartType() {}
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // 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
|
|
|
|
}
|