remove duplicate file
This commit is contained in:
@@ -1,236 +0,0 @@
|
|||||||
package mc.core.network.proto_1_12_2.packets;
|
|
||||||
|
|
||||||
import com.flowpowered.nbt.*;
|
|
||||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
|
||||||
import mc.core.network.proto_1_12_2.packets.DumbChunkData.DumbChunkSection;
|
|
||||||
import mc.core.world.Biome;
|
|
||||||
import mc.core.world.block.*;
|
|
||||||
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.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@Disabled //FIXME
|
|
||||||
class ChunkDataPacketTest {
|
|
||||||
private static DumbChunkData expectedDumbChunkData;
|
|
||||||
private static DumbChunkData actualDumbChunkData;
|
|
||||||
|
|
||||||
private static void setupExpectedData() throws IOException {
|
|
||||||
InputStream inputStream = ChunkDataPacketTest.class.getResourceAsStream("ChunkDataPacket.bin");
|
|
||||||
assertNotNull(inputStream);
|
|
||||||
expectedDumbChunkData = DumbChunkData.ReadFromNetInputStream(IOUtils.toByteArray(inputStream));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Chunk createMockChunk() {
|
|
||||||
final ChunkSection chunkSection0 = createChunkSection(0);
|
|
||||||
final ChunkSection chunkSection1 = createChunkSection(1);
|
|
||||||
|
|
||||||
final Chunk chunk = mock(Chunk.class);
|
|
||||||
when(chunk.getX()).thenReturn(0);
|
|
||||||
when(chunk.getZ()).thenReturn(0);
|
|
||||||
when(chunk.getBiome(anyInt(), anyInt())).thenReturn(Biome.PLAINS);
|
|
||||||
when(chunk.getChunkSection(0)).thenReturn(chunkSection0);
|
|
||||||
when(chunk.getChunkSection(1)).thenReturn(chunkSection1);
|
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void verifyMock(Chunk chunk) {
|
|
||||||
verify(chunk).getX();
|
|
||||||
verify(chunk).getZ();
|
|
||||||
verify(chunk, times(256)).getBiome(anyInt(), anyInt());
|
|
||||||
verify(chunk, atLeast(2)).getChunkSection(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupActualData() {
|
|
||||||
Chunk chunk = createMockChunk();
|
|
||||||
|
|
||||||
ChunkDataPacket packet = new ChunkDataPacket();
|
|
||||||
packet.setX(chunk.getX());
|
|
||||||
packet.setZ(chunk.getZ());
|
|
||||||
packet.setChunk(chunk);
|
|
||||||
packet.setInitChunk(true);
|
|
||||||
|
|
||||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
|
||||||
packet.writeSelf(netStream);
|
|
||||||
|
|
||||||
verifyMock(chunk);
|
|
||||||
|
|
||||||
actualDumbChunkData = DumbChunkData.ReadFromNetInputStream(netStream.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void beforeClassTest() throws IOException {
|
|
||||||
setupExpectedData();
|
|
||||||
setupActualData(); // FIXME тест валится здесь
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Block createChestBlock(BlockType type, int x, int y, int z, int height) {
|
|
||||||
final BlockLocation location = new BlockLocation(x, y, z);
|
|
||||||
|
|
||||||
final CompoundMap compoundMap = new CompoundMap();
|
|
||||||
compoundMap.put(new IntTag("x", x));
|
|
||||||
compoundMap.put(new IntTag("y", (height << 4) + y));
|
|
||||||
compoundMap.put(new IntTag("z", z));
|
|
||||||
compoundMap.put(new StringTag("id", type.getNamedId()));
|
|
||||||
final CompoundTag compoundTag = new CompoundTag("", compoundMap);
|
|
||||||
|
|
||||||
return new AbstractBlock(type) {
|
|
||||||
@Override
|
|
||||||
public BlockLocation getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundTag getNBTData() {
|
|
||||||
return compoundTag;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ChunkSection createChunkSection(int height) {
|
|
||||||
final ChunkSection chunkSection = mock(ChunkSection.class);
|
|
||||||
when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenReturn(0);
|
|
||||||
when(chunkSection.getY()).thenReturn(height);
|
|
||||||
|
|
||||||
if (height == 0) {
|
|
||||||
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 {
|
|
||||||
return blockFactory.create(BlockType.STONE, x, y, z);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
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();
|
|
||||||
|
|
||||||
// @formatter:off
|
|
||||||
if (y == 0) return blockFactory.create(BlockType.DIRT, x, y, z);
|
|
||||||
else if (y == 1) return blockFactory.create(BlockType.GRASS, x, y, z);
|
|
||||||
else if (y == 2) {
|
|
||||||
if ((x == 2 || x == 4 || x == 5) && z == 1)
|
|
||||||
return createChestBlock(BlockType.CHEST_NORTH, x, y, z, height);
|
|
||||||
else if ((x == 2 || x == 3 || x == 5) && z == 6)
|
|
||||||
return createChestBlock(BlockType.CHEST_SOUTH, x, y, z, height);
|
|
||||||
else if (x == 1 && (z == 2 || z == 3 || z == 5))
|
|
||||||
return createChestBlock(BlockType.CHEST_WEST, x, y, z, height);
|
|
||||||
else if (x == 6 && (z == 2 || z == 4 || z == 5))
|
|
||||||
return createChestBlock(BlockType.CHEST_EAST, x, y, z, height);
|
|
||||||
else
|
|
||||||
return blockFactory.create(BlockType.AIR, x, y, z);
|
|
||||||
}
|
|
||||||
else return blockFactory.create(BlockType.AIR, x, y, z);
|
|
||||||
// @formatter:on
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunkSection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGeneral() {
|
|
||||||
assertEquals(expectedDumbChunkData.getX(), actualDumbChunkData.getX());
|
|
||||||
assertEquals(expectedDumbChunkData.getZ(), actualDumbChunkData.getZ());
|
|
||||||
assertEquals(expectedDumbChunkData.isInitChunk(), actualDumbChunkData.isInitChunk());
|
|
||||||
assertEquals(expectedDumbChunkData.getBitMask(), actualDumbChunkData.getBitMask());
|
|
||||||
assertArrayEquals(expectedDumbChunkData.getBiomes(), actualDumbChunkData.getBiomes());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testNBT() {
|
|
||||||
assertEquals(expectedDumbChunkData.getNumberNBT(), actualDumbChunkData.getNumberNBT());
|
|
||||||
assertEquals(expectedDumbChunkData.getNbt().size(), actualDumbChunkData.getNbt().size());
|
|
||||||
|
|
||||||
for (Tag<?> tag : actualDumbChunkData.getNbt()) {
|
|
||||||
assertTrue(expectedDumbChunkData.getNbt().contains(tag));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testData() {
|
|
||||||
assertEquals(expectedDumbChunkData.getData().length, actualDumbChunkData.getData().length);
|
|
||||||
|
|
||||||
for (int numberSection = 0; numberSection < expectedDumbChunkData.getData().length; numberSection++) {
|
|
||||||
final DumbChunkSection expectedDumbChunkSection = expectedDumbChunkData.getData()[numberSection];
|
|
||||||
final DumbChunkSection actualDumbChunkSection = actualDumbChunkData.getData()[numberSection];
|
|
||||||
|
|
||||||
// Palette
|
|
||||||
testPalette(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
|
|
||||||
|
|
||||||
// Data
|
|
||||||
testDataBlock(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
|
|
||||||
|
|
||||||
// Block and Sky light
|
|
||||||
// DISABLE //
|
|
||||||
//testLight(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testPalette(DumbChunkSection expected, DumbChunkSection actual, int numberSection) {
|
|
||||||
assertEquals(expected.getBitsPerBlock(), actual.getBitsPerBlock());
|
|
||||||
|
|
||||||
if (expected.getPalette().size() > actual.getPalette().size()) {
|
|
||||||
for (int j = 0; j < actual.getPalette().size(); j++) {
|
|
||||||
assertTrue(expected.getPalette().contains(
|
|
||||||
actual.getPalette().get(j)
|
|
||||||
), String.format("[%d] Palette not contains %s", numberSection, actual.getPalette().get(j)));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int j = 0; j < expected.getPalette().size(); j++) {
|
|
||||||
assertTrue(actual.getPalette().contains(
|
|
||||||
expected.getPalette().get(j)
|
|
||||||
), String.format("[%d] Palette not contains %s", numberSection, actual.getPalette().get(j)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testDataBlock(DumbChunkSection expected, DumbChunkSection actual, int numberSection) {
|
|
||||||
assertEquals(expected.getData().size(), actual.getData().size());
|
|
||||||
|
|
||||||
for (int j = 0; j < expected.getData().size(); j++) {
|
|
||||||
assertEquals(
|
|
||||||
expected.getData().get(j),
|
|
||||||
actual.getData().get(j),
|
|
||||||
String.format("[%d] Data (blocks)", numberSection)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testLight(DumbChunkSection expected, DumbChunkSection actual, int numberSection) {
|
|
||||||
// Block light
|
|
||||||
assertArrayEquals(expected.getBlockLight(), actual.getBlockLight(),
|
|
||||||
String.format("[%d] Block light", numberSection));
|
|
||||||
|
|
||||||
// Sky light
|
|
||||||
assertArrayEquals(expected.getSkyLight(), actual.getSkyLight(),
|
|
||||||
String.format("[%d] Sky light", numberSection));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user