Paper/nms-patches/EntityHanging.patch

175 lines
6.9 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityHanging.java
+++ b/net/minecraft/server/EntityHanging.java
2016-05-10 13:47:39 +02:00
@@ -4,6 +4,11 @@
import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
+// CraftBukkit start
+import org.bukkit.entity.Hanging;
+import org.bukkit.event.hanging.HangingBreakEvent;
+// CraftBukkit end
+
public abstract class EntityHanging extends Entity {
2016-02-29 22:32:46 +01:00
private static final Predicate<Entity> c = new Predicate() {
2016-06-09 12:42:49 +02:00
@@ -41,43 +46,52 @@
2015-02-26 23:41:06 +01:00
this.updateBoundingBox();
}
2016-02-29 22:32:46 +01:00
- protected void updateBoundingBox() {
- if (this.direction != null) {
- double d0 = (double) this.blockPosition.getX() + 0.5D;
- double d1 = (double) this.blockPosition.getY() + 0.5D;
- double d2 = (double) this.blockPosition.getZ() + 0.5D;
2016-06-09 03:43:49 +02:00
- double d3 = 0.46875D;
2016-02-29 22:32:46 +01:00
- double d4 = this.a(this.getWidth());
- double d5 = this.a(this.getHeight());
2016-06-09 03:43:49 +02:00
-
- d0 -= (double) this.direction.getAdjacentX() * 0.46875D;
- d2 -= (double) this.direction.getAdjacentZ() * 0.46875D;
2016-06-09 03:43:49 +02:00
- d1 += d5;
- EnumDirection enumdirection = this.direction.f();
2016-06-09 03:43:49 +02:00
+ // CraftBukkit start - break out BB calc into own method
+ public static AxisAlignedBB calculateBoundingBox(Entity entity, BlockPosition blockPosition, EnumDirection direction, int width, int height) {
+ double d0 = (double) blockPosition.getX() + 0.5D;
+ double d1 = (double) blockPosition.getY() + 0.5D;
+ double d2 = (double) blockPosition.getZ() + 0.5D;
+ double d3 = 0.46875D;
2016-06-09 12:42:49 +02:00
+ double d4 = a(width);
+ double d5 = a(height);
2016-06-09 03:43:49 +02:00
+
+ d0 -= (double) direction.getAdjacentX() * 0.46875D;
+ d2 -= (double) direction.getAdjacentZ() * 0.46875D;
+ d1 += d5;
+ EnumDirection enumdirection = direction.f();
+
+ d0 += d4 * (double) enumdirection.getAdjacentX();
+ d2 += d4 * (double) enumdirection.getAdjacentZ();
2016-06-09 06:27:59 +02:00
+ if (entity != null) {
+ entity.locX = d0;
+ entity.locY = d1;
+ entity.locZ = d2;
+ }
2016-06-09 03:43:49 +02:00
+ double d6 = (double) width;
+ double d7 = (double) height;
+ double d8 = (double) width;
2016-06-09 03:43:49 +02:00
- d0 += d4 * (double) enumdirection.getAdjacentX();
- d2 += d4 * (double) enumdirection.getAdjacentZ();
- this.locX = d0;
- this.locY = d1;
- this.locZ = d2;
2016-02-29 22:32:46 +01:00
- double d6 = (double) this.getWidth();
- double d7 = (double) this.getHeight();
- double d8 = (double) this.getWidth();
2016-06-09 03:43:49 +02:00
-
- if (this.direction.k() == EnumDirection.EnumAxis.Z) {
- d8 = 1.0D;
- } else {
- d6 = 1.0D;
- }
+ if (direction.k() == EnumDirection.EnumAxis.Z) {
+ d8 = 1.0D;
+ } else {
+ d6 = 1.0D;
2016-02-29 22:32:46 +01:00
+ }
2015-02-26 23:41:06 +01:00
2016-06-09 03:43:49 +02:00
- d6 /= 32.0D;
- d7 /= 32.0D;
- d8 /= 32.0D;
- this.a(new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8));
2016-06-09 03:43:49 +02:00
+ d6 /= 32.0D;
+ d7 /= 32.0D;
+ d8 /= 32.0D;
+ return new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8);
+ }
+
2016-02-29 22:32:46 +01:00
+ protected void updateBoundingBox() {
+ if (this.direction != null) {
+ // CraftBukkit start code moved in to calculateBoundingBox
2016-02-29 22:32:46 +01:00
+ this.a(calculateBoundingBox(this, this.blockPosition, this.direction, this.getWidth(), this.getHeight()));
+ // CraftBukkit end
}
}
2016-06-09 12:42:49 +02:00
- private double a(int i) {
+ private static double a(int i) { // CraftBukkit - static
return i % 32 == 0 ? 0.5D : 0.0D;
}
2016-06-09 06:27:59 +02:00
@@ -88,6 +102,24 @@
2016-02-29 22:32:46 +01:00
if (this.d++ == 100 && !this.world.isClientSide) {
this.d = 0;
if (!this.dead && !this.survives()) {
+ // CraftBukkit start - fire break events
2016-02-29 22:32:46 +01:00
+ Material material = this.world.getType(new BlockPosition(this)).getMaterial();
+ HangingBreakEvent.RemoveCause cause;
+
+ if (!material.equals(Material.AIR)) {
+ // TODO: This feels insufficient to catch 100% of suffocation cases
+ cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
+ } else {
+ cause = HangingBreakEvent.RemoveCause.PHYSICS;
+ }
+
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
+ this.world.getServer().getPluginManager().callEvent(event);
+
2016-02-29 22:32:46 +01:00
+ if (dead || event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.die();
2016-02-29 22:32:46 +01:00
this.a((Entity) null);
}
2016-06-09 06:27:59 +02:00
@@ -140,6 +172,21 @@
return false;
} else {
2015-02-26 23:41:06 +01:00
if (!this.dead && !this.world.isClientSide) {
+ // CraftBukkit start - fire break events
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.DEFAULT);
+ if (damagesource.getEntity() != null) {
+ event = new org.bukkit.event.hanging.HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
+ } else if (damagesource.isExplosion()) {
+ event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.EXPLOSION);
+ }
+
+ this.world.getServer().getPluginManager().callEvent(event);
+
2016-02-29 22:32:46 +01:00
+ if (this.dead || event.isCancelled()) {
+ return true;
+ }
+ // CraftBukkit end
+
this.die();
2016-06-09 03:43:49 +02:00
this.ap();
2016-02-29 22:32:46 +01:00
this.a(damagesource.getEntity());
2016-06-09 06:27:59 +02:00
@@ -151,6 +198,18 @@
public void move(double d0, double d1, double d2) {
2015-02-26 23:41:06 +01:00
if (!this.world.isClientSide && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
+ if (this.dead) return; // CraftBukkit
+
+ // CraftBukkit start - fire break events
+ // TODO - Does this need its own cause? Seems to only be triggered by pistons
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (this.dead || event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
this.die();
2016-02-29 22:32:46 +01:00
this.a((Entity) null);
}
2016-06-09 06:27:59 +02:00
@@ -158,7 +217,7 @@
}
public void g(double d0, double d1, double d2) {
2015-02-26 23:41:06 +01:00
- if (!this.world.isClientSide && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
+ if (false && !this.world.isClientSide && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { // CraftBukkit - not needed
this.die();
2016-02-29 22:32:46 +01:00
this.a((Entity) null);
}