Remove the previous NBT library

This commit is contained in:
Felix Cravic 2020-05-30 00:25:07 +02:00
parent 639629ccf6
commit 407bdd8ea7
4 changed files with 41 additions and 41 deletions

View File

@ -25,8 +25,6 @@ dependencies {
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
api group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0'
api 'com.github.Querz:NBT:4.1'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'

View File

@ -7,8 +7,8 @@ import net.minestom.server.gamedata.loottables.LootTable;
import net.minestom.server.gamedata.loottables.LootTableManager;
import net.minestom.server.instance.Instance;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.nbt.NbtWriter;
import net.minestom.server.utils.time.UpdateOption;
import net.querz.nbt.CompoundTag;
/**
* TODO
@ -193,7 +193,7 @@ public abstract class CustomBlock {
* @param position position of the block
* @param blockData equivalent to <pre>instance.getBlockData(position)</pre>
*/
public void writeBlockEntity(BlockPosition position, Data blockData, CompoundTag nbt) {
public void writeBlockEntity(BlockPosition position, Data blockData, NbtWriter nbt) {
}
/**

View File

@ -15,13 +15,8 @@ import net.minestom.server.utils.Utils;
import net.minestom.server.utils.buffer.BufferUtils;
import net.minestom.server.utils.buffer.BufferWrapper;
import net.minestom.server.utils.chunk.ChunkUtils;
import net.querz.nbt.CompoundTag;
import net.querz.nbt.DoubleTag;
import net.querz.nbt.LongArrayTag;
import net.minestom.server.utils.nbt.NbtWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Set;
public class ChunkDataPacket implements ServerPacket {
@ -47,6 +42,8 @@ public class ChunkDataPacket implements ServerPacket {
@Override
public void write(PacketWriter writer) {
NbtWriter nbtWriter = new NbtWriter(writer);
writer.writeInt(chunkX);
writer.writeInt(chunkZ);
writer.writeBoolean(fullChunk);
@ -80,17 +77,10 @@ public class ChunkDataPacket implements ServerPacket {
}
{
CompoundTag compound = new CompoundTag();
compound.put("MOTION_BLOCKING", new LongArrayTag(Utils.encodeBlocks(motionBlocking, 9)));
compound.put("WORLD_SURFACE", new LongArrayTag(Utils.encodeBlocks(worldSurface, 9)));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
compound.serialize(new DataOutputStream(outputStream), 100);
} catch (IOException e) {
e.printStackTrace();
}
byte[] data = outputStream.toByteArray();
writer.writeBytes(data);
nbtWriter.writeCompound(null, compound -> {
compound.writeLongArray("MOTION_BLOCKING", Utils.encodeBlocks(motionBlocking, 9));
compound.writeLongArray("WORLD_SURFACE", Utils.encodeBlocks(worldSurface, 9));
});
}
// Biome data
@ -108,25 +98,20 @@ public class ChunkDataPacket implements ServerPacket {
writer.writeVarInt(blockEntities.size());
for (int index : blockEntities) {
BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
CompoundTag blockEntity = new CompoundTag();
blockEntity.put("x", new DoubleTag(blockPosition.getX()));
blockEntity.put("y", new DoubleTag(blockPosition.getY()));
blockEntity.put("z", new DoubleTag(blockPosition.getZ()));
short customBlockId = customBlocksId[index];
CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
if (customBlock != null) {
Data data = blocksData.get(index);
customBlock.writeBlockEntity(blockPosition, data, blockEntity);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
blockEntity.serialize(new DataOutputStream(os), 100);
} catch (IOException e) {
e.printStackTrace();
}
byte[] d = os.toByteArray();
writer.writeBytes(d);
final BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
nbtWriter.writeCompound(null, compound -> {
compound.writeDouble("x", blockPosition.getX());
compound.writeDouble("y", blockPosition.getY());
compound.writeDouble("z", blockPosition.getZ());
final short customBlockId = customBlocksId[index];
final CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
if (customBlock != null) {
Data data = blocksData.get(index);
customBlock.writeBlockEntity(blockPosition, data, compound);
}
});
}
}

View File

@ -48,7 +48,6 @@ public class NbtWriter {
packet.writeDouble(value);
}
// FIXME: not sure
public void writeByteArray(String name, byte[] value) {
packet.writeByte(NBT_BYTE_ARRAY);
packet.writeShortSizedString(name);
@ -81,4 +80,22 @@ public class NbtWriter {
packet.writeByte((byte) 0x00); // End compound
}
public void writeIntArray(String name, int[] value) {
packet.writeByte(NBT_INT_ARRAY);
packet.writeShortSizedString(name);
packet.writeInt(value.length);
for (int val : value) {
packet.writeInt(val);
}
}
public void writeLongArray(String name, long[] value) {
packet.writeByte(NBT_LONG_ARRAY);
packet.writeShortSizedString(name);
packet.writeInt(value.length);
for (long val : value) {
packet.writeLong(val);
}
}
}