2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
|
|
|
|
+++ b/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
|
2023-04-19 11:59:19 +02:00
|
|
|
@@ -47,6 +47,16 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.AxisAlignedBB;
|
|
|
|
import net.minecraft.world.phys.Vec3D;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.Location;
|
2023-04-19 11:59:19 +02:00
|
|
|
+import org.bukkit.craftbukkit.util.CraftLocation;
|
2014-11-25 22:32:16 +01:00
|
|
|
+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
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private static final DataWatcherObject<Integer> DATA_ID_HURT = DataWatcher.defineId(EntityMinecartAbstract.class, DataWatcherRegistry.INT);
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -90,6 +100,17 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
private double lyd;
|
|
|
|
private double lzd;
|
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);
|
2021-06-11 07:00:00 +02:00
|
|
|
this.blocksBuilding = true;
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -216,6 +237,19 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
if (this.isInvulnerableTo(damagesource)) {
|
2014-11-25 22:32:16 +01:00
|
|
|
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);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(event);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ 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
|
2021-11-21 23:00:00 +01:00
|
|
|
this.setHurtDir(-this.getHurtDir());
|
|
|
|
this.setHurtTime(10);
|
|
|
|
this.markHurt();
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -224,6 +258,15 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).getAbilities().instabuild;
|
2015-04-13 13:01:55 +02:00
|
|
|
|
|
|
|
if (flag || this.getDamage() > 40.0F) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(destroyEvent);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ 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()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.discard();
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -285,6 +328,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
|
2021-11-21 23:00:00 +01:00
|
|
|
+ double prevX = this.getX();
|
|
|
|
+ double prevY = this.getY();
|
|
|
|
+ double prevZ = this.getZ();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ float prevYaw = this.getYRot();
|
|
|
|
+ float prevPitch = this.getXRot();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
if (this.getHurtTime() > 0) {
|
|
|
|
this.setHurtTime(this.getHurtTime() - 1);
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -294,7 +345,7 @@
|
2018-02-09 08:02:53 +01:00
|
|
|
}
|
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
this.checkBelowWorld();
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.handleNetherPortal();
|
|
|
|
+ // this.handleNetherPortal(); // CraftBukkit - handled in postTick
|
2021-06-11 07:00:00 +02:00
|
|
|
double d0;
|
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
if (this.level().isClientSide) {
|
|
|
|
@@ -361,6 +412,18 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.setRot(this.getYRot(), this.getXRot());
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2023-06-07 17:30:00 +02:00
|
|
|
+ org.bukkit.World bworld = this.level().getWorld();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
|
2023-04-19 11:59:19 +02:00
|
|
|
+ Location to = CraftLocation.toBukkit(this.position(), bworld, this.getYRot(), this.getXRot());
|
2014-11-25 22:32:16 +01:00
|
|
|
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
|
|
|
|
+
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (!from.equals(to)) {
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
if (this.getMinecartType() == EntityMinecartAbstract.EnumMinecartType.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
|
2023-06-07 17:30:00 +02:00
|
|
|
List<Entity> list = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), IEntitySelector.pushableBy(this));
|
2016-06-09 03:43:49 +02:00
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -369,8 +432,26 @@
|
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());
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent);
|
2016-06-09 03:43:49 +02:00
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
entity.startRiding(this);
|
|
|
|
} else {
|
2016-06-12 02:45:03 +02:00
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ if (!this.isPassengerOfSameVehicle(entity)) {
|
2020-01-24 06:48:48 +01:00
|
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity());
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent);
|
2016-06-12 02:45:03 +02:00
|
|
|
+
|
2020-01-24 06:48:48 +01:00
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
2016-06-12 02:45:03 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
entity.push(this);
|
2016-06-12 02:45:03 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -382,6 +463,14 @@
|
2016-06-12 02:45:03 +02:00
|
|
|
Entity entity1 = (Entity) iterator.next();
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
if (!this.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof EntityMinecartAbstract) {
|
2016-06-12 02:45:03 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity());
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent);
|
2016-06-12 02:45:03 +02:00
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
entity1.push(this);
|
2016-06-12 02:45:03 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -398,7 +487,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
protected double getMaxSpeed() {
|
2021-06-11 07:00:00 +02:00
|
|
|
- return (this.isInWater() ? 4.0D : 8.0D) / 20.0D;
|
|
|
|
+ return (this.isInWater() ? this.maxSpeed / 2.0D: this.maxSpeed); // CraftBukkit
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
public void activateMinecart(int i, int j, int k, boolean flag) {}
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -409,12 +498,16 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.setDeltaMovement(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0));
|
2023-06-07 17:30:00 +02:00
|
|
|
if (this.onGround()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.setDeltaMovement(this.getDeltaMovement().scale(0.5D));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - replace magic numbers with our variables
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.setDeltaMovement(new Vec3D(this.getDeltaMovement().x * this.derailedX, this.getDeltaMovement().y * this.derailedY, this.getDeltaMovement().z * this.derailedZ));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.move(EnumMoveType.SELF, this.getDeltaMovement());
|
2023-06-07 17:30:00 +02:00
|
|
|
if (!this.onGround()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.setDeltaMovement(this.getDeltaMovement().scale(0.95D));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - replace magic numbers with our variables
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.setDeltaMovement(new Vec3D(this.getDeltaMovement().x * this.flyingX, this.getDeltaMovement().y * this.flyingY, this.getDeltaMovement().z * this.flyingZ));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -610,7 +703,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
protected void applyNaturalSlowdown() {
|
2019-04-23 04:00:00 +02:00
|
|
|
- double d0 = this.isVehicle() ? 0.997D : 0.96D;
|
|
|
|
+ double d0 = this.isVehicle() || !this.slowWhenEmpty ? 0.997D : 0.96D; // CraftBukkit - add !this.slowWhenEmpty
|
2021-11-21 23:00:00 +01:00
|
|
|
Vec3D vec3d = this.getDeltaMovement();
|
2019-04-23 04:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
vec3d = vec3d.multiply(d0, 0.0D, d0);
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -749,6 +842,14 @@
|
|
|
|
if (!this.level().isClientSide) {
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!entity.noPhysics && !this.noPhysics) {
|
2021-11-21 23:00:00 +01:00
|
|
|
if (!this.hasPassenger(entity)) {
|
2018-04-02 04:55:28 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent);
|
2018-04-02 04:55:28 +02:00
|
|
|
+
|
|
|
|
+ if (collisionEvent.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
double d0 = entity.getX() - this.getX();
|
|
|
|
double d1 = entity.getZ() - this.getZ();
|
2018-04-02 04:55:28 +02:00
|
|
|
double d2 = d0 * d0 + d1 * d1;
|
2023-06-07 17:30:00 +02:00
|
|
|
@@ -923,4 +1024,26 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|