PaperMC/nms-patches/EntityBoat.patch

158 lines
6.4 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityBoat.java
+++ b/net/minecraft/server/EntityBoat.java
2016-02-29 22:32:46 +01:00
@@ -4,6 +4,15 @@
import java.util.ArrayList;
import java.util.List;
+// 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 {
2016-02-29 22:32:46 +01:00
private static final DataWatcherObject<Integer> a = DataWatcher.a(EntityBoat.class, DataWatcherRegistry.b);
@@ -31,6 +40,14 @@
private EntityBoat.EnumStatus aG;
private double aH;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2016-02-29 22:32:46 +01: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 23:41:06 +01:00
+
public EntityBoat(World world) {
super(world);
2016-02-29 22:32:46 +01:00
this.f = new float[2];
@@ -47,6 +64,7 @@
this.lastX = d0;
this.lastY = d1;
this.lastZ = d2;
+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleCreateEvent((Vehicle) this.getBukkitEntity())); // CraftBukkit
}
2016-02-29 22:32:46 +01:00
protected boolean playStepSound() {
@@ -88,6 +106,19 @@
if (damagesource instanceof EntityDamageSourceIndirect && damagesource.getEntity() != null && this.w(damagesource.getEntity())) {
return false;
} else {
+ // CraftBukkit start
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+ org.bukkit.entity.Entity attacker = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity();
+
+ VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, (double) f);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return true;
+ }
+ // f = event.getDamage(); // TODO Why don't we do this?
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
this.d(-this.q());
this.b(10);
this.setDamage(this.n() + f * 10.0F);
@@ -95,6 +126,15 @@
boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild;
2016-02-29 22:32:46 +01:00
if (flag || this.n() > 40.0F) {
+ // CraftBukkit start
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker);
+ this.world.getServer().getPluginManager().callEvent(destroyEvent);
+
+ if (destroyEvent.isCancelled()) {
+ this.setDamage(40F); // Maximize damage so this doesn't get triggered again right away
+ return true;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
if (!flag && this.world.getGameRules().getBoolean("doEntityDrops")) {
this.a(this.j(), 1, 0.0F);
}
2016-02-29 22:32:46 +01:00
@@ -112,9 +152,25 @@
public void collide(Entity entity) {
if (entity instanceof EntityBoat) {
if (entity.getBoundingBox().b < this.getBoundingBox().e) {
+ // CraftBukkit start
+ VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
super.collide(entity);
}
} else if (entity.getBoundingBox().b <= this.getBoundingBox().b) {
+ // CraftBukkit start
+ VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
super.collide(entity);
}
2016-02-29 22:32:46 +01:00
@@ -172,6 +228,10 @@
this.setDamage(this.n() - 1.0F);
}
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
+ float prevYaw = this.yaw;
+ float prevPitch = this.pitch;
+ // CraftBukkit end
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
@@ -189,6 +249,22 @@
}
this.move(this.motX, this.motY, this.motZ);
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ // PAIL: CHECK ME
+ org.bukkit.Server server = this.world.getServer();
+ org.bukkit.World bworld = this.world.getWorld();
+
2016-02-29 22:32:46 +01:00
+ Location from = new Location(bworld, this.lastX, this.lastY, this.lastZ, prevYaw, prevPitch);
+ Location to = new Location(bworld, this.locX, this.locY, this.locZ, this.yaw, this.pitch);
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+
+ server.getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
+
+ if (!from.equals(to)) {
+ VehicleMoveEvent event = new VehicleMoveEvent(vehicle, from, to);
+ server.getPluginManager().callEvent(event);
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
} else {
this.motX = 0.0D;
this.motY = 0.0D;
@@ -591,6 +667,11 @@
2016-02-29 22:32:46 +01:00
this.e(this.fallDistance, 1.0F);
if (!this.world.isClientSide && !this.dead) {
+ // CraftBukkit start
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, null);
+ this.world.getServer().getPluginManager().callEvent(destroyEvent);
+ if (!destroyEvent.isCancelled()) {
2016-02-29 22:32:46 +01:00
this.die();
if (this.world.getGameRules().getBoolean("doEntityDrops")) {
int i;
@@ -604,6 +685,7 @@
}
2015-02-26 23:41:06 +01:00
}
}
2015-02-26 23:41:06 +01:00
+ } // CraftBukkit end
}
this.fallDistance = 0.0F;