craftbukkit/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch

151 lines
6.3 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/entity/vehicle/EntityBoat.java
+++ b/net/minecraft/world/entity/vehicle/EntityBoat.java
2022-03-01 02:00:00 +11:00
@@ -51,6 +51,15 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// 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.event.vehicle.VehicleMoveEvent;
+// CraftBukkit end
+
public class EntityBoat extends Entity {
2021-11-22 09:00:00 +11:00
private static final DataWatcherObject<Integer> DATA_ID_HURT = DataWatcher.defineId(EntityBoat.class, DataWatcherRegistry.INT);
2022-03-01 02:00:00 +11:00
@@ -91,6 +100,14 @@
2021-06-11 15:00:00 +10:00
private float bubbleAngle;
private float bubbleAngleO;
2015-02-26 22:41:06 +00:00
+ // CraftBukkit start
2016-03-01 08:32:46 +11:00
+ // PAIL: Some of these haven't worked since a few updates, and since 1.9 they are less and less applicable.
+ public double maxSpeed = 0.4D;
+ public double occupiedDeceleration = 0.2D;
+ public double unoccupiedDeceleration = -1;
+ public boolean landBoats = false;
+ // CraftBukkit end
2015-02-26 22:41:06 +00:00
+
2019-04-23 12:00:00 +10:00
public EntityBoat(EntityTypes<? extends EntityBoat> entitytypes, World world) {
super(entitytypes, world);
2021-06-11 15:00:00 +10:00
this.paddlePositions = new float[2];
2022-03-01 02:00:00 +11:00
@@ -160,6 +177,19 @@
2021-11-22 09:00:00 +11:00
if (this.isInvulnerableTo(damagesource)) {
2020-06-25 10:00:00 +10:00
return false;
2021-06-11 15:00:00 +10:00
} else if (!this.level.isClientSide && !this.isRemoved()) {
2020-06-25 10:00:00 +10:00
+ // CraftBukkit start
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+ org.bukkit.entity.Entity attacker = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity();
+
2020-06-25 10:00:00 +10:00
+ VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, (double) f);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+
2020-06-25 10:00:00 +10:00
+ if (event.isCancelled()) {
+ return false;
+ }
+ // f = event.getDamage(); // TODO Why don't we do this?
+ // CraftBukkit end
2015-02-26 22:41:06 +00:00
+
2021-11-22 09:00:00 +11:00
this.setHurtDir(-this.getHurtDir());
this.setHurtTime(10);
2020-06-25 10:00:00 +10:00
this.setDamage(this.getDamage() + f * 10.0F);
2022-03-01 02:00:00 +11:00
@@ -168,6 +198,15 @@
2021-06-11 15:00:00 +10:00
boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).getAbilities().instabuild;
2020-06-25 10:00:00 +10:00
if (flag || this.getDamage() > 40.0F) {
+ // CraftBukkit start
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker);
+ this.level.getCraftServer().getPluginManager().callEvent(destroyEvent);
+
2020-06-25 10:00:00 +10:00
+ if (destroyEvent.isCancelled()) {
+ this.setDamage(40F); // Maximize damage so this doesn't get triggered again right away
+ return true;
+ }
+ // CraftBukkit end
2021-06-11 15:00:00 +10:00
if (!flag && this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
2022-06-08 02:00:00 +10:00
this.destroy(damagesource);
2020-06-25 10:00:00 +10:00
}
2022-06-08 02:00:00 +10:00
@@ -207,9 +246,29 @@
2021-11-22 09:00:00 +11:00
public void push(Entity entity) {
2016-03-01 08:32:46 +11:00
if (entity instanceof EntityBoat) {
2018-10-23 06:00:00 +11:00
if (entity.getBoundingBox().minY < this.getBoundingBox().maxY) {
2016-03-01 08:32:46 +11:00
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ if (!this.isPassengerOfSameVehicle(entity)) {
+ VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+ this.level.getCraftServer().getPluginManager().callEvent(event);
2016-03-01 08:32:46 +11:00
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
2016-03-01 08:32:46 +11:00
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
super.push(entity);
2016-03-01 08:32:46 +11:00
}
2018-10-23 06:00:00 +11:00
} else if (entity.getBoundingBox().minY <= this.getBoundingBox().minY) {
2016-03-01 08:32:46 +11:00
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ if (!this.isPassengerOfSameVehicle(entity)) {
+ VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+ this.level.getCraftServer().getPluginManager().callEvent(event);
2016-03-01 08:32:46 +11:00
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
super.push(entity);
2016-03-01 08:32:46 +11:00
}
2022-06-08 02:00:00 +10:00
@@ -262,6 +321,7 @@
2021-11-22 09:00:00 +11:00
return this.getDirection().getClockWise();
}
+ private Location lastLocation; // CraftBukkit
2019-04-23 12:00:00 +10:00
@Override
2018-07-15 10:00:00 +10:00
public void tick() {
2021-06-11 15:00:00 +10:00
this.oldStatus = this.status;
2022-06-08 02:00:00 +10:00
@@ -302,6 +362,22 @@
2021-11-22 09:00:00 +11:00
this.setDeltaMovement(Vec3D.ZERO);
}
+ // CraftBukkit start
+ org.bukkit.Server server = this.level.getCraftServer();
2021-06-11 15:00:00 +10:00
+ org.bukkit.World bworld = this.level.getWorld();
+
2021-11-22 09:00:00 +11:00
+ Location to = new Location(bworld, this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+
+ server.getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
+
+ if (lastLocation != null && !lastLocation.equals(to)) {
+ VehicleMoveEvent event = new VehicleMoveEvent(vehicle, lastLocation, to);
+ server.getPluginManager().callEvent(event);
+ }
+ lastLocation = vehicle.getLocation();
+ // CraftBukkit end
+
2021-11-22 09:00:00 +11:00
this.tickBubbleColumn();
2018-07-15 10:00:00 +10:00
for (int i = 0; i <= 1; ++i) {
2022-06-08 02:00:00 +10:00
@@ -809,6 +885,11 @@
2021-11-22 09:00:00 +11:00
this.causeFallDamage(this.fallDistance, 1.0F, DamageSource.FALL);
2021-06-11 15:00:00 +10:00
if (!this.level.isClientSide && !this.isRemoved()) {
+ // CraftBukkit start
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, null);
+ this.level.getCraftServer().getPluginManager().callEvent(destroyEvent);
+ if (!destroyEvent.isCancelled()) {
2021-11-22 09:00:00 +11:00
this.kill();
2021-06-11 15:00:00 +10:00
if (this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
2016-03-01 08:32:46 +11:00
int i;
2022-06-08 02:00:00 +10:00
@@ -822,6 +903,7 @@
2016-03-01 08:32:46 +11:00
}
2015-02-26 22:41:06 +00:00
}
}
2015-02-26 22:41:06 +00:00
+ } // CraftBukkit end
}
2021-11-22 09:00:00 +11:00
this.resetFallDistance();