Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-21 05:50:05 +01:00
158 Zeilen
6.8 KiB
Diff
158 Zeilen
6.8 KiB
Diff
--- a/net/minecraft/server/EntityHanging.java
|
|
+++ b/net/minecraft/server/EntityHanging.java
|
|
@@ -4,6 +4,12 @@
|
|
import javax.annotation.Nullable;
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.entity.Hanging;
|
|
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
|
+import org.bukkit.event.hanging.HangingBreakEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public abstract class EntityHanging extends Entity {
|
|
|
|
protected static final Predicate<Entity> b = (entity) -> {
|
|
@@ -37,26 +43,37 @@
|
|
|
|
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 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;
|
|
- double d4 = this.a(this.getHangingWidth());
|
|
- double d5 = this.a(this.getHangingHeight());
|
|
+ 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.g();
|
|
+ EnumDirection enumdirection = direction.g();
|
|
|
|
d0 += d4 * (double) enumdirection.getAdjacentX();
|
|
d2 += d4 * (double) enumdirection.getAdjacentZ();
|
|
- this.setPositionRaw(d0, d1, d2);
|
|
- double d6 = (double) this.getHangingWidth();
|
|
- double d7 = (double) this.getHangingHeight();
|
|
- double d8 = (double) this.getHangingWidth();
|
|
+ if (entity != null) {
|
|
+ entity.setPositionRaw(d0, d1, d2);
|
|
+ }
|
|
+ double d6 = (double) width;
|
|
+ double d7 = (double) height;
|
|
+ double d8 = (double) width;
|
|
|
|
- if (this.direction.m() == EnumDirection.EnumAxis.Z) {
|
|
+ if (direction.m() == EnumDirection.EnumAxis.Z) {
|
|
d8 = 1.0D;
|
|
} else {
|
|
d6 = 1.0D;
|
|
@@ -65,11 +82,12 @@
|
|
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);
|
|
}
|
|
}
|
|
+ // CraftBukkit end
|
|
|
|
- private double a(int i) {
|
|
+ private static double a(int i) { // CraftBukkit - static
|
|
return i % 32 == 0 ? 0.5D : 0.0D;
|
|
}
|
|
|
|
@@ -78,6 +96,24 @@
|
|
if (this.e++ == 100 && !this.world.isClientSide) {
|
|
this.e = 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);
|
|
}
|
|
@@ -140,6 +176,22 @@
|
|
return false;
|
|
} else {
|
|
if (!this.dead && !this.world.isClientSide) {
|
|
+ // CraftBukkit start - fire break events
|
|
+ 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);
|
|
+ }
|
|
+
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (this.dead || event.isCancelled()) {
|
|
+ return true;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
this.die();
|
|
this.velocityChanged();
|
|
this.a(damagesource.getEntity());
|
|
@@ -152,6 +204,18 @@
|
|
@Override
|
|
public void move(EnumMoveType enummovetype, Vec3D vec3d) {
|
|
if (!this.world.isClientSide && !this.dead && vec3d.g() > 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);
|
|
}
|
|
@@ -160,7 +224,7 @@
|
|
|
|
@Override
|
|
public void h(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);
|
|
}
|