diff --git a/Changelog.txt b/Changelog.txt index 1a619ee47..f847b9e0a 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +Version 2.2.029 + Fixed bug where block checks at world height would throw IndexOutOfBounds exceptions + Version 2.2.028 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 diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/BitSetChunkStore.java b/src/main/java/com/gmail/nossr50/util/blockmeta/BitSetChunkStore.java index a25f60beb..2142fa81c 100644 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/BitSetChunkStore.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/BitSetChunkStore.java @@ -102,7 +102,7 @@ public class BitSetChunkStore implements ChunkStore { } 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)); int yOffset = -worldMin; // Ensures y multiplier remains positive return (z * 16 + x) + (256 * (y + yOffset)); diff --git a/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java b/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java index a522b3585..553b82a1b 100644 --- a/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java +++ b/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java @@ -74,8 +74,13 @@ class UserBlockTrackerTest { final HashChunkManager hashChunkManager = new HashChunkManager(); // 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)); + + int illegalMinHeight = -65; + final Block otherIllegalHeightBlock = initMockBlock(1337, illegalMinHeight, -1337); + Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(otherIllegalHeightBlock)); } @Test @@ -85,7 +90,7 @@ class UserBlockTrackerTest { int radius = 2; // Could be anything but drastically changes test time 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++) { final Block testBlock = initMockBlock(x, y, z); // mark ineligible @@ -147,7 +152,8 @@ class UserBlockTrackerTest { Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, -1, 0)); Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, -1)); 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)); }