From 225d5f937ddbbf1ad5c117659bf6961209f99c2c Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sun, 14 Jul 2024 12:56:30 -0700 Subject: [PATCH] Avoid collision shapes outside world border in findFreePosition This is to correctly adhere to Vanilla behavior. --- .../moonrise/mixin/collisions/LevelMixin.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/collisions/LevelMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/collisions/LevelMixin.java index 495d4ba0..5299d45a 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/collisions/LevelMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/collisions/LevelMixin.java @@ -16,6 +16,7 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.border.WorldBorder; import net.minecraft.world.level.chunk.ChunkSource; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; @@ -48,6 +49,8 @@ public abstract class LevelMixin implements CollisionLevel, LevelAccessor, AutoC @Shadow public abstract LevelChunk getChunk(int x, int z); + @Shadow + public abstract WorldBorder getWorldBorder(); @Unique @@ -330,6 +333,16 @@ public final Optional findFreePosition(final Entity entity, final VoxelSha null ); + final WorldBorder worldBorder = this.getWorldBorder(); + if (worldBorder != null) { + aabbs.removeIf((final AABB aabb) -> { + return !worldBorder.isWithinBounds(aabb); + }); + voxels.removeIf((final VoxelShape shape) -> { + return !worldBorder.isWithinBounds(shape.bounds()); + }); + } + // push voxels into aabbs for (int i = 0, len = voxels.size(); i < len; ++i) { aabbs.addAll(voxels.get(i).toAabbs());