обновлен ChunkDataPacketTest
проверка чанка с более 16 типами блоков
This commit is contained in:
Binary file not shown.
@@ -17,7 +17,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -28,13 +28,13 @@ import static org.mockito.Mockito.*;
|
|||||||
class ChunkDataPacketTest {
|
class ChunkDataPacketTest {
|
||||||
private static List<Pair<DumbChunkData, DumbChunkData>> listOfParams;
|
private static List<Pair<DumbChunkData, DumbChunkData>> listOfParams;
|
||||||
|
|
||||||
private static DumbChunkData createExpectedData() throws IOException {
|
private static DumbChunkData createExpectedData(String xz) throws IOException {
|
||||||
InputStream inputStream = ChunkDataPacketTest.class.getResourceAsStream("ChunkDataPacket.bin");
|
InputStream inputStream = ChunkDataPacketTest.class.getResourceAsStream(String.format("ChunkDataPacket%s.bin", xz));
|
||||||
assertNotNull(inputStream);
|
assertNotNull(inputStream);
|
||||||
return DumbChunkData.ReadFromNetInputStream(IOUtils.toByteArray(inputStream));
|
return DumbChunkData.ReadFromNetInputStream(IOUtils.toByteArray(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Block createChestBlock(BlockType type, int x, int y, int z, int height) {
|
private static Block createChestBlock00(BlockType type, int x, int y, int z, int height) {
|
||||||
final BlockLocation location = new BlockLocation(x, y, z);
|
final BlockLocation location = new BlockLocation(x, y, z);
|
||||||
|
|
||||||
final CompoundMap compoundMap = new CompoundMap();
|
final CompoundMap compoundMap = new CompoundMap();
|
||||||
@@ -57,7 +57,7 @@ class ChunkDataPacketTest {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChunkSection createChunkSection(int height) {
|
private static ChunkSection createChunkSection00(int height) {
|
||||||
final ChunkSection chunkSection = mock(ChunkSection.class);
|
final ChunkSection chunkSection = mock(ChunkSection.class);
|
||||||
when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenReturn(0);
|
when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenReturn(0);
|
||||||
when(chunkSection.getY()).thenReturn(height);
|
when(chunkSection.getY()).thenReturn(height);
|
||||||
@@ -97,13 +97,13 @@ class ChunkDataPacketTest {
|
|||||||
else if (y == 1) return blockFactory.create(BlockType.GRASS, x, y, z);
|
else if (y == 1) return blockFactory.create(BlockType.GRASS, x, y, z);
|
||||||
else if (y == 2) {
|
else if (y == 2) {
|
||||||
if ((x == 2 || x == 4 || x == 5) && z == 1)
|
if ((x == 2 || x == 4 || x == 5) && z == 1)
|
||||||
return createChestBlock(BlockType.CHEST_NORTH, x, y, z, height);
|
return createChestBlock00(BlockType.CHEST_NORTH, x, y, z, height);
|
||||||
else if ((x == 2 || x == 3 || x == 5) && z == 6)
|
else if ((x == 2 || x == 3 || x == 5) && z == 6)
|
||||||
return createChestBlock(BlockType.CHEST_SOUTH, x, y, z, height);
|
return createChestBlock00(BlockType.CHEST_SOUTH, x, y, z, height);
|
||||||
else if (x == 1 && (z == 2 || z == 3 || z == 5))
|
else if (x == 1 && (z == 2 || z == 3 || z == 5))
|
||||||
return createChestBlock(BlockType.CHEST_WEST, x, y, z, height);
|
return createChestBlock00(BlockType.CHEST_WEST, x, y, z, height);
|
||||||
else if (x == 6 && (z == 2 || z == 4 || z == 5))
|
else if (x == 6 && (z == 2 || z == 4 || z == 5))
|
||||||
return createChestBlock(BlockType.CHEST_EAST, x, y, z, height);
|
return createChestBlock00(BlockType.CHEST_EAST, x, y, z, height);
|
||||||
else
|
else
|
||||||
return blockFactory.create(BlockType.AIR, x, y, z);
|
return blockFactory.create(BlockType.AIR, x, y, z);
|
||||||
}
|
}
|
||||||
@@ -115,9 +115,9 @@ class ChunkDataPacketTest {
|
|||||||
return chunkSection;
|
return chunkSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Chunk createMockChunk() {
|
private static Chunk createMockChunk00() {
|
||||||
final ChunkSection chunkSection0 = createChunkSection(0);
|
final ChunkSection chunkSection0 = createChunkSection00(0);
|
||||||
final ChunkSection chunkSection1 = createChunkSection(1);
|
final ChunkSection chunkSection1 = createChunkSection00(1);
|
||||||
|
|
||||||
final Chunk chunk = mock(Chunk.class);
|
final Chunk chunk = mock(Chunk.class);
|
||||||
when(chunk.getX()).thenReturn(0);
|
when(chunk.getX()).thenReturn(0);
|
||||||
@@ -129,6 +129,68 @@ class ChunkDataPacketTest {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ChunkSection createChunkSection01() {
|
||||||
|
final ChunkSection chunkSection = mock(ChunkSection.class);
|
||||||
|
when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenReturn(0);
|
||||||
|
when(chunkSection.getY()).thenReturn(0);
|
||||||
|
|
||||||
|
final List<BlockType> types = Arrays.asList(
|
||||||
|
BlockType.CLAY,
|
||||||
|
BlockType.ORE_REDSTONE,
|
||||||
|
BlockType.ORE_DIAMOND,
|
||||||
|
BlockType.OBSIDIAN,
|
||||||
|
BlockType.MOSS_STONE,
|
||||||
|
BlockType.SANDSTONE,
|
||||||
|
BlockType.ORE_LAPIS,
|
||||||
|
BlockType.WOOD_JUNGLE,
|
||||||
|
BlockType.WOOD_BIRCH,
|
||||||
|
BlockType.WOOD_SPRUCE,
|
||||||
|
BlockType.WOOD_OAK,
|
||||||
|
BlockType.ORE_COAL,
|
||||||
|
BlockType.ORE_IRON,
|
||||||
|
BlockType.ORE_GOLD,
|
||||||
|
BlockType.GRAVEL,
|
||||||
|
BlockType.SAND
|
||||||
|
);
|
||||||
|
|
||||||
|
when(chunkSection.getBlock(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||||
|
Object[] args = invocation.getArguments();
|
||||||
|
final int x = (int) args[0];
|
||||||
|
final int y = (int) args[1];
|
||||||
|
final int z = (int) args[2];
|
||||||
|
|
||||||
|
BlockFactory blockFactory = new BlockFactory();
|
||||||
|
|
||||||
|
if (y == 0) {
|
||||||
|
// @formatter:off
|
||||||
|
if (x == 0 && z == 0) return blockFactory.create(BlockType.STONE, x, y, z);
|
||||||
|
else if (x == 15 && z == 0) return blockFactory.create(BlockType.GRANITE, x, y, z);
|
||||||
|
else if (x == 0 && z == 15) return blockFactory.create(BlockType.POLISHED_GRANITE, x, y, z);
|
||||||
|
else if (x == 15 && z == 15) return blockFactory.create(BlockType.DIORITE, x, y, z);
|
||||||
|
else return blockFactory.create(BlockType.BEDROCK, x, y, z);
|
||||||
|
// @formatter:on
|
||||||
|
} else if (y == 1) {
|
||||||
|
return blockFactory.create(types.get(x), x, y, z);
|
||||||
|
} else {
|
||||||
|
return blockFactory.create(BlockType.AIR, x, y, z);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return chunkSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Chunk createMockChunk01() {
|
||||||
|
final ChunkSection chunkSection0 = createChunkSection01();
|
||||||
|
|
||||||
|
final Chunk chunk = mock(Chunk.class);
|
||||||
|
when(chunk.getX()).thenReturn(0);
|
||||||
|
when(chunk.getZ()).thenReturn(1);
|
||||||
|
when(chunk.getBiome(anyInt(), anyInt())).thenReturn(Biome.PLAINS);
|
||||||
|
when(chunk.getChunkSection(0)).thenReturn(chunkSection0);
|
||||||
|
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
private static void verifyMock(Chunk chunk) {
|
private static void verifyMock(Chunk chunk) {
|
||||||
verify(chunk, atLeast(1)).getX();
|
verify(chunk, atLeast(1)).getX();
|
||||||
verify(chunk, atLeast(1)).getZ();
|
verify(chunk, atLeast(1)).getZ();
|
||||||
@@ -136,9 +198,7 @@ class ChunkDataPacketTest {
|
|||||||
verify(chunk, atLeast(2)).getChunkSection(anyInt());
|
verify(chunk, atLeast(2)).getChunkSection(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DumbChunkData createActualData() {
|
private static DumbChunkData createActualData(Chunk chunk) {
|
||||||
Chunk chunk = createMockChunk();
|
|
||||||
|
|
||||||
ChunkDataPacket packet = new ChunkDataPacket();
|
ChunkDataPacket packet = new ChunkDataPacket();
|
||||||
packet.setX(chunk.getX());
|
packet.setX(chunk.getX());
|
||||||
packet.setZ(chunk.getZ());
|
packet.setZ(chunk.getZ());
|
||||||
@@ -155,8 +215,10 @@ class ChunkDataPacketTest {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void beforeClassTest() throws IOException {
|
static void beforeClassTest() throws IOException {
|
||||||
listOfParams = new ArrayList<>();
|
listOfParams = Arrays.asList(
|
||||||
listOfParams.add(new Pair<>(createExpectedData(), createActualData()));
|
new Pair<>(createExpectedData("00"), createActualData(createMockChunk00())),
|
||||||
|
new Pair<>(createExpectedData("01"), createActualData(createMockChunk01()))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> streamArguments() {
|
private static Stream<Arguments> streamArguments() {
|
||||||
@@ -164,18 +226,18 @@ class ChunkDataPacketTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("testGeneral")
|
@DisplayName("testGeneral")
|
||||||
@ParameterizedTest(name = "[{index}] => {0}")
|
@ParameterizedTest(name = "[{index}] {0}")
|
||||||
@MethodSource("streamArguments")
|
@MethodSource("streamArguments")
|
||||||
void testGeneral(DumbChunkData expected, DumbChunkData actual) {
|
void testGeneral(DumbChunkData expected, DumbChunkData actual) {
|
||||||
assertEquals(expected.getX(), actual.getX());
|
assertEquals(expected.getX(), actual.getX(), "X coord not equals");
|
||||||
assertEquals(expected.getZ(), actual.getZ());
|
assertEquals(expected.getZ(), actual.getZ(), "Z coord not equals");
|
||||||
assertEquals(expected.isInitChunk(), actual.isInitChunk());
|
assertEquals(expected.isInitChunk(), actual.isInitChunk(), "Flag init chunk not equals");
|
||||||
assertEquals(expected.getBitMask(), actual.getBitMask());
|
assertEquals(expected.getBitMask(), actual.getBitMask(), "BitMask not equals");
|
||||||
assertArrayEquals(expected.getBiomes(), actual.getBiomes());
|
assertArrayEquals(expected.getBiomes(), actual.getBiomes(), "Biomes not equals");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("testNBT")
|
@DisplayName("testNBT")
|
||||||
@ParameterizedTest(name = "[{index}] => {0}")
|
@ParameterizedTest(name = "[{index}] {0}")
|
||||||
@MethodSource("streamArguments")
|
@MethodSource("streamArguments")
|
||||||
void testNBT(DumbChunkData expected, DumbChunkData actual) {
|
void testNBT(DumbChunkData expected, DumbChunkData actual) {
|
||||||
assertEquals(expected.getNumberNBT(), actual.getNumberNBT());
|
assertEquals(expected.getNumberNBT(), actual.getNumberNBT());
|
||||||
@@ -187,7 +249,7 @@ class ChunkDataPacketTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("testData (disabled light test)")
|
@DisplayName("testData (disabled light test)")
|
||||||
@ParameterizedTest(name = "[{index}] => {0}")
|
@ParameterizedTest(name = "[{index}] {0}")
|
||||||
@MethodSource("streamArguments")
|
@MethodSource("streamArguments")
|
||||||
void testData(DumbChunkData expected, DumbChunkData actual) {
|
void testData(DumbChunkData expected, DumbChunkData actual) {
|
||||||
assertEquals(expected.getData().length, actual.getData().length);
|
assertEquals(expected.getData().length, actual.getData().length);
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ class DumbChunkData {
|
|||||||
idxBlock = (int)(data.get(startLong) >> startOffset);
|
idxBlock = (int)(data.get(startLong) >> startOffset);
|
||||||
} else {
|
} else {
|
||||||
int endOffset = 64 - startOffset;
|
int endOffset = 64 - startOffset;
|
||||||
idxBlock = (int)(data.get(startLong) >> startOffset | data.get(endLong) << endOffset);
|
long mask = (1 << endOffset) - 1;
|
||||||
|
idxBlock = (int)(((data.get(startLong) >> startOffset) & mask) | data.get(endLong) << endOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
dumbChunkSection.data.add(dumbChunkSection.palette.get(idxBlock & bitMask));
|
dumbChunkSection.data.add(dumbChunkSection.palette.get(idxBlock & bitMask));
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user