Archived
0

добавление теста ChunkDataPacket

This commit is contained in:
2018-08-16 00:30:19 +03:00
parent b4679a6536
commit 1559347186
4 changed files with 174 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ public abstract class AbstractBlock implements Block {
@Setter @Setter
private Location location; private Location location;
@Getter @Getter
private int light = 15; private int light = 0;
@Getter @Getter
private final BlockType blockType; private final BlockType blockType;
private final Map<String, Tag<?>> nbtTagsMap = new HashMap<>(); private final Map<String, Tag<?>> nbtTagsMap = new HashMap<>();

View File

@@ -0,0 +1,133 @@
package mc.core.network.proto_1_12_2.packets;
import mc.core.EntityLocation;
import mc.core.world.Biome;
import mc.core.world.World;
import mc.core.world.WorldType;
import mc.core.world.block.Block;
import mc.core.world.block.BlockFactory;
import mc.core.world.block.BlockType;
import mc.core.world.chunk.Chunk;
import mc.core.world.chunk.ChunkSection;
public class DummyWorld implements World {
private class DummyChunkSection implements ChunkSection {
@Override
public int getSkyLight(int x, int y, int z) {
if (y <= 3) return 0;
else return 15;
}
@Override
public void setSkyLight(int x, int y, int z, int lightLevel) {
}
@Override
public int getAddition(int x, int y, int z) {
return 0;
}
@Override
public void setAddition(int x, int y, int z, int value) {
}
@Override
public int getX() {
return 0;
}
@Override
public int getY() {
return 0;
}
@Override
public int getZ() {
return 0;
}
@Override
public void setBlock(Block block) {
}
@Override
public Block getBlock(int x, int y, int z) {
BlockFactory blockFactory = new BlockFactory();
if (y == 0) return blockFactory.create(BlockType.BEDROCK, x, y, z, getWorld());
else if (y >= 1 && y <= 2) return blockFactory.create(BlockType.DIRT, x, y, z, getWorld());
else if (y == 3) return blockFactory.create(BlockType.GRASS, x, y, z, getWorld());
else return blockFactory.create(BlockType.AIR, x, y, z, getWorld());
}
@Override
public World getWorld() {
return DummyWorld.this;
}
}
private class DummyChunk implements Chunk {
@Override
public World getWorld() {
return DummyWorld.this;
}
@Override
public void setWorld(World world) {
}
@Override
public ChunkSection getChunkSection(int height) {
if (height < 1) return new DummyChunkSection();
else return null;
}
@Override
public void setChunkSection(int height, ChunkSection chunkSection) {
}
@Override
public Biome getBiome(int localX, int localZ) {
return Biome.PLAINS;
}
@Override
public void setBiome(int localX, int localZ, Biome biome) {
}
@Override
public int getX() {
return 0;
}
@Override
public int getZ() {
return 0;
}
}
private final Chunk chunk = new DummyChunk();
@Override
public WorldType getWorldType() {
return WorldType.FLAT;
}
@Override
public EntityLocation getSpawn() {
return null;
}
@Override
public void setSpawn(EntityLocation location) {
}
@Override
public Chunk getChunk(int x, int z) {
return chunk;
}
@Override
public void setChunk(int x, int z, Chunk chunk) {
}
}

View File

@@ -0,0 +1,40 @@
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.World;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.*;
public class TestChunkdataPacket {
private static byte[] expectedPacketData;
@BeforeClass
public static void beforeClassTest() throws IOException {
InputStream inputStream = TestChunkdataPacket.class.getResourceAsStream("ChunkDataPacket.bin");
expectedPacketData = ByteStreams.toByteArray(inputStream);
}
private World createDummyWorld() {
return new DummyWorld();
}
@Test
public void test() {
ChunkDataPacket packet = new ChunkDataPacket();
packet.setX(0);
packet.setZ(0);
packet.setChunk(createDummyWorld().getChunk(0, 0));
packet.setInitChunk(true);
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
packet.writeSelf(netStream);
byte[] actualPacketData = netStream.toByteArray();
Assert.assertEquals(expectedPacketData.length, actualPacketData.length);
Assert.assertArrayEquals(expectedPacketData, actualPacketData);
}
}