Work on sending chunks
This commit is contained in:
parent
2d1403548c
commit
f6bb87ab2b
|
@ -189,32 +189,22 @@ namespace Feather
|
||||||
|
|
||||||
client.SendMessage(spawnPos);
|
client.SendMessage(spawnPos);
|
||||||
|
|
||||||
using RelativeFlags = Play::ClientboundPlayerPositionAndLook::RelativeFlags;
|
// SEND CHUNKS
|
||||||
|
|
||||||
Play::ClientboundPlayerPositionAndLook playerPos =
|
|
||||||
{
|
|
||||||
.x = 0,
|
|
||||||
.y = 70,
|
|
||||||
.z = 0,
|
|
||||||
.xRot = 0,
|
|
||||||
.yRot = 0,
|
|
||||||
.flags = (RelativeFlags)0,
|
|
||||||
.id = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
client.SendMessage(playerPos);
|
|
||||||
|
|
||||||
|
|
||||||
NetworkMessage chunkData(5KB);
|
NetworkMessage chunkData(5KB);
|
||||||
// Packet ID
|
// Packet ID
|
||||||
chunkData.WriteVarInt(0x22);
|
chunkData.WriteVarInt(0x22);
|
||||||
|
|
||||||
|
|
||||||
// Chunk X, Z
|
// Chunk X, Z
|
||||||
chunkData.Write<int32_t>(-10);
|
//chunkData.Write<int32_t>(-10);
|
||||||
chunkData.Write<int32_t>(-12);
|
//chunkData.Write<int32_t>(-12);
|
||||||
|
chunkData.Write<int32_t>(0);
|
||||||
|
chunkData.Write<int32_t>(0);
|
||||||
|
|
||||||
// Full chunk
|
// Full chunk
|
||||||
chunkData.Write(true);
|
chunkData.Write<bool>(true);
|
||||||
|
|
||||||
|
|
||||||
Chunk* chunk = m_worldManager.GetOverworld()->m_chunk;
|
Chunk* chunk = m_worldManager.GetOverworld()->m_chunk;
|
||||||
|
@ -229,41 +219,36 @@ namespace Feather
|
||||||
{
|
{
|
||||||
ChunkSection sect = chunk->sections[i];
|
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());
|
Log::Trace("Chunk: Got Section {} with local palette size {}", i, sect.localPalette.Size());
|
||||||
|
|
||||||
sectionsBits |= 1 << i;
|
sectionsBits |= 1 << i;
|
||||||
|
|
||||||
// Block Count: fudge
|
// Block Count: fudge
|
||||||
sections.Write<uint16_t>(1024);
|
sections.Write<int16_t>(1024);
|
||||||
|
|
||||||
// Bits Per Block
|
const size_t bitsPerBlock = 4;
|
||||||
sections.Write<uint8_t>(4);
|
sections.Write<uint8_t>(bitsPerBlock);
|
||||||
|
|
||||||
// Palette
|
const size_t dataLength = (16 * 16 * 16) * bitsPerBlock / 64;
|
||||||
|
|
||||||
NetworkMessage paletteData(512);
|
if (bitsPerBlock <= 8)
|
||||||
|
|
||||||
for (int i = 0; i < sect.localPalette.Size(); i++)
|
|
||||||
{
|
{
|
||||||
int id = sect.localPalette.ByID(i);
|
// Palette
|
||||||
Log::Trace("Palette: {} -> {}", i, id);
|
sections.WriteVarInt(sect.localPalette.Size());
|
||||||
|
|
||||||
paletteData.WriteVarInt(id);
|
for (int j = 0; j < sect.localPalette.Size(); j++)
|
||||||
|
sections.WriteVarInt(sect.localPalette.ByID(j));
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paletteData.Finalize();
|
sections.WriteVarInt(dataLength);
|
||||||
sections.WriteData(paletteData.GetData(), paletteData.GetDataSize());
|
sections.WriteData(sect.blockStates, dataLength * sizeof(int64_t));
|
||||||
|
|
||||||
// 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log::Trace("Section bits: {:#b}", sectionsBits);
|
Log::Trace("Section bits: {:#b}", sectionsBits);
|
||||||
|
|
||||||
chunkData.WriteVarInt(sectionsBits);
|
chunkData.WriteVarInt(sectionsBits);
|
||||||
|
|
||||||
|
@ -273,14 +258,11 @@ namespace Feather
|
||||||
chunkData.WriteData(buf.data, buf.length);
|
chunkData.WriteData(buf.data, buf.length);
|
||||||
|
|
||||||
// Biomes
|
// Biomes
|
||||||
for (int i = 0; i < 1024; i++)
|
NBT::IntArrayTag biomes = chunkNBT->Get<NBT::IntArrayTag>("Biomes");
|
||||||
chunkData.Write<int32_t>(5);
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
//NBT::IntArrayTag biomes = chunk->Get<NBT::IntArrayTag>("Biomes");
|
chunkData.Write<int32_t>(biomes[i]);
|
||||||
//NBT::DataBuffer buf1 = biomes.GetData();
|
|
||||||
//chunkData.WriteData(buf1.data, buf1.length);
|
|
||||||
|
|
||||||
sections.Finalize();
|
sections.Finalize();
|
||||||
chunkData.WriteVarInt(sections.GetDataSize());
|
|
||||||
chunkData.WriteData(sections.GetData(), sections.GetDataSize());
|
chunkData.WriteData(sections.GetData(), sections.GetDataSize());
|
||||||
|
|
||||||
// Block Ents
|
// Block Ents
|
||||||
|
@ -289,6 +271,21 @@ namespace Feather
|
||||||
chunkData.Finalize();
|
chunkData.Finalize();
|
||||||
client.SendMessage(chunkData);
|
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 <>
|
template <>
|
||||||
|
|
Loading…
Reference in New Issue