mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 22:47:41 +02:00
Pushing what I have in case someone wants to finish it before I find the motivation to
This commit is contained in:
parent
930054385f
commit
098a58a500
@ -2,6 +2,7 @@ package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.data.Data;
|
||||
@ -14,6 +15,7 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.BufUtils;
|
||||
import net.minestom.server.utils.Utils;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.cache.CacheablePacket;
|
||||
import net.minestom.server.utils.cache.TemporaryCache;
|
||||
@ -22,8 +24,11 @@ import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -53,6 +58,10 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
private final UUID identifier;
|
||||
private final long timestamp;
|
||||
|
||||
private ChunkDataPacket() {
|
||||
this(new UUID(0, 0), 0);
|
||||
}
|
||||
|
||||
public ChunkDataPacket(@Nullable UUID identifier, long timestamp) {
|
||||
this.identifier = identifier;
|
||||
this.timestamp = timestamp;
|
||||
@ -82,6 +91,7 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
|
||||
writer.writeVarInt(mask);
|
||||
|
||||
// TODO: don't hardcode heightmaps
|
||||
// Heightmap
|
||||
int[] motionBlocking = new int[16 * 16];
|
||||
int[] worldSurface = new int[16 * 16];
|
||||
@ -114,25 +124,67 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
blocks.release();
|
||||
|
||||
// Block entities
|
||||
writer.writeVarInt(blockEntities.size());
|
||||
if(blockEntities == null) {
|
||||
writer.writeVarInt(0);
|
||||
} else {
|
||||
writer.writeVarInt(blockEntities.size());
|
||||
|
||||
for (int index : blockEntities) {
|
||||
final BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
|
||||
for (int index : blockEntities) {
|
||||
final BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
|
||||
|
||||
NBTCompound nbt = new NBTCompound()
|
||||
.setInt("x", blockPosition.getX())
|
||||
.setInt("y", blockPosition.getY())
|
||||
.setInt("z", blockPosition.getZ());
|
||||
NBTCompound nbt = new NBTCompound()
|
||||
.setInt("x", blockPosition.getX())
|
||||
.setInt("y", blockPosition.getY())
|
||||
.setInt("z", blockPosition.getZ());
|
||||
|
||||
if (customBlockPaletteStorage != null) {
|
||||
final short customBlockId = customBlockPaletteStorage.getBlockAt(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||
final CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
||||
if (customBlock != null) {
|
||||
final Data data = blocksData.get(index);
|
||||
customBlock.writeBlockEntity(blockPosition, data, nbt);
|
||||
if (customBlockPaletteStorage != null) {
|
||||
final short customBlockId = customBlockPaletteStorage.getBlockAt(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||
final CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
||||
if (customBlock != null) {
|
||||
final Data data = blocksData.get(index);
|
||||
customBlock.writeBlockEntity(blockPosition, data, nbt);
|
||||
}
|
||||
}
|
||||
writer.writeNBT("", nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
chunkX = reader.readInt();
|
||||
chunkZ = reader.readInt();
|
||||
fullChunk = reader.readBoolean();
|
||||
|
||||
int mask = reader.readVarInt();
|
||||
try {
|
||||
// TODO: Use heightmaps
|
||||
// unused at the moment
|
||||
NBT heightmaps = reader.readTag();
|
||||
|
||||
if(fullChunk) {
|
||||
int[] biomesIds = reader.readVarIntArray();
|
||||
biomes = new Biome[biomesIds.length];
|
||||
for (int i = 0; i < biomesIds.length; i++) {
|
||||
biomes[i] = MinecraftServer.getBiomeManager().getById(biomesIds[i]);
|
||||
}
|
||||
}
|
||||
writer.writeNBT("", nbt);
|
||||
|
||||
int blockArrayLength = reader.readVarInt();
|
||||
byte[] blockArray = reader.readBytes(blockArrayLength);
|
||||
// TODO: read blocks
|
||||
|
||||
int blockEntityCount = reader.readVarInt();
|
||||
blockEntities = new IntOpenHashSet();
|
||||
for (int i = 0; i < blockEntityCount; i++) {
|
||||
NBTCompound tag = (NBTCompound) reader.readTag();
|
||||
|
||||
}
|
||||
|
||||
// TODO
|
||||
} catch (IOException | NBTException e) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
// TODO: should we throw to avoid an invalid packet?
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user