3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00
Paper/nms-patches/EntityHanging.patch
2016-03-01 09:32:45 +11:00

168 Zeilen
6.9 KiB
Diff

--- a/net/minecraft/server/EntityHanging.java
+++ b/net/minecraft/server/EntityHanging.java
@@ -3,6 +3,11 @@
import com.google.common.base.Predicate;
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 {
private static final Predicate<Entity> c = new Predicate() {
@@ -38,30 +43,39 @@
this.updateBoundingBox();
}
- 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;
+ /* CraftBukkit start - bounding box calculation made static (for spawn usage)
+
+ l is from function l()
+ m is from function m()
+
+ Placing here as it's more likely to be noticed as something which needs to be updated
+ then something in a CraftBukkit file.
+ */
+ 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;
- double d4 = this.a(this.getWidth());
- double d5 = this.a(this.getHeight());
+ double d4 = a(width);
+ double d5 = a(height);
- d0 -= (double) this.direction.getAdjacentX() * 0.46875D;
- d2 -= (double) this.direction.getAdjacentZ() * 0.46875D;
+ d0 -= (double) direction.getAdjacentX() * 0.46875D;
+ d2 -= (double) direction.getAdjacentZ() * 0.46875D;
d1 += d5;
- EnumDirection enumdirection = this.direction.f();
+ EnumDirection enumdirection = direction.f();
d0 += d4 * (double) enumdirection.getAdjacentX();
d2 += d4 * (double) enumdirection.getAdjacentZ();
- this.locX = d0;
- this.locY = d1;
- this.locZ = d2;
- double d6 = (double) this.getWidth();
- double d7 = (double) this.getHeight();
- double d8 = (double) this.getWidth();
+ if (entity != null) {
+ entity.locX = d0;
+ entity.locY = d1;
+ entity.locZ = d2;
+ }
+ double d6 = (double) width;
+ double d7 = (double) height;
+ double d8 = (double) width;
- if (this.direction.k() == EnumDirection.EnumAxis.Z) {
+ if (direction.k() == EnumDirection.EnumAxis.Z) {
d8 = 1.0D;
} else {
d6 = 1.0D;
@@ -70,11 +84,18 @@
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));
+ return new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8);
+ }
+
+ protected void updateBoundingBox() {
+ if (this.direction != null) {
+ // CraftBukkit start code moved in to calculateBoundingBox
+ this.a(calculateBoundingBox(this, this.blockPosition, this.direction, this.getWidth(), this.getHeight()));
+ // CraftBukkit end
}
}
- private double a(int i) {
+ private static double a(int i) {
return i % 32 == 0 ? 0.5D : 0.0D;
}
@@ -85,6 +106,24 @@
if (this.d++ == 100 && !this.world.isClientSide) {
this.d = 0;
if (!this.dead && !this.survives()) {
+ // CraftBukkit start - fire break events
+ 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);
+
+ if (dead || event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.die();
this.a((Entity) null);
}
@@ -135,6 +174,21 @@
return false;
} else {
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);
+
+ if (this.dead || event.isCancelled()) {
+ return true;
+ }
+ // CraftBukkit end
+
this.die();
this.ao();
this.a(damagesource.getEntity());
@@ -146,6 +200,18 @@
public void move(double d0, double d1, double d2) {
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
+
this.die();
this.a((Entity) null);
}
@@ -153,7 +219,7 @@
}
public void g(double d0, double d1, double d2) {
- 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();
this.a((Entity) null);
}