diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-20 22:26:29 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-21 01:53:09 +0200 |
commit | 9a9079d3da006dc59ee2a8867f832d03211b1cd5 (patch) | |
tree | 5b5153d1cb806d9567706d09108c60bcc743770a /src | |
parent | Replace PowerData struct with PowerLevel (diff) | |
download | cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.tar cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.tar.gz cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.tar.bz2 cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.tar.lz cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.tar.xz cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.tar.zst cuberite-9a9079d3da006dc59ee2a8867f832d03211b1cd5.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Protocol/Protocol_1_13.cpp | 65 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_13.h | 28 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_14.cpp | 43 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_14.h | 6 |
4 files changed, 48 insertions, 94 deletions
diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index eced4129e..553fb87e0 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -72,21 +72,9 @@ Implements the 1.13 protocol classes: 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 <auto Palette> -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.WriteXYZPosition64(a_BlockX, a_BlockY, a_BlockZ); - Pkt.WriteVarInt32(Palette(PaletteUpgrade::FromBlock(a_BlockType, a_BlockMeta))); + Pkt.WriteVarInt32(GetProtocolBlockType(a_BlockType, a_BlockMeta)); } @@ -95,7 +83,18 @@ 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) { - SendBlockChanges<&Palette_1_13::FromBlock>(a_ChunkX, a_ChunkZ, 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<UInt32>(a_Changes.size())); + for (const auto & Change : a_Changes) + { + Int16 Coords = static_cast<Int16>(Change.m_RelY | (Change.m_RelZ << 8) | (Change.m_RelX << 12)); + Pkt.WriteBEInt16(Coords); + Pkt.WriteVarInt32(GetProtocolBlockType(Change.m_BlockType, Change.m_BlockMeta)); + } // for itr - a_Changes[] } @@ -628,7 +627,16 @@ std::pair<short, short> cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolI -UInt32 cProtocol_1_13::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) +UInt32 cProtocol_1_13::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +{ + return Palette_1_13::FromBlock(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); +} + + + + + +UInt32 cProtocol_1_13::GetProtocolItemType(short a_ItemID, short a_ItemDamage) { return Palette_1_13::FromItem(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); } @@ -699,7 +707,7 @@ void cProtocol_1_13::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) } // Normal item - a_Pkt.WriteBEInt16(GetProtocolIDFromItem(a_Item.m_ItemType, a_Item.m_ItemDamage)); + a_Pkt.WriteBEInt16(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage)); a_Pkt.WriteBEInt8(a_Item.m_ItemCount); // TODO: NBT @@ -1248,43 +1256,34 @@ 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) +cProtocol::Version cProtocol_1_13_1::GetProtocolVersion() { - Super::SendBlockChanges<&Palette_1_13_1::FromBlock>(a_ChunkX, a_ChunkZ, a_Changes); + return Version::Version_1_13_1; } -cProtocol::Version cProtocol_1_13_1::GetProtocolVersion() +std::pair<short, short> cProtocol_1_13_1::GetItemFromProtocolID(UInt32 a_ProtocolID) { - return Version::Version_1_13_1; + return PaletteUpgrade::ToItem(Palette_1_13_1::ToItem(a_ProtocolID)); } -std::pair<short, short> cProtocol_1_13_1::GetItemFromProtocolID(UInt32 a_ProtocolID) +UInt32 cProtocol_1_13_1::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) { - return PaletteUpgrade::ToItem(Palette_1_13_1::ToItem(a_ProtocolID)); + return Palette_1_13_1::FromBlock(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); } -UInt32 cProtocol_1_13_1::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) +UInt32 cProtocol_1_13_1::GetProtocolItemType(short a_ItemID, short a_ItemDamage) { return Palette_1_13_1::FromItem(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); } @@ -1371,7 +1370,7 @@ void cProtocol_1_13_2::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) a_Pkt.WriteBool(true); // Normal item - a_Pkt.WriteVarInt32(GetProtocolIDFromItem(a_Item.m_ItemType, a_Item.m_ItemDamage)); + a_Pkt.WriteVarInt32(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage)); a_Pkt.WriteBEInt8(a_Item.m_ItemCount); // TODO: NBT diff --git a/src/Protocol/Protocol_1_13.h b/src/Protocol/Protocol_1_13.h index 3c3253cc5..1d19c59fe 100644 --- a/src/Protocol/Protocol_1_13.h +++ b/src/Protocol/Protocol_1_13.h @@ -37,26 +37,7 @@ public: protected: virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - template <auto Palette> void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // Template to avoid virtual calls in tight loops virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; - - /** Common implementation of multiblock change sending, templated to avoid virtual calls in tight loops. */ - template <auto Palette>void 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<UInt32>(a_Changes.size())); - for (const auto & Change : a_Changes) - { - Int16 Coords = static_cast<Int16>(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[] - } - 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<int, 2> a_Data) override; @@ -78,7 +59,8 @@ protected: virtual UInt8 GetEntityMetadataID(eEntityMetadata a_Metadata); virtual UInt8 GetEntityMetadataID(eEntityMetadataType a_FieldType); virtual std::pair<short, short> GetItemFromProtocolID(UInt32 a_ProtocolID); - virtual UInt32 GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage); + virtual UInt32 GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta); + virtual UInt32 GetProtocolItemType(short a_ItemID, short a_ItemDamage); virtual UInt32 GetProtocolStatisticType(Statistic a_Statistic); virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) override; @@ -107,12 +89,10 @@ 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; - virtual Version GetProtocolVersion() override; virtual std::pair<short, short> GetItemFromProtocolID(UInt32 a_ProtocolID) override; - virtual UInt32 GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) override; + virtual UInt32 GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) override; + virtual UInt32 GetProtocolItemType(short a_ItemID, short a_ItemDamage) override; virtual UInt32 GetProtocolStatisticType(Statistic a_Statistic) override; }; diff --git a/src/Protocol/Protocol_1_14.cpp b/src/Protocol/Protocol_1_14.cpp index 3222e7fe2..1cde27413 100644 --- a/src/Protocol/Protocol_1_14.cpp +++ b/src/Protocol/Protocol_1_14.cpp @@ -70,38 +70,6 @@ void cProtocol_1_14::SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_B -void cProtocol_1_14::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) -{ - SendBlockChange<&Palette_1_14::FromBlock>(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); -} - - - - - -template <auto Palette> -void cProtocol_1_14::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.WriteXZYPosition64(a_BlockX, a_BlockY, a_BlockZ); - Pkt.WriteVarInt32(Palette(PaletteUpgrade::FromBlock(a_BlockType, a_BlockMeta))); -} - - - - - -void cProtocol_1_14::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) -{ - cProtocol_1_13::SendBlockChanges<&Palette_1_14::FromBlock>(a_ChunkX, a_ChunkZ, a_Changes); -} - - - - - void cProtocol_1_14::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { } @@ -299,7 +267,16 @@ std::pair<short, short> cProtocol_1_14::GetItemFromProtocolID(UInt32 a_ProtocolI -UInt32 cProtocol_1_14::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) +UInt32 cProtocol_1_14::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +{ + return Palette_1_14::FromBlock(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); +} + + + + + +UInt32 cProtocol_1_14::GetProtocolItemType(short a_ItemID, short a_ItemDamage) { return Palette_1_14::FromItem(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); } diff --git a/src/Protocol/Protocol_1_14.h b/src/Protocol/Protocol_1_14.h index 8a80d0bee..54b9c080f 100644 --- a/src/Protocol/Protocol_1_14.h +++ b/src/Protocol/Protocol_1_14.h @@ -32,9 +32,6 @@ protected: virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override; virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override; - virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - template <auto Palette> void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; @@ -52,7 +49,8 @@ protected: virtual void HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer) override; virtual std::pair<short, short> GetItemFromProtocolID(UInt32 a_ProtocolID) override; - virtual UInt32 GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) override; + virtual UInt32 GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) override; + virtual UInt32 GetProtocolItemType(short a_ItemID, short a_ItemDamage) override; virtual UInt32 GetProtocolStatisticType(Statistic a_Statistic) override; virtual void WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) override {} |