Work on sending chunks
This commit is contained in:
parent
2d1403548c
commit
f6bb87ab2b
|
@ -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<int32_t>(-10);
|
||||
chunkData.Write<int32_t>(-12);
|
||||
//chunkData.Write<int32_t>(-10);
|
||||
//chunkData.Write<int32_t>(-12);
|
||||
chunkData.Write<int32_t>(0);
|
||||
chunkData.Write<int32_t>(0);
|
||||
|
||||
// Full chunk
|
||||
chunkData.Write(true);
|
||||
chunkData.Write<bool>(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<uint16_t>(1024);
|
||||
sections.Write<int16_t>(1024);
|
||||
|
||||
// Bits Per Block
|
||||
sections.Write<uint8_t>(4);
|
||||
const size_t bitsPerBlock = 4;
|
||||
sections.Write<uint8_t>(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<NBT::LongArrayTag>("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<int32_t>(5);
|
||||
//NBT::IntArrayTag biomes = chunk->Get<NBT::IntArrayTag>("Biomes");
|
||||
//NBT::DataBuffer buf1 = biomes.GetData();
|
||||
//chunkData.WriteData(buf1.data, buf1.length);
|
||||
NBT::IntArrayTag biomes = chunkNBT->Get<NBT::IntArrayTag>("Biomes");
|
||||
for (uint32_t i = 0; i < 1024; i++)
|
||||
chunkData.Write<int32_t>(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 <>
|
||||
|
|
Loading…
Reference in New Issue