mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-17 13:41:24 +01:00
Remove the previous NBT library
This commit is contained in:
parent
639629ccf6
commit
407bdd8ea7
@ -25,8 +25,6 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
||||||
api group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0'
|
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
|
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||||
api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
|
api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ import net.minestom.server.gamedata.loottables.LootTable;
|
|||||||
import net.minestom.server.gamedata.loottables.LootTableManager;
|
import net.minestom.server.gamedata.loottables.LootTableManager;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
|
import net.minestom.server.utils.nbt.NbtWriter;
|
||||||
import net.minestom.server.utils.time.UpdateOption;
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
import net.querz.nbt.CompoundTag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
@ -193,7 +193,7 @@ public abstract class CustomBlock {
|
|||||||
* @param position position of the block
|
* @param position position of the block
|
||||||
* @param blockData equivalent to <pre>instance.getBlockData(position)</pre>
|
* @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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,13 +15,8 @@ import net.minestom.server.utils.Utils;
|
|||||||
import net.minestom.server.utils.buffer.BufferUtils;
|
import net.minestom.server.utils.buffer.BufferUtils;
|
||||||
import net.minestom.server.utils.buffer.BufferWrapper;
|
import net.minestom.server.utils.buffer.BufferWrapper;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||||
import net.querz.nbt.CompoundTag;
|
import net.minestom.server.utils.nbt.NbtWriter;
|
||||||
import net.querz.nbt.DoubleTag;
|
|
||||||
import net.querz.nbt.LongArrayTag;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ChunkDataPacket implements ServerPacket {
|
public class ChunkDataPacket implements ServerPacket {
|
||||||
@ -47,6 +42,8 @@ public class ChunkDataPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketWriter writer) {
|
public void write(PacketWriter writer) {
|
||||||
|
NbtWriter nbtWriter = new NbtWriter(writer);
|
||||||
|
|
||||||
writer.writeInt(chunkX);
|
writer.writeInt(chunkX);
|
||||||
writer.writeInt(chunkZ);
|
writer.writeInt(chunkZ);
|
||||||
writer.writeBoolean(fullChunk);
|
writer.writeBoolean(fullChunk);
|
||||||
@ -80,17 +77,10 @@ public class ChunkDataPacket implements ServerPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
CompoundTag compound = new CompoundTag();
|
nbtWriter.writeCompound(null, compound -> {
|
||||||
compound.put("MOTION_BLOCKING", new LongArrayTag(Utils.encodeBlocks(motionBlocking, 9)));
|
compound.writeLongArray("MOTION_BLOCKING", Utils.encodeBlocks(motionBlocking, 9));
|
||||||
compound.put("WORLD_SURFACE", new LongArrayTag(Utils.encodeBlocks(worldSurface, 9)));
|
compound.writeLongArray("WORLD_SURFACE", 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Biome data
|
// Biome data
|
||||||
@ -108,25 +98,20 @@ public class ChunkDataPacket implements ServerPacket {
|
|||||||
writer.writeVarInt(blockEntities.size());
|
writer.writeVarInt(blockEntities.size());
|
||||||
|
|
||||||
for (int index : blockEntities) {
|
for (int index : blockEntities) {
|
||||||
BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
|
final BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
|
||||||
CompoundTag blockEntity = new CompoundTag();
|
|
||||||
blockEntity.put("x", new DoubleTag(blockPosition.getX()));
|
nbtWriter.writeCompound(null, compound -> {
|
||||||
blockEntity.put("y", new DoubleTag(blockPosition.getY()));
|
compound.writeDouble("x", blockPosition.getX());
|
||||||
blockEntity.put("z", new DoubleTag(blockPosition.getZ()));
|
compound.writeDouble("y", blockPosition.getY());
|
||||||
short customBlockId = customBlocksId[index];
|
compound.writeDouble("z", blockPosition.getZ());
|
||||||
CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
|
||||||
|
final short customBlockId = customBlocksId[index];
|
||||||
|
final CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
||||||
if (customBlock != null) {
|
if (customBlock != null) {
|
||||||
Data data = blocksData.get(index);
|
Data data = blocksData.get(index);
|
||||||
customBlock.writeBlockEntity(blockPosition, data, blockEntity);
|
customBlock.writeBlockEntity(blockPosition, data, compound);
|
||||||
}
|
}
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
});
|
||||||
try {
|
|
||||||
blockEntity.serialize(new DataOutputStream(os), 100);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
byte[] d = os.toByteArray();
|
|
||||||
writer.writeBytes(d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ public class NbtWriter {
|
|||||||
packet.writeDouble(value);
|
packet.writeDouble(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: not sure
|
|
||||||
public void writeByteArray(String name, byte[] value) {
|
public void writeByteArray(String name, byte[] value) {
|
||||||
packet.writeByte(NBT_BYTE_ARRAY);
|
packet.writeByte(NBT_BYTE_ARRAY);
|
||||||
packet.writeShortSizedString(name);
|
packet.writeShortSizedString(name);
|
||||||
@ -81,4 +80,22 @@ public class NbtWriter {
|
|||||||
packet.writeByte((byte) 0x00); // End compound
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user