Fix wrong plot id calculation for negative coordinates (#3898)

This commit is contained in:
Hannes Greule 2023-01-04 12:35:12 +01:00 committed by GitHub
parent 742d78a505
commit 339ca8e30f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 36 deletions

View File

@ -114,26 +114,14 @@ public abstract class SquarePlotManager extends GridPlotManager {
end = pathWidthLower + squarePlotWorld.PLOT_WIDTH; end = pathWidthLower + squarePlotWorld.PLOT_WIDTH;
} }
int size = squarePlotWorld.PLOT_WIDTH + squarePlotWorld.ROAD_WIDTH; int size = squarePlotWorld.PLOT_WIDTH + squarePlotWorld.ROAD_WIDTH;
int idx; int dx = Math.floorDiv(x, size) + 1;
if (x < 0) { int rx = Math.floorMod(x, size);
idx = x / size; int dz = Math.floorDiv(z, size) + 1;
x = size + (x % size); int rz = Math.floorMod(z, size);
} else { if (rz <= pathWidthLower || rz > end || rx <= pathWidthLower || rx > end) {
idx = (x / size) + 1;
x = x % size;
}
int idz;
if (z < 0) {
idz = z / size;
z = size + (z % size);
} else {
idz = (z / size) + 1;
z = z % size;
}
if (z <= pathWidthLower || z > end || x <= pathWidthLower || x > end) {
return null; return null;
} else { } else {
return PlotId.of(idx, idz); return PlotId.of(dx, dz);
} }
} }
@ -180,24 +168,10 @@ public abstract class SquarePlotManager extends GridPlotManager {
} }
end = pathWidthLower + squarePlotWorld.PLOT_WIDTH; end = pathWidthLower + squarePlotWorld.PLOT_WIDTH;
} }
int dx; int dx = Math.floorDiv(x, size) + 1;
int rx; int rx = Math.floorMod(x, size);
if (x < 0) { int dz = Math.floorDiv(z, size) + 1;
dx = x / size; int rz = Math.floorMod(z, size);
rx = size + (x % size);
} else {
dx = (x / size) + 1;
rx = x % size;
}
int dz;
int rz;
if (z < 0) {
dz = z / size;
rz = size + (z % size);
} else {
dz = (z / size) + 1;
rz = z % size;
}
PlotId id = PlotId.of(dx, dz); PlotId id = PlotId.of(dx, dz);
boolean[] merged = new boolean[]{rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower}; boolean[] merged = new boolean[]{rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower};
int hash = HashUtil.hash(merged); int hash = HashUtil.hash(merged);