From f4fe137ab5cec2b82bdccec98dd2c2863127207e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jul 2020 17:02:14 +0100 Subject: Use 1.13.1 block palette --- src/Protocol/Protocol_1_13.cpp | 59 ++++++++++++++++++++++++++++++------------ src/Protocol/Protocol_1_13.h | 6 ++++- 2 files changed, 47 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index b08622fc6..cab839678 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -72,13 +72,23 @@ Implements the 1.13 protocol classes: //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_13: +void cProtocol_1_13::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +{ + SendBlockChange<&Palette_1_13::FromBlock>(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); +} + + + + + +template void cProtocol_1_13::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktBlockChange); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); - Pkt.WriteVarInt32(static_cast(Palette_1_13::FromBlock(PaletteUpgrade::FromBlock(a_BlockType, a_BlockMeta)))); // TODO: Palette + Pkt.WriteVarInt32(Palette(PaletteUpgrade::FromBlock(a_BlockType, a_BlockMeta))); } @@ -87,31 +97,28 @@ void cProtocol_1_13::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, B void cProtocol_1_13::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, pktBlockChanges); - Pkt.WriteBEInt32(a_ChunkX); - Pkt.WriteBEInt32(a_ChunkZ); - Pkt.WriteVarInt32(static_cast(a_Changes.size())); - for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) - { - Int16 Coords = static_cast(itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12)); - Pkt.WriteBEInt16(Coords); - Pkt.WriteVarInt32(static_cast(Palette_1_13::FromBlock(PaletteUpgrade::FromBlock(itr->m_BlockType, itr->m_BlockMeta)))); // TODO: Palette - } // for itr - a_Changes[] + SendBlockChanges<&Palette_1_13::FromBlock>(a_ChunkX, a_ChunkZ, a_Changes); } -void cProtocol_1_13::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) +template +void cProtocol_1_13::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { ASSERT(m_State == 3); // In game mode? - const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_13, a_ChunkX, a_ChunkZ); - cCSLock Lock(m_CSPacket); - SendData(ChunkData.data(), ChunkData.size()); + cPacketizer Pkt(*this, pktBlockChanges); + Pkt.WriteBEInt32(a_ChunkX); + Pkt.WriteBEInt32(a_ChunkZ); + Pkt.WriteVarInt32(static_cast(a_Changes.size())); + for (const auto & Change : a_Changes) + { + Int16 Coords = static_cast(Change.m_RelY | (Change.m_RelZ << 8) | (Change.m_RelX << 12)); + Pkt.WriteBEInt16(Coords); + Pkt.WriteVarInt32(Palette(PaletteUpgrade::FromBlock(Change.m_BlockType, Change.m_BlockMeta))); + } // for itr - a_Changes[] } @@ -1177,6 +1184,24 @@ void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_13_1: +void cProtocol_1_13_1::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +{ + Super::SendBlockChange<&Palette_1_13_1::FromBlock>(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); +} + + + + + +void cProtocol_1_13_1::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) +{ + Super::SendBlockChanges<&Palette_1_13_1::FromBlock>(a_ChunkX, a_ChunkZ, a_Changes); +} + + + + + cProtocol::Version cProtocol_1_13_1::GetProtocolVersion() { return Version::Version_1_13_1; diff --git a/src/Protocol/Protocol_1_13.h b/src/Protocol/Protocol_1_13.h index 62f9cf2e4..189dff903 100644 --- a/src/Protocol/Protocol_1_13.h +++ b/src/Protocol/Protocol_1_13.h @@ -41,8 +41,9 @@ protected: // Packet sending: virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + template void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // Template to avoid virutal calls in tight loops virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; - virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; + template void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes); // Template to avoid virutal calls in tight loops virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array a_Data) override; @@ -92,6 +93,9 @@ public: protected: + virtual void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; + /** Returns 1.13.1 */ virtual Version GetProtocolVersion() override; virtual std::pair GetItemFromProtocolID(UInt32 a_ProtocolID) override; -- cgit v1.2.3