Skip to content

Commit

Permalink
Switch to suggest shulker instanceof check
Browse files Browse the repository at this point in the history
Removes the added logic in the shulker entitiy to update its own
bounding box after peeking and replaces it with an instanceof check in
the setPosRaw method.
  • Loading branch information
lynxplay committed Jul 8, 2021
1 parent 232a2f0 commit 65c1e75
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
52 changes: 32 additions & 20 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..7606f6fd9a79b1becd7af5b203ababbc6c6e4b7e 100644
index 581f1ba9a24f5c5267dea29c892c6dfe03468f0c..e3ad8f9d995b93ab670904726b8f2cdd31b80ee4 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,29 +17,41 @@ index 912723108af2ffe660f0c2e528e4e028f7f74bcb..7606f6fd9a79b1becd7af5b203ababbc
}

protected AABB makeBoundingBox() {
@@ -3750,6 +3750,13 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
@@ -3740,7 +3740,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
}

public final void setPosRaw(double x, double y, double z) {
- if (this.position.x != x || this.position.y != y || this.position.z != z) {
+ // Paper start - never allow AABB to become desynced from position
+ final boolean changedPosition = this.position.x != x || this.position.y != y || this.position.z != z;
+ if (changedPosition) { // Paper - update internal position references if position changed.
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);
int j = Mth.floor(y);
@@ -3749,7 +3751,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
if (i != this.blockPosition.getX() || j != this.blockPosition.getY() || k != this.blockPosition.getZ()) {
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
+ }
+
+ // Paper - only recreate bounding box if position changed to reuse the existing instance as long as possible.
+ // Shulkers always require an updated bounding box, even if their position did not change
+ // as they change their bounding box while peeking.
+ // Hanging entities have their own logic and never require a bounding box update.
+ if ((changedPosition || this instanceof net.minecraft.world.entity.Shulker)
+ && !(this instanceof net.minecraft.world.entity.decoration.HangingEntity) {
+ this.setBoundingBox(this.makeBoundingBox());
+ }

+ if (changedPosition) {
this.levelCallback.onMove();
GameEventListenerRegistrar gameeventlistenerregistrar = this.getGameEventListenerRegistrar();

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
+++ b/src/main/java/net/minecraft/world/entity/monster/Shulker.java
@@ -236,6 +236,7 @@ public class Shulker extends AbstractGolem implements Enemy {
@@ -3757,6 +3770,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
gameeventlistenerregistrar.onListenerMove(this.level);
}
}
+ // Paper end

}

private void onPeekAmountChange() {
this.reapplyPosition();
+ this.setBoundingBox(this.makeBoundingBox()); // Paper - manually update bounding box as paper caches bounding box if the entity did not move (See Entity#setPosRaw)
float f = Shulker.getPhysicalPeek(this.currentPeekAmount);
float f1 = Shulker.getPhysicalPeek(this.currentPeekAmountO);
Direction enumdirection = this.getAttachFace().getOpposite();
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 1e0a9fb7db34350191d1ddb2633df31c8528e17f..8e1d9ffd52a4988a436ba67507f36fd5623ea81f 100644
index 8a07fdb74bf726b53479134e7cbf88d8d7fa998c..2866a9e01d335c8d441e1034879a33772bd40195 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3928,4 +3928,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
@@ -3935,4 +3935,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n

void accept(Entity entity, double x, double y, double z);
}
Expand All @@ -21,7 +21,7 @@ index 1e0a9fb7db34350191d1ddb2633df31c8528e17f..8e1d9ffd52a4988a436ba67507f36fd5
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 736cbdc118b7a19b724a3afd433927e8e8316d23..a6250143baced61e87900181f8b37cfd89c717ff 100644
index 135749c789d44f0af1ad11ccd1b208f1e28853eb..8c1ac43cf5510a14d1d41ec45d189ad9711024da 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -443,6 +443,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0531-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 8e1d9ffd52a4988a436ba67507f36fd5623ea81f..ef67543c0d571813264bc674ba5b5ad31ed842e8 100644
index 2866a9e01d335c8d441e1034879a33772bd40195..b9a2094e04daaf96e6d88f8be6e83dab4e4efd98 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 8e1d9ffd52a4988a436ba67507f36fd5623ea81f..ef67543c0d571813264bc674ba5b5ad3
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.TicketType;
@@ -3933,5 +3934,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
@@ -3940,5 +3941,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
public static int nextEntityId() {
return ENTITY_COUNTER.incrementAndGet();
}
Expand Down
10 changes: 5 additions & 5 deletions patches/server/0570-MC-4-Fix-item-position-desync.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loss, which forces the server to lose the same precision as the client
keeping them in sync.

diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 652d87fc5d566dba8018c81676329f0e0bca471b..c56e7fb18f9a56c8025eb70a524f028b5942da37 100644
index e62bb33852b0dca346aeb3cb2747d1a5686dea2d..ea4fa458113d68dc2ed3187e19b11d72fc05d36c 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -474,4 +474,9 @@ public class PaperConfig {
Expand Down 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 debb4a8c9ed0153f0f3cdb9709681c4564d5ba38..49d89ddfe01d4002da50f22c811b9df4e0c70dc3 100644
index bdea7ac5f14155455448b161bf324683ffc9fda5..c5bb8e5fabe12c339a35259eb1ebd6d18f81cab3 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 debb4a8c9ed0153f0f3cdb9709681c4564d5ba38..49d89ddfe01d4002da50f22c811b9df4
+ }
+ }
+ // Paper end - fix MC-4
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);
// Paper start - never allow AABB to become desynced from position
final boolean changedPosition = this.position.x != x || this.position.y != y || this.position.z != z;
if (changedPosition) { // Paper - update internal position references if position changed.

0 comments on commit 65c1e75

Please sign in to comment.