diff options
author | Jake Potrebic <[email protected]> | 2024-04-10 16:42:38 -0700 |
---|---|---|
committer | Jake Potrebic <[email protected]> | 2024-04-10 16:42:38 -0700 |
commit | 05395a5019af322c79f7195d6d261e3ff4c72eff (patch) | |
tree | 7766dadad8826bff9bc3c4dc74c2b56f539d3b4e | |
parent | 6ab2636b17708c1239057e33aa8bd17ed9bcafa8 (diff) | |
download | Paper-05395a5019af322c79f7195d6d261e3ff4c72eff.tar.gz Paper-05395a5019af322c79f7195d6d261e3ff4c72eff.zip |
fix collision patch
-rw-r--r-- | patches/server/0993-Optimize-Collision-to-not-load-chunks.patch | 115 | ||||
-rw-r--r-- | patches/server/1015-Collision-optimisations.patch | 22 |
2 files changed, 47 insertions, 90 deletions
diff --git a/patches/server/0993-Optimize-Collision-to-not-load-chunks.patch b/patches/server/0993-Optimize-Collision-to-not-load-chunks.patch index 0ade44ccc3..dd6fd94feb 100644 --- a/patches/server/0993-Optimize-Collision-to-not-load-chunks.patch +++ b/patches/server/0993-Optimize-Collision-to-not-load-chunks.patch @@ -26,7 +26,7 @@ index 461c27292af06a5150de8ec263d0c8527e8c5278..37245ff682837e7e8c9647f4afe30f0d // CraftBukkit end entityplayer1.setPos(entityplayer1.getX(), entityplayer1.getY() + 1.0D, entityplayer1.getZ()); diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index e6ba58cf8aef66bacdff8bf538c73b14e16fbea5..5cc7043d2783d38f9d3a28d0cb62f8834e971e1e 100644 +index a66fe080ee73171090abec48352ad0bd457a2a6f..d4c8f2cb1e3adf45863226ae9ad31968bc3445c9 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -242,6 +242,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -38,19 +38,21 @@ index e6ba58cf8aef66bacdff8bf538c73b14e16fbea5..5cc7043d2783d38f9d3a28d0cb62f883 public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper diff --git a/src/main/java/net/minecraft/world/level/BlockCollisions.java b/src/main/java/net/minecraft/world/level/BlockCollisions.java -index 1c10835b59aaefa3a65ff64f784620bdc54ddcdc..354290f88af285af229e4315e53e9bd76439d0da 100644 +index 1c10835b59aaefa3a65ff64f784620bdc54ddcdc..cd89623a44f02d7db77f0d0f87545cf80841f403 100644 --- a/src/main/java/net/minecraft/world/level/BlockCollisions.java +++ b/src/main/java/net/minecraft/world/level/BlockCollisions.java -@@ -65,35 +65,64 @@ public class BlockCollisions<T> extends AbstractIterator<T> { - +@@ -66,18 +66,37 @@ public class BlockCollisions<T> extends AbstractIterator<T> { @Override protected T computeNext() { -- while (this.cursor.advance()) { + while (this.cursor.advance()) { - int i = this.cursor.nextX(); - int j = this.cursor.nextY(); - int k = this.cursor.nextZ(); -- int l = this.cursor.getNextType(); -- if (l != 3) { ++ int i = this.cursor.nextX(); final int x = i; // Paper - OBFHELPER ++ int j = this.cursor.nextY(); final int y = j; // Paper - OBFHELPER ++ int k = this.cursor.nextZ(); final int z = k; // Paper - OBFHELPER + int l = this.cursor.getNextType(); + if (l != 3) { - BlockGetter blockGetter = this.getChunk(i, k); - if (blockGetter != null) { - this.pos.set(i, j, k); @@ -58,82 +60,37 @@ index 1c10835b59aaefa3a65ff64f784620bdc54ddcdc..354290f88af285af229e4315e53e9bd7 - if ((!this.onlySuffocatingBlocks || blockState.isSuffocating(blockGetter, this.pos)) - && (l != 1 || blockState.hasLargeCollisionShape()) - && (l != 2 || blockState.is(Blocks.MOVING_PISTON))) { -- VoxelShape voxelShape = blockState.getCollisionShape(this.collisionGetter, this.pos, this.context); -- if (voxelShape == Shapes.block()) { -- if (this.box.intersects((double)i, (double)j, (double)k, (double)i + 1.0, (double)j + 1.0, (double)k + 1.0)) { -- return this.resultProvider.apply(this.pos, voxelShape.move((double)i, (double)j, (double)k)); -- } -- } else { -- VoxelShape voxelShape2 = voxelShape.move((double)i, (double)j, (double)k); -- if (!voxelShape2.isEmpty() && Shapes.joinIsNotEmpty(voxelShape2, this.entityShape, BooleanOp.AND)) { -- return this.resultProvider.apply(this.pos, voxelShape2); -- } -- } -+ while(true) { -+ if (this.cursor.advance()) { -+ int i = this.cursor.nextX(); final int x = i; // Paper -+ int j = this.cursor.nextY(); final int y = j; // Paper -+ int k = this.cursor.nextZ(); final int z = k; // Paper -+ int l = this.cursor.getNextType(); -+ if (l == 3) { -+ continue; -+ } + // Paper start - ensure we don't load chunks -+ final @Nullable Entity source = this.context instanceof net.minecraft.world.phys.shapes.EntityCollisionContext entityContext ? entityContext.getEntity() : null; -+ boolean far = source != null && io.papermc.paper.util.MCUtil.distanceSq(source.getX(), y, source.getZ(), x, y, z) > 14; -+ this.pos.set(x, y, z); -+ -+ BlockState blockState; -+ if (this.collisionGetter instanceof net.minecraft.server.level.WorldGenRegion) { -+ BlockGetter blockGetter = this.getChunk(x, z); -+ if (blockGetter == null) { -+ continue; -+ } -+ blockState = blockGetter.getBlockState(this.pos); -+ } else if ((!far && source instanceof net.minecraft.server.level.ServerPlayer) || (source != null && source.collisionLoadChunks)) { -+ blockState = this.collisionGetter.getBlockState(this.pos); -+ } else { -+ blockState = this.collisionGetter.getBlockStateIfLoaded(this.pos); -+ } -+ -+ if (blockState == null) { -+ if (!(source instanceof net.minecraft.server.level.ServerPlayer) || source.level().paperConfig().chunks.preventMovingIntoUnloadedChunks) { -+ return this.resultProvider.apply(new BlockPos.MutableBlockPos(x, y, z), Shapes.create(far ? source.getBoundingBox() : new AABB(new BlockPos(x, y, z)))); ++ // BlockGetter blockGetter = this.getChunk(i, k); ++ if (true) { ++ final @Nullable Entity source = this.context instanceof net.minecraft.world.phys.shapes.EntityCollisionContext entityContext ? entityContext.getEntity() : null; ++ boolean far = source != null && io.papermc.paper.util.MCUtil.distanceSq(source.getX(), y, source.getZ(), x, y, z) > 14; ++ this.pos.set(x, y, z); ++ BlockState blockState; ++ if (this.collisionGetter instanceof net.minecraft.server.level.WorldGenRegion) { ++ BlockGetter blockGetter = this.getChunk(x, z); ++ if (blockGetter == null) { ++ continue; ++ } ++ blockState = blockGetter.getBlockState(this.pos); ++ } else if ((!far && source instanceof net.minecraft.server.level.ServerPlayer) || (source != null && source.collisionLoadChunks)) { ++ blockState = this.collisionGetter.getBlockState(this.pos); ++ } else { ++ blockState = this.collisionGetter.getBlockStateIfLoaded(this.pos); + } -+ // Paper end -+ continue; -+ } -+ -+ // Paper - moved up -+ if (/*this.onlySuffocatingBlocks && (!blockState.isSuffocating(blockGetter, this.pos)) ||*/ l == 1 && !blockState.hasLargeCollisionShape() || l == 2 && !blockState.is(Blocks.MOVING_PISTON)) { // Paper - onlySuffocatingBlocks is only true on the client, so we don't care about it here -+ continue; -+ } -+ -+ VoxelShape voxelShape = blockState.getCollisionShape(this.collisionGetter, this.pos, this.context); -+ if (voxelShape == Shapes.block()) { -+ if (!this.box.intersects((double)i, (double)j, (double)k, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D)) { ++ if (blockState == null) { ++ if (!(source instanceof net.minecraft.server.level.ServerPlayer) || source.level().paperConfig().chunks.preventMovingIntoUnloadedChunks) { ++ return this.resultProvider.apply(new BlockPos.MutableBlockPos(x, y, z), Shapes.create(far ? source.getBoundingBox() : new AABB(new BlockPos(x, y, z)))); ++ } + continue; - } -+ -+ return this.resultProvider.apply(this.pos, voxelShape.move((double)i, (double)j, (double)k)); -+ } -+ -+ VoxelShape voxelShape2 = voxelShape.move((double)i, (double)j, (double)k); -+ if (voxelShape2.isEmpty() || !Shapes.joinIsNotEmpty(voxelShape2, this.entityShape, BooleanOp.AND)) { -+ continue; - } -+ -+ return this.resultProvider.apply(this.pos, voxelShape2); - } -- } - -- return this.endOfData(); -+ return this.endOfData(); -+ } - } - } ++ } ++ if (/*(!this.onlySuffocatingBlocks || blockState.isSuffocating(blockGetter, this.pos)) &&*/ (l != 1 || blockState.hasLargeCollisionShape()) && (l != 2 || blockState.is(Blocks.MOVING_PISTON))) { // Paper - onlySuffocatingBlocks is only true on the client, so we don't care about it here ++ // Paper end + VoxelShape voxelShape = blockState.getCollisionShape(this.collisionGetter, this.pos, this.context); + if (voxelShape == Shapes.block()) { + if (this.box.intersects((double)i, (double)j, (double)k, (double)i + 1.0, (double)j + 1.0, (double)k + 1.0)) { diff --git a/src/main/java/net/minecraft/world/level/CollisionGetter.java b/src/main/java/net/minecraft/world/level/CollisionGetter.java -index 204791d893383a17b47e4c683cad3ba6c0839762..a4200e1992207e7665673c2acdb45facfd0bc676 100644 +index e57cb7fe53e915d24246e44c7f49971f5b2ab2cf..1ad0c976c6e2d6d31397dff850a9de7c16d16fba 100644 --- a/src/main/java/net/minecraft/world/level/CollisionGetter.java +++ b/src/main/java/net/minecraft/world/level/CollisionGetter.java @@ -44,11 +44,13 @@ public interface CollisionGetter extends BlockGetter { diff --git a/patches/server/1015-Collision-optimisations.patch b/patches/server/1015-Collision-optimisations.patch index d418ac9c7b..1d0d846bfb 100644 --- a/patches/server/1015-Collision-optimisations.patch +++ b/patches/server/1015-Collision-optimisations.patch @@ -2214,7 +2214,7 @@ index 594cb6ce4bfa6c42212000a1ed983ea95ee2c4bf..97b0119ac71284b3a223c089bec26d87 entityplayer1.setPos(entityplayer1.getX(), entityplayer1.getY() + 1.0D, entityplayer1.getZ()); } diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 865c5ee8a8a14ef1a7d71dcab3e324932d065d5f..8c2c877a26af90dae6d083e12a51384755c7a1de 100644 +index 9a01eff5a93c68edd45f98e9a6f8d24656650fb6..7992375dc55492aeb6defb204b28dd267be4a6e7 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -1250,9 +1250,44 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -2466,18 +2466,18 @@ index ffa4f34d964fbcc53e2dfe11677832db21a6eb93..7618364e5373fe17cfe45a5a4ee9ab25 } diff --git a/src/main/java/net/minecraft/world/level/BlockCollisions.java b/src/main/java/net/minecraft/world/level/BlockCollisions.java -index 354290f88af285af229e4315e53e9bd76439d0da..b87bcc4a465fb83463da4811a79c381141c6f70b 100644 +index cd89623a44f02d7db77f0d0f87545cf80841f403..068c65fc7366b22b4a6fe10f4680637f14f4635f 100644 --- a/src/main/java/net/minecraft/world/level/BlockCollisions.java +++ b/src/main/java/net/minecraft/world/level/BlockCollisions.java -@@ -107,7 +107,7 @@ public class BlockCollisions<T> extends AbstractIterator<T> { - - VoxelShape voxelShape = blockState.getCollisionShape(this.collisionGetter, this.pos, this.context); - if (voxelShape == Shapes.block()) { -- if (!this.box.intersects((double)i, (double)j, (double)k, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D)) { -+ if (!io.papermc.paper.util.CollisionUtil.voxelShapeIntersect(this.box, (double)i, (double)j, (double)k, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D)) { // Paper - keep vanilla behavior for voxelshape intersection - See comment in CollisionUtil - continue; - } - +@@ -99,7 +99,7 @@ public class BlockCollisions<T> extends AbstractIterator<T> { + // Paper end + VoxelShape voxelShape = blockState.getCollisionShape(this.collisionGetter, this.pos, this.context); + if (voxelShape == Shapes.block()) { +- if (this.box.intersects((double)i, (double)j, (double)k, (double)i + 1.0, (double)j + 1.0, (double)k + 1.0)) { ++ if (!io.papermc.paper.util.CollisionUtil.voxelShapeIntersect(this.box, (double)i, (double)j, (double)k, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D)) { // Paper - keep vanilla behavior for voxelshape intersection - See comment in CollisionUtil + return this.resultProvider.apply(this.pos, voxelShape.move((double)i, (double)j, (double)k)); + } + } else { diff --git a/src/main/java/net/minecraft/world/level/ClipContext.java b/src/main/java/net/minecraft/world/level/ClipContext.java index 86a4f30c8784c602436ecf1c78efb0bdca4b7089..b0bea28e9261767c60d30fb0e76f4f3af8a5634e 100644 --- a/src/main/java/net/minecraft/world/level/ClipContext.java |