Skip to content

Commit

Permalink
[Experimentation] Use Entity#makeBoundingBox
Browse files Browse the repository at this point in the history
The initial patch to prevent bounding box desync used the
EntityDimension to create the bounding box if neccesary. This fails to
respect the ability of entities overwriting their Entity#makeBoundingBox
method (e.g. what shulkers do).
This commit moves the bounding box recalculation after the position
update but prior to any callbacks to the level.
  • Loading branch information
lynxplay committed Jun 27, 2021
1 parent dd4466e commit 8c62b3a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
27 changes: 14 additions & 13 deletions patches/server/0467-Ensure-Entity-AABB-s-are-never-invalid.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Ensure Entity AABB's are never invalid


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 912723108af2ffe660f0c2e528e4e028f7f74bcb..b208f561ab8bb0ea9ad06fb2a30becef4583c2e6 100644
index 912723108af2ffe660f0c2e528e4e028f7f74bcb..7606f6fd9a79b1becd7af5b203ababbc6c6e4b7e 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -560,7 +560,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
Expand All @@ -17,19 +17,20 @@ index 912723108af2ffe660f0c2e528e4e028f7f74bcb..b208f561ab8bb0ea9ad06fb2a30becef
}

protected AABB makeBoundingBox() {
@@ -3740,6 +3740,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
}
@@ -3750,6 +3750,13 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
this.blockPosition = new BlockPos(i, j, k);
}

+ // Paper start - never allow AABB to become desynced from position
+ // hanging has its own special logic
+ if (!(this instanceof net.minecraft.world.entity.decoration.HangingEntity)) {
+ this.setBoundingBox(this.makeBoundingBox());
+ }
+ // Paper end
+
this.levelCallback.onMove();
GameEventListenerRegistrar gameeventlistenerregistrar = this.getGameEventListenerRegistrar();

public final void setPosRaw(double x, double y, double z) {
+ // Paper start - never allow AABB to become desynced from position
+ // hanging has its own special logic
+ if (!(this instanceof net.minecraft.world.entity.decoration.HangingEntity) && (this.position.x != x || this.position.y != y || this.position.z != z)) {
+ this.setBoundingBox(this.dimensions.makeBoundingBox(x, y, z));
+ }
+ // Paper end
if (this.position.x != x || this.position.y != y || this.position.z != z) {
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);
diff --git a/src/main/java/net/minecraft/world/entity/monster/Shulker.java b/src/main/java/net/minecraft/world/entity/monster/Shulker.java
index ca0d1c059a6ad94590bcbff34b37b9c13ef19474..c61f127342f404fbf766c64254fd191ff01f1507 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Shulker.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 6fe23851c3ab105c8ebc4fd7ded47da205d5036c..487b22171521de0cae30e57ca7f62cf05aeb3b0c 100644
index 1e0a9fb7db34350191d1ddb2633df31c8528e17f..8e1d9ffd52a4988a436ba67507f36fd5623ea81f 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3927,4 +3927,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
@@ -3928,4 +3928,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n

void accept(Entity entity, double x, double y, double z);
}
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0530-Entity-isTicking.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Entity#isTicking


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 487b22171521de0cae30e57ca7f62cf05aeb3b0c..a8d000717a52e3896c0c81e8cf754d8cfbeadf52 100644
index 8e1d9ffd52a4988a436ba67507f36fd5623ea81f..ef67543c0d571813264bc674ba5b5ad31ed842e8 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -52,6 +52,7 @@ import net.minecraft.resources.ResourceKey;
Expand All @@ -16,7 +16,7 @@ index 487b22171521de0cae30e57ca7f62cf05aeb3b0c..a8d000717a52e3896c0c81e8cf754d8c
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.TicketType;
@@ -3932,5 +3933,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
@@ -3933,5 +3934,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
public static int nextEntityId() {
return ENTITY_COUNTER.incrementAndGet();
}
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0569-MC-4-Fix-item-position-desync.patch
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ index b30c08bfb8c55161543a4ef09f2e462e0a1fe4ae..ec93f5300cc7d423ec0d292f0f8443f9

public Vec3 updateEntityPosition(Vec3 orig) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 9c37264884d1353de9b1ef388773d1991f5db2b4..bf8e02e23fce3c48fc07c0bdb4ac137c8ba13e03 100644
index debb4a8c9ed0153f0f3cdb9709681c4564d5ba38..49d89ddfe01d4002da50f22c811b9df4e0c70dc3 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3754,6 +3754,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
Expand All @@ -58,6 +58,6 @@ index 9c37264884d1353de9b1ef388773d1991f5db2b4..bf8e02e23fce3c48fc07c0bdb4ac137c
+ }
+ }
+ // Paper end - fix MC-4
// Paper start - never allow AABB to become desynced from position
// hanging has its own special logic
if (!(this instanceof net.minecraft.world.entity.decoration.HangingEntity) && (this.position.x != x || this.position.y != y || this.position.z != z)) {
if (this.position.x != x || this.position.y != y || this.position.z != z) {
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);

0 comments on commit 8c62b3a

Please sign in to comment.