diff --git a/src/DedicatedServer.cpp b/src/DedicatedServer.cpp index 5db6f6b..d55dcbd 100644 --- a/src/DedicatedServer.cpp +++ b/src/DedicatedServer.cpp @@ -189,32 +189,22 @@ namespace Feather client.SendMessage(spawnPos); - using RelativeFlags = Play::ClientboundPlayerPositionAndLook::RelativeFlags; - - Play::ClientboundPlayerPositionAndLook playerPos = - { - .x = 0, - .y = 70, - .z = 0, - .xRot = 0, - .yRot = 0, - .flags = (RelativeFlags)0, - .id = 0, - }; - - client.SendMessage(playerPos); + // SEND CHUNKS NetworkMessage chunkData(5KB); // Packet ID chunkData.WriteVarInt(0x22); + // Chunk X, Z - chunkData.Write(-10); - chunkData.Write(-12); + //chunkData.Write(-10); + //chunkData.Write(-12); + chunkData.Write(0); + chunkData.Write(0); // Full chunk - chunkData.Write(true); + chunkData.Write(true); Chunk* chunk = m_worldManager.GetOverworld()->m_chunk; @@ -229,41 +219,36 @@ namespace Feather { ChunkSection sect = chunk->sections[i]; + // Don't support bitsPerBlock != 4 yet! + if (i == 4) + continue; + Log::Trace("Chunk: Got Section {} with local palette size {}", i, sect.localPalette.Size()); sectionsBits |= 1 << i; // Block Count: fudge - sections.Write(1024); + sections.Write(1024); - // Bits Per Block - sections.Write(4); + const size_t bitsPerBlock = 4; + sections.Write(bitsPerBlock); - // Palette - - NetworkMessage paletteData(512); - - for (int i = 0; i < sect.localPalette.Size(); i++) + const size_t dataLength = (16 * 16 * 16) * bitsPerBlock / 64; + + if (bitsPerBlock <= 8) { - int id = sect.localPalette.ByID(i); - Log::Trace("Palette: {} -> {}", i, id); + // Palette + sections.WriteVarInt(sect.localPalette.Size()); - paletteData.WriteVarInt(id); - - i++; + for (int j = 0; j < sect.localPalette.Size(); j++) + sections.WriteVarInt(sect.localPalette.ByID(j)); } - paletteData.Finalize(); - sections.WriteData(paletteData.GetData(), paletteData.GetDataSize()); - - // Block Data - //NBT::LongArrayTag blocks = sect.Get("BlockStates"); - - sections.WriteVarInt(ChunkSection::NUM_LONGS); - sections.WriteData(sect.blockStates, ChunkSection::NUM_LONGS * sizeof(int64_t)); + sections.WriteVarInt(dataLength); + sections.WriteData(sect.blockStates, dataLength * sizeof(int64_t)); } - //Log::Trace("Section bits: {:#b}", sectionsBits); + Log::Trace("Section bits: {:#b}", sectionsBits); chunkData.WriteVarInt(sectionsBits); @@ -273,14 +258,11 @@ namespace Feather chunkData.WriteData(buf.data, buf.length); // Biomes - for (int i = 0; i < 1024; i++) - chunkData.Write(5); - //NBT::IntArrayTag biomes = chunk->Get("Biomes"); - //NBT::DataBuffer buf1 = biomes.GetData(); - //chunkData.WriteData(buf1.data, buf1.length); + NBT::IntArrayTag biomes = chunkNBT->Get("Biomes"); + for (uint32_t i = 0; i < 1024; i++) + chunkData.Write(biomes[i]); sections.Finalize(); - chunkData.WriteVarInt(sections.GetDataSize()); chunkData.WriteData(sections.GetData(), sections.GetDataSize()); // Block Ents @@ -289,6 +271,21 @@ namespace Feather chunkData.Finalize(); client.SendMessage(chunkData); + // UPDATE POSITION + using RelativeFlags = Play::ClientboundPlayerPositionAndLook::RelativeFlags; + + Play::ClientboundPlayerPositionAndLook playerPos = + { + .x = 0, + .y = 87, + .z = 0, + .xRot = 0, + .yRot = 0, + .flags = RelativeFlags(0), + .id = 0, + }; + + client.SendMessage(playerPos); } template <>