mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-03 18:43:43 +01:00 
			
		
		
		
	fix index out of bounds for blocks at world max height
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user