Call HangingBreakByEntityEvent for collision with boats

This commit is contained in:
Tamion 2024-02-13 13:51:57 +01:00
parent 6e31f385e3
commit ed5406ab93
No known key found for this signature in database
GPG Key ID: 01E616386DBAE296
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tamion <70228790+notTamion@users.noreply.github.com>
Date: Tue, 13 Feb 2024 13:49:50 +0100
Subject: [PATCH] Call HangingBreakByEntityEvent for collision with boats
diff --git a/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java b/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java
index f88918b7c15b72f4cb1dd313734f550432fd5858..7472bf8688b9d6e6461691bb232a79d9922cf721 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java
@@ -125,14 +125,22 @@ public abstract class HangingEntity extends Entity {
BlockState material = this.level().getBlockState(this.blockPosition());
HangingBreakEvent.RemoveCause cause;
- if (!material.isAir()) {
- // TODO: This feels insufficient to catch 100% of suffocation cases
- cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
+ // Paper start - Call HangingBreakByEntityEvent for collision with boats
+ HangingBreakEvent event;
+ java.util.List<Entity> collidingEntities = this.level().getHardCollidingEntities(this, this.getBoundingBox(), null);
+ if (!collidingEntities.isEmpty()) {
+ event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), collidingEntities.get(0).getBukkitEntity());
} else {
- cause = HangingBreakEvent.RemoveCause.PHYSICS;
+ // Paper end - Call HangingBreakByEntityEvent for collision with boats
+ if (!material.isAir()) {
+ // TODO: This feels insufficient to catch 100% of suffocation cases
+ cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
+ } else {
+ cause = HangingBreakEvent.RemoveCause.PHYSICS;
+ }
+ event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause); // Paper - Call HangingBreakByEntityEvent for collision with boats
}
- HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
this.level().getCraftServer().getPluginManager().callEvent(event);
if (this.isRemoved() || event.isCancelled()) {