mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 14:37:31 +02:00
Use a byte array to avoid synchronization
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
972e15a62b
commit
f12b1e1e58
@ -185,7 +185,7 @@ public class DynamicChunk extends Chunk {
|
||||
ChunkDataPacket packet = new ChunkDataPacket();
|
||||
packet.chunkX = chunkX;
|
||||
packet.chunkZ = chunkZ;
|
||||
packet.chunkData = new ChunkData(heightmapsNBT, writer.getBuffer().flip(), entries);
|
||||
packet.chunkData = new ChunkData(heightmapsNBT, writer.toByteArray(), entries);
|
||||
packet.lightData = createLightData();
|
||||
return packet;
|
||||
}
|
||||
|
@ -10,28 +10,27 @@ import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ChunkData implements Writeable {
|
||||
private final NBTCompound heightmaps;
|
||||
private final ByteBuffer data;
|
||||
private final byte[] data;
|
||||
private final Map<Integer, Block> blockEntities;
|
||||
|
||||
public ChunkData(NBTCompound heightmaps, ByteBuffer data, Map<Integer, Block> blockEntities) {
|
||||
public ChunkData(NBTCompound heightmaps, byte[] data, Map<Integer, Block> blockEntities) {
|
||||
this.heightmaps = heightmaps.deepClone();
|
||||
this.data = data.asReadOnlyBuffer();
|
||||
this.data = data.clone();
|
||||
this.blockEntities = Map.copyOf(blockEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Heightmaps
|
||||
writer.writeNBT("", this.heightmaps);
|
||||
// Data
|
||||
writer.writeVarInt(data.position(0).remaining());
|
||||
writer.write(data);
|
||||
writer.writeVarInt(data.length);
|
||||
writer.writeBytes(data);
|
||||
// Block entities
|
||||
writer.writeVarInt(blockEntities.size());
|
||||
for (var entry : blockEntities.entrySet()) {
|
||||
|
Loading…
Reference in New Issue
Block a user