That division code is correct. Here’s a small test program:
[java] static private int blockIndex(float coord, float chunkSize) {
return (int) Math.floor(coord / chunkSize);
}
static private void test(float a, float b) {
System.out.println("a: " + a + ", b: " + b + ", chunked: " + blockIndex(a, b));
}
public static void main(String[] args) {
for (int i = -4; i < 4; i++) {
test((float) i - 0.1f, 2.0f);
test((float) i + 0.1f, 2.0f);
}
}
[/java]
(I’m intentionally not testing the exact borders, as these will usually be prone to round-off errors.)
Things I can think of:
- You are assuming your code is testing coordinates at -4.0, -3.0, etc., but in reality some round-off error made it slightly less than your assumption for negative values and slightly above for positive ones.
- You are feeding off-by-one negative values to the division.
- settings.getChunkSizeX() returns a negative value for negative block locations (that’s not reasonably possible in the code you posted, but I bet you simplified it).
- getX returns an absolute value, and some code you didn’t show negates the sign afterwards.