diff options
author | 12xx12 <44411062+12xx12@users.noreply.github.com> | 2020-08-12 10:54:36 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-19 21:45:27 +0200 |
commit | 7d0813ce8c1be14bc1b9b706644bd4aa797244ee (patch) | |
tree | 6d026a11be6db2da3d60b94b4f4a442460253e1d /src/Protocol/Protocol_1_13.cpp | |
parent | Add enhanced Gold generation in Mesa-Type Biomes (#4821) (diff) | |
download | cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.tar cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.tar.gz cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.tar.bz2 cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.tar.lz cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.tar.xz cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.tar.zst cuberite-7d0813ce8c1be14bc1b9b706644bd4aa797244ee.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Protocol/Protocol_1_13.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index 94dc39ea9..f0f2312d2 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -155,7 +155,45 @@ void cProtocol_1_13::SendScoreboardObjective(const AString & a_Name, const AStri void cProtocol_1_13::SendStatistics(const cStatManager & a_Manager) { - // TODO + ASSERT(m_State == 3); // In game mode? + + UInt32 Size = 0; + a_Manager.ForEachStatisticType([this, &Size](const auto & Store) + { + for (const auto & Item : Store) + { + // Client balks at out-of-range values so there is no good default value + // We're forced to not send the statistics this protocol version doesn't support + + if (GetProtocolStatisticType(Item.first) != static_cast<UInt32>(-1)) + { + Size++; + } + } + }); + + // No need to check Size != 0 + // Assume that the vast majority of the time there's at least one statistic to send + + cPacketizer Pkt(*this, pktStatistics); + Pkt.WriteVarInt32(Size); + + a_Manager.ForEachStatisticType([this, &Pkt](const cStatManager::CustomStore & Store) + { + for (const auto & Item : Store) + { + const auto ID = GetProtocolStatisticType(Item.first); + if (ID == static_cast<UInt32>(-1)) + { + // Unsupported, don't send: + continue; + } + + Pkt.WriteVarInt32(8); // "Custom" category + Pkt.WriteVarInt32(ID); + Pkt.WriteVarInt32(static_cast<UInt32>(Item.second)); + } + }); } @@ -563,6 +601,15 @@ UInt32 cProtocol_1_13::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) +UInt32 cProtocol_1_13::GetProtocolStatisticType(Statistic a_Statistic) +{ + return Palette_1_13::From(a_Statistic); +} + + + + + bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) { HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemID); @@ -1210,6 +1257,15 @@ UInt32 cProtocol_1_13_1::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamag +UInt32 cProtocol_1_13_1::GetProtocolStatisticType(Statistic a_Statistic) +{ + return Palette_1_13_1::From(a_Statistic); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_13_2: |