diff --git a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/ChunkdataPacketTest.java b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/ChunkdataPacketTest.java index 5060676..18dbac9 100644 --- a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/ChunkdataPacketTest.java +++ b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/ChunkdataPacketTest.java @@ -1,6 +1,5 @@ package mc.core.network.proto_1_12_2.packets; -import com.google.common.io.ByteStreams; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; import mc.core.world.Biome; import mc.core.world.World; @@ -9,6 +8,7 @@ import mc.core.world.block.BlockFactory; import mc.core.world.block.BlockType; import mc.core.world.chunk.Chunk; import mc.core.world.chunk.ChunkSection; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,6 +18,7 @@ import java.io.InputStream; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,51 +30,61 @@ class ChunkdataPacketTest { @BeforeAll static void beforeClassTest() throws IOException { InputStream inputStream = ChunkdataPacketTest.class.getResourceAsStream("ChunkDataPacket.bin"); - expectedPacketData = ByteStreams.toByteArray(inputStream); + assertNotNull(inputStream); + expectedPacketData = IOUtils.toByteArray(inputStream); + assertEquals(12571, expectedPacketData.length); + } + + private ChunkSection createChunkSection(int height) { + final ChunkSection chunkSection = mock(ChunkSection.class); + when(chunkSection.getBiomeLocal(anyInt(), anyInt())).thenReturn(Biome.PLAINS); + when(chunkSection.getSkyLightLocal(anyInt(), anyInt(), anyInt())).thenReturn(0); + when(chunkSection.getY()).thenReturn(height); + + if (height == 0) { + when(chunkSection.getBlockLocal(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { + Object[] args = invocation.getArguments(); + int x = (int) args[0]; + int y = (int) args[1]; + int z = (int) args[2]; + + BlockFactory blockFactory = new BlockFactory(); + + if (y == 0) return blockFactory.create(BlockType.BEDROCK, x, y, z); + else return blockFactory.create(BlockType.DIRT, x, y, z); + }); + } else { + when(chunkSection.getBlockLocal(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { + Object[] args = invocation.getArguments(); + int x = (int) args[0]; + int y = (int) args[1]; + int z = (int) args[2]; + + BlockFactory blockFactory = new BlockFactory(); + + if (y < 15) return blockFactory.create(BlockType.DIRT, x, y, z); + else return blockFactory.create(BlockType.GRASS, x, y, z); + }); + } + + return chunkSection; } @BeforeEach void prepareWorld() { - final ChunkSection chunkSection = mock(ChunkSection.class); - when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { - int y = (int)invocation.getArguments()[1]; + final ChunkSection chunkSection0 = createChunkSection(0); + final ChunkSection chunkSection1 = createChunkSection(1); - if (y <= 3) return 0; - else return 15; - }); - when(chunkSection.getBiome(anyInt(), anyInt())).thenReturn(Biome.PLAINS); - when(chunkSection.getBlock(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { - Object[] args = invocation.getArguments(); - int x = (int) args[0]; - int y = (int) args[1]; - int z = (int) args[2]; - - BlockFactory blockFactory = new BlockFactory(); - - if (y == 0) return blockFactory.create(BlockType.BEDROCK, x, y, z); - else if (y >= 1 && y <= 2) return blockFactory.create(BlockType.DIRT, x, y, z); - else if (y == 3) return blockFactory.create(BlockType.GRASS, x, y, z); - else return blockFactory.create(BlockType.AIR, x, y, z); - }); + final Chunk chunk = mock(Chunk.class); + when(chunk.getX()).thenReturn(0); + when(chunk.getZ()).thenReturn(0); + when(chunk.getBiomeLocal(anyInt(), anyInt())).thenReturn(Biome.PLAINS); + when(chunk.getChunkSection(0)).thenReturn(chunkSection0); + when(chunk.getChunkSection(1)).thenReturn(chunkSection1); world = mock(World.class); when(world.getWorldType()).thenReturn(WorldType.FLAT); - when(world.getChunk(anyInt(), anyInt())).thenAnswer(invocation -> { - Object[] args = invocation.getArguments(); - - Chunk chunk = mock(Chunk.class); - when(chunk.getX()).thenReturn((int) args[0]); - when(chunk.getZ()).thenReturn((int) args[1]); - when(chunk.getBiome(anyInt(), anyInt())).thenReturn(Biome.PLAINS); - when(chunk.getChunkSection(anyInt())).thenAnswer(invocation1 -> { - int height = (int)invocation1.getArguments()[0]; - - if (height < 1) return chunkSection; - else return null; - }); - - return chunk; - }); + when(world.getChunk(0, 0)).thenReturn(chunk); } @Test diff --git a/proto_1.12.2/src/test/resources/mc/core/network/proto_1_12_2/packets/ChunkDataPacket.bin b/proto_1.12.2/src/test/resources/mc/core/network/proto_1_12_2/packets/ChunkDataPacket.bin index fcfd0c0..d0acd42 100644 Binary files a/proto_1.12.2/src/test/resources/mc/core/network/proto_1_12_2/packets/ChunkDataPacket.bin and b/proto_1.12.2/src/test/resources/mc/core/network/proto_1_12_2/packets/ChunkDataPacket.bin differ