Skip to content

Commit

Permalink
Fix CachedToAABBs when offset becomes zero
Browse files Browse the repository at this point in the history
If the offset were to be undone, then it would incorrectly mark the
cache as not having an offset when it actually did.
  • Loading branch information
Spottedleaf committed Sep 19, 2023
1 parent 016b3e5 commit e2d4a5f
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2176,10 +2176,10 @@ index 0000000000000000000000000000000000000000..1cb96b09375770f92f3e494ce2f28d9f
+}
diff --git a/src/main/java/io/papermc/paper/util/collisions/CachedToAABBs.java b/src/main/java/io/papermc/paper/util/collisions/CachedToAABBs.java
new file mode 100644
index 0000000000000000000000000000000000000000..7aa8a16b5a58b709f644ff3600a4dd9b5e0b501d
index 0000000000000000000000000000000000000000..85c448a775f60ca4b4a4f2baf17487ef45bdd383
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/collisions/CachedToAABBs.java
@@ -0,0 +1,37 @@
@@ -0,0 +1,39 @@
+package io.papermc.paper.util.collisions;
+
+import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -2208,13 +2208,15 @@ index 0000000000000000000000000000000000000000..7aa8a16b5a58b709f644ff3600a4dd9b
+ }
+
+ public static CachedToAABBs offset(final CachedToAABBs cache, final double offX, final double offY, final double offZ) {
+ if (offX == 0.0 && offY == 0.0 && offZ == 0.0) {
+ return cache;
+ }
+
+ final double resX = cache.offX + offX;
+ final double resY = cache.offY + offY;
+ final double resZ = cache.offZ + offZ;
+
+ final boolean isOffset = resX != 0.0 || resY != 0.0 || resZ != 0.0;
+
+ return new CachedToAABBs(cache.aabbs, isOffset, resX, resY, resZ);
+ return new CachedToAABBs(cache.aabbs, true, resX, resY, resZ);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/util/collisions/FlatBitsetUtil.java b/src/main/java/io/papermc/paper/util/collisions/FlatBitsetUtil.java
Expand Down

0 comments on commit e2d4a5f

Please sign in to comment.