Skip to content

Commit

Permalink
Cache x coordinate multiplier for CollisionUtil#sliceShapeOptimised
Browse files Browse the repository at this point in the history
This is consistent with how the rest of the collision patch iterates
the voxel bitset.
  • Loading branch information
Spottedleaf committed Aug 12, 2024
1 parent e68d381 commit a749c72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private void initHook(RegionStorageInfo regionStorageInfo, Path path, DataFixer
*/
@Overwrite
public int sectionsToVillage(final SectionPos pos) {
this.villageDistanceTracker.propagateUpdates(); // Paper - replace distance tracking util
return convertBetweenLevels(this.villageDistanceTracker.getLevel(CoordinateUtils.getChunkSectionKey(pos))); // Paper - replace distance tracking util
this.villageDistanceTracker.propagateUpdates();
return convertBetweenLevels(this.villageDistanceTracker.getLevel(CoordinateUtils.getChunkSectionKey(pos)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,15 @@ private static VoxelShape sliceShapeOptimised(final VoxelShape src, final Direct

final BitSetDiscreteVoxelShape shape = new BitSetDiscreteVoxelShape(local_len_x, local_len_y, local_len_z);

final int idx_off = shape_sz + shape_sy*size_z + shape_sx*(size_z*size_y);
final int bitset_mul_x = size_z*size_y;
final int idx_off = shape_sz + shape_sy*size_z + shape_sx*bitset_mul_x;
final int shape_mul_x = local_len_y*local_len_z;
for (int x = 0; x < local_len_x; ++x) {
boolean setX = false;
for (int y = 0; y < local_len_y; ++y) {
boolean setY = false;
for (int z = 0; z < local_len_z; ++z) {
final int unslicedIdx = idx_off + z + y*size_z + x*(size_z*size_y);
final int unslicedIdx = idx_off + z + y*size_z + x*bitset_mul_x;
if ((bitset[unslicedIdx >>> 6] & (1L << unslicedIdx)) == 0L) {
continue;
}
Expand All @@ -348,7 +350,7 @@ private static VoxelShape sliceShapeOptimised(final VoxelShape src, final Direct
shape.zMax = Math.max(shape.zMax, z + 1);

shape.storage.set(
z + y*local_len_z + x*(local_len_y*local_len_z)
z + y*local_len_z + x*shape_mul_x
);
}

Expand Down

0 comments on commit a749c72

Please sign in to comment.