Skip to content

Commit

Permalink
Fix structure locating (integer overflow)
Browse files Browse the repository at this point in the history
  • Loading branch information
xpple committed Nov 5, 2024
1 parent 8f2a4f1 commit 799f10e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ private static int locateStructure(CustomClientCommandSource source, int structu
int regionSize = StructureConfig.regionSize(structureConfig) << 4;
SpiralLoop.spiral(center.getX() / regionSize, center.getZ() / regionSize, Level.MAX_LEVEL_SIZE / regionSize, (x, z) -> {
MemorySegment structurePos = Pos.allocate(arena);
int valid = Cubiomes.getStructurePos(structure, version, seed, x, z, structurePos);
if (valid == 0) {
if (Cubiomes.getStructurePos(structure, version, seed, x, z, structurePos) == 0) {
return false;
}
if (Cubiomes.isViableStructurePos(structure, generator, Pos.x(structurePos), Pos.z(structurePos), 0) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/xpple/seedmapper/util/SpiralLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void spiral(final int centerX, final int centerZ, final int radius
int x = centerX, dx = 0, z = centerZ, dz = -step;
final int leftBoundX = centerX - radius, rightBoundX = centerX + radius;
final int bottomBoundZ = centerZ - radius, topBoundZ = centerZ + radius;
final int max = (2 * radius + 1) * (2 * radius + 1);
final long max = (2L * radius + 1) * (2L * radius + 1);
for (int i = 0; i < max ; i++) {
if (leftBoundX <= x && x <= rightBoundX && bottomBoundZ <= z && z <= topBoundZ) {
if (callback.consume(x, z)) {
Expand Down

0 comments on commit 799f10e

Please sign in to comment.