mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-18 08:25:27 +01:00
fix index out of bounds for blocks at world max height
This commit is contained in:
parent
1b6b127ef4
commit
6dd175331c
@ -1,3 +1,6 @@
|
|||||||
|
Version 2.2.029
|
||||||
|
Fixed bug where block checks at world height would throw IndexOutOfBounds exceptions
|
||||||
|
|
||||||
Version 2.2.028
|
Version 2.2.028
|
||||||
Fixed stack overflow during ChunkUnloadEvent
|
Fixed stack overflow during ChunkUnloadEvent
|
||||||
Fixed a bug where you had to wait to summon another COTW summon if one or more of them had died or otherwise expired before their time limit
|
Fixed a bug where you had to wait to summon another COTW summon if one or more of them had died or otherwise expired before their time limit
|
||||||
|
@ -102,7 +102,7 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int coordToIndex(int x, int y, int z, int worldMin, int worldMax) {
|
private static int coordToIndex(int x, int y, int z, int worldMin, int worldMax) {
|
||||||
if (x < 0 || x >= 16 || y < worldMin || y >= worldMax || z < 0 || z >= 16)
|
if (x < 0 || x >= 16 || y < worldMin || y > worldMax || z < 0 || z >= 16)
|
||||||
throw new IndexOutOfBoundsException(String.format("x: %d y: %d z: %d World Min: %d World Max: %d", x, y, z, worldMin, worldMax));
|
throw new IndexOutOfBoundsException(String.format("x: %d y: %d z: %d World Min: %d World Max: %d", x, y, z, worldMin, worldMax));
|
||||||
int yOffset = -worldMin; // Ensures y multiplier remains positive
|
int yOffset = -worldMin; // Ensures y multiplier remains positive
|
||||||
return (z * 16 + x) + (256 * (y + yOffset));
|
return (z * 16 + x) + (256 * (y + yOffset));
|
||||||
|
@ -74,8 +74,13 @@ class UserBlockTrackerTest {
|
|||||||
final HashChunkManager hashChunkManager = new HashChunkManager();
|
final HashChunkManager hashChunkManager = new HashChunkManager();
|
||||||
|
|
||||||
// Top Block
|
// Top Block
|
||||||
final Block illegalHeightBlock = initMockBlock(1337, 256, -1337);
|
int illegalMaxHeight = 256 + 1;
|
||||||
|
final Block illegalHeightBlock = initMockBlock(1337, illegalMaxHeight, -1337);
|
||||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(illegalHeightBlock));
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(illegalHeightBlock));
|
||||||
|
|
||||||
|
int illegalMinHeight = -65;
|
||||||
|
final Block otherIllegalHeightBlock = initMockBlock(1337, illegalMinHeight, -1337);
|
||||||
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(otherIllegalHeightBlock));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -85,7 +90,7 @@ class UserBlockTrackerTest {
|
|||||||
int radius = 2; // Could be anything but drastically changes test time
|
int radius = 2; // Could be anything but drastically changes test time
|
||||||
|
|
||||||
for (int x = -radius; x <= radius; x++) {
|
for (int x = -radius; x <= radius; x++) {
|
||||||
for (int y = mockWorld.getMinHeight(); y < mockWorld.getMaxHeight(); y++) {
|
for (int y = mockWorld.getMinHeight(); y <= mockWorld.getMaxHeight(); y++) {
|
||||||
for (int z = -radius; z <= radius; z++) {
|
for (int z = -radius; z <= radius; z++) {
|
||||||
final Block testBlock = initMockBlock(x, y, z);
|
final Block testBlock = initMockBlock(x, y, z);
|
||||||
// mark ineligible
|
// mark ineligible
|
||||||
@ -147,7 +152,8 @@ class UserBlockTrackerTest {
|
|||||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, -1, 0));
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, -1, 0));
|
||||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, -1));
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, -1));
|
||||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(16, 0, 0));
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(16, 0, 0));
|
||||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, mockWorld.getMaxHeight(), 0));
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, mockWorld.getMaxHeight()+1, 0));
|
||||||
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, mockWorld.getMinHeight()-1, 0));
|
||||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, 16));
|
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user