2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/EntityHanging.java
|
|
|
|
+++ b/net/minecraft/server/EntityHanging.java
|
2016-11-23 00:34:08 +01:00
|
|
|
@@ -4,6 +4,12 @@
|
2016-05-10 13:47:39 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-25 22:32:16 +01:00
|
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.entity.Hanging;
|
2016-11-23 00:34:08 +01:00
|
|
|
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.event.hanging.HangingBreakEvent;
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
|
|
|
public abstract class EntityHanging extends Entity {
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
protected static final Predicate<Entity> b = (entity) -> {
|
2019-12-10 23:00:00 +01:00
|
|
|
@@ -37,26 +43,37 @@
|
2014-12-14 17:22:59 +01:00
|
|
|
|
2019-07-23 01:34:52 +02:00
|
|
|
protected void updateBoundingBox() {
|
|
|
|
if (this.direction != null) {
|
2014-12-14 17:22:59 +01:00
|
|
|
- double d0 = (double) this.blockPosition.getX() + 0.5D;
|
|
|
|
- double d1 = (double) this.blockPosition.getY() + 0.5D;
|
|
|
|
- double d2 = (double) this.blockPosition.getZ() + 0.5D;
|
2019-07-23 01:34:52 +02:00
|
|
|
+ // CraftBukkit start code moved in to calculateBoundingBox
|
|
|
|
+ this.a(calculateBoundingBox(this, this.blockPosition, this.direction, this.getHangingWidth(), this.getHangingHeight()));
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // CraftBukkit start - break out BB calc into own method
|
|
|
|
+ public static AxisAlignedBB calculateBoundingBox(@Nullable 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;
|
2019-04-23 04:00:00 +02:00
|
|
|
- double d4 = this.a(this.getHangingWidth());
|
|
|
|
- double d5 = this.a(this.getHangingHeight());
|
2019-07-23 01:34:52 +02:00
|
|
|
+ double d4 = a(width);
|
|
|
|
+ double d5 = a(height);
|
|
|
|
|
2014-12-14 17:22:59 +01:00
|
|
|
- d0 -= (double) this.direction.getAdjacentX() * 0.46875D;
|
|
|
|
- d2 -= (double) this.direction.getAdjacentZ() * 0.46875D;
|
2019-07-23 01:34:52 +02:00
|
|
|
+ d0 -= (double) direction.getAdjacentX() * 0.46875D;
|
|
|
|
+ d2 -= (double) direction.getAdjacentZ() * 0.46875D;
|
|
|
|
d1 += d5;
|
2020-06-25 02:00:00 +02:00
|
|
|
- EnumDirection enumdirection = this.direction.h();
|
|
|
|
+ EnumDirection enumdirection = direction.h();
|
2014-12-14 17:22:59 +01:00
|
|
|
|
2019-07-23 01:34:52 +02:00
|
|
|
d0 += d4 * (double) enumdirection.getAdjacentX();
|
|
|
|
d2 += d4 * (double) enumdirection.getAdjacentZ();
|
2019-12-10 23:00:00 +01:00
|
|
|
- this.setPositionRaw(d0, d1, d2);
|
2019-04-23 04:00:00 +02:00
|
|
|
- double d6 = (double) this.getHangingWidth();
|
|
|
|
- double d7 = (double) this.getHangingHeight();
|
|
|
|
- double d8 = (double) this.getHangingWidth();
|
2019-07-23 01:34:52 +02:00
|
|
|
+ if (entity != null) {
|
2019-12-10 23:00:00 +01:00
|
|
|
+ entity.setPositionRaw(d0, d1, d2);
|
2019-07-23 01:34:52 +02:00
|
|
|
+ }
|
|
|
|
+ double d6 = (double) width;
|
|
|
|
+ double d7 = (double) height;
|
|
|
|
+ double d8 = (double) width;
|
2019-04-23 04:00:00 +02:00
|
|
|
|
2020-06-25 02:00:00 +02:00
|
|
|
- if (this.direction.n() == EnumDirection.EnumAxis.Z) {
|
|
|
|
+ if (direction.n() == EnumDirection.EnumAxis.Z) {
|
2019-07-23 01:34:52 +02:00
|
|
|
d8 = 1.0D;
|
|
|
|
} else {
|
|
|
|
d6 = 1.0D;
|
2019-12-10 23:00:00 +01:00
|
|
|
@@ -65,11 +82,12 @@
|
2019-07-23 01:34:52 +02:00
|
|
|
d6 /= 32.0D;
|
|
|
|
d7 /= 32.0D;
|
|
|
|
d8 /= 32.0D;
|
2019-04-23 04:00:00 +02:00
|
|
|
- this.a(new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8));
|
2019-07-23 01:34:52 +02:00
|
|
|
+ return new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8);
|
2014-12-14 17:22:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 01:34:52 +02:00
|
|
|
+ // CraftBukkit end
|
2014-12-14 17:22:59 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -83,6 +101,24 @@
|
|
|
|
if (this.e++ == 100) {
|
|
|
|
this.e = 0;
|
|
|
|
if (!this.dead && !this.survives()) {
|
|
|
|
+ // CraftBukkit start - fire break events
|
|
|
|
+ Material material = this.world.getType(this.getChunkCoordinates()).getMaterial();
|
|
|
|
+ HangingBreakEvent.RemoveCause cause;
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2020-06-25 02:00:00 +02:00
|
|
|
+ if (!material.equals(Material.AIR)) {
|
|
|
|
+ // TODO: This feels insufficient to catch 100% of suffocation cases
|
|
|
|
+ cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
|
|
|
|
+ } else {
|
|
|
|
+ cause = HangingBreakEvent.RemoveCause.PHYSICS;
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2020-06-25 02:00:00 +02:00
|
|
|
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2020-06-25 02:00:00 +02:00
|
|
|
+ if (dead || event.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.die();
|
|
|
|
this.a((Entity) null);
|
|
|
|
}
|
|
|
|
@@ -146,6 +182,22 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2015-02-26 23:41:06 +01:00
|
|
|
if (!this.dead && !this.world.isClientSide) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - fire break events
|
2019-11-28 06:31:04 +01:00
|
|
|
+ Entity damager = (damagesource instanceof EntityDamageSourceIndirect) ? ((EntityDamageSourceIndirect) damagesource).getProximateDamageSource() : damagesource.getEntity();
|
|
|
|
+ HangingBreakEvent event;
|
|
|
|
+ if (damager != null) {
|
|
|
|
+ event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damager.getBukkitEntity(), damagesource.isExplosion() ? HangingBreakEvent.RemoveCause.EXPLOSION : HangingBreakEvent.RemoveCause.ENTITY);
|
|
|
|
+ } else {
|
|
|
|
+ event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), damagesource.isExplosion() ? HangingBreakEvent.RemoveCause.EXPLOSION : HangingBreakEvent.RemoveCause.DEFAULT);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ if (this.dead || event.isCancelled()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
|
|
|
this.die();
|
2019-04-23 04:00:00 +02:00
|
|
|
this.velocityChanged();
|
2016-02-29 22:32:46 +01:00
|
|
|
this.a(damagesource.getEntity());
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -158,6 +210,18 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
|
|
|
public void move(EnumMoveType enummovetype, Vec3D vec3d) {
|
|
|
|
if (!this.world.isClientSide && !this.dead && vec3d.g() > 0.0D) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ 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
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
this.die();
|
2016-02-29 22:32:46 +01:00
|
|
|
this.a((Entity) null);
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -166,7 +230,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2020-08-11 23:00:00 +02:00
|
|
|
public void i(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
|
2014-11-25 22:32:16 +01:00
|
|
|
this.die();
|
2016-02-29 22:32:46 +01:00
|
|
|
this.a((Entity) null);
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|