mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 15:07:36 +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();
|
ChunkDataPacket packet = new ChunkDataPacket();
|
||||||
packet.chunkX = chunkX;
|
packet.chunkX = chunkX;
|
||||||
packet.chunkZ = chunkZ;
|
packet.chunkZ = chunkZ;
|
||||||
packet.chunkData = new ChunkData(heightmapsNBT, writer.getBuffer().flip(), entries);
|
packet.chunkData = new ChunkData(heightmapsNBT, writer.toByteArray(), entries);
|
||||||
packet.lightData = createLightData();
|
packet.lightData = createLightData();
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -10,28 +10,27 @@ import net.minestom.server.utils.chunk.ChunkUtils;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public final class ChunkData implements Writeable {
|
public final class ChunkData implements Writeable {
|
||||||
private final NBTCompound heightmaps;
|
private final NBTCompound heightmaps;
|
||||||
private final ByteBuffer data;
|
private final byte[] data;
|
||||||
private final Map<Integer, Block> blockEntities;
|
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.heightmaps = heightmaps.deepClone();
|
||||||
this.data = data.asReadOnlyBuffer();
|
this.data = data.clone();
|
||||||
this.blockEntities = Map.copyOf(blockEntities);
|
this.blockEntities = Map.copyOf(blockEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
// Heightmaps
|
// Heightmaps
|
||||||
writer.writeNBT("", this.heightmaps);
|
writer.writeNBT("", this.heightmaps);
|
||||||
// Data
|
// Data
|
||||||
writer.writeVarInt(data.position(0).remaining());
|
writer.writeVarInt(data.length);
|
||||||
writer.write(data);
|
writer.writeBytes(data);
|
||||||
// Block entities
|
// Block entities
|
||||||
writer.writeVarInt(blockEntities.size());
|
writer.writeVarInt(blockEntities.size());
|
||||||
for (var entry : blockEntities.entrySet()) {
|
for (var entry : blockEntities.entrySet()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user