Skip to content

Commit

Permalink
Avoid collision shapes outside world border in findFreePosition
Browse files Browse the repository at this point in the history
This is to correctly adhere to Vanilla behavior.
  • Loading branch information
Spottedleaf committed Jul 14, 2024
1 parent 1f0ca52 commit 225d5f9
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -330,6 +333,16 @@ public final Optional<Vec3> 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());
Expand Down

0 comments on commit 225d5f9

Please sign in to comment.