From e3fe9e5e93fbf8ce26a61719fdb4ccd9a627d37a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 15 Mar 2021 17:06:58 +0000 Subject: Deduplicate WriteBlockEntity --- src/Protocol/Protocol_1_13.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/Protocol/Protocol_1_13.cpp') diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index 77cf86333..b892e8433 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -29,6 +29,7 @@ Implements the 1.13 protocol classes: #include "../Server.h" #include "../World.h" #include "../JsonUtils.h" +#include "../WorldStorage/FastNBT.h" #include "../Bindings/PluginManager.h" @@ -200,13 +201,13 @@ void cProtocol_1_13::SendTabCompletionResults(const AStringVector & a_Results) void cProtocol_1_13::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, pktUpdateBlockEntity); - - Pkt.WriteXYZPosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); - Byte Action = 0; + Byte Action; switch (a_BlockEntity.GetBlockType()) { + case E_BLOCK_ENCHANTMENT_TABLE: Action = 0; break; // The ones with a action of 0 is just a workaround to send the block entities to a client. + case E_BLOCK_END_PORTAL: Action = 0; break; // Todo: 18.09.2020 - remove this when block entities are transmitted in the ChunkData packet - 12xx12 + case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity @@ -220,14 +221,17 @@ void cProtocol_1_13::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) // case E_BLOCK_SHULKER_BOX: Action = 10; break; // sets shulker box - not used just here if anyone is confused from reading the protocol wiki case E_BLOCK_BED: Action = 11; break; // Update bed color - case E_BLOCK_ENCHANTMENT_TABLE: Action = 0; break; // The ones with a action of 0 is just a workaround to send the block entities to a client. - case E_BLOCK_END_PORTAL: Action = 0; break; // Todo: 18.09.2020 - remove this when block entities are transmitted in the ChunkData packet - 12xx12 - - default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; + default: return; // Block entities change between versions } + + cPacketizer Pkt(*this, pktUpdateBlockEntity); + Pkt.WriteXYZPosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); Pkt.WriteBEUInt8(Action); - WriteBlockEntity(Pkt, a_BlockEntity); + cFastNBTWriter Writer; + WriteBlockEntity(Writer, a_BlockEntity); + Writer.Finish(); + Pkt.WriteBuf(Writer.GetResult()); } @@ -1361,6 +1365,7 @@ void cProtocol_1_13_1::SendBossBarAdd(UInt32 a_UniqueID, const cCompositeChat & case BossBarColor::Purple: return 5U; case BossBarColor::White: return 6U; } + UNREACHABLE("Unsupported boss bar property"); }()); Pkt.WriteVarInt32([a_DivisionType] { @@ -1372,6 +1377,7 @@ void cProtocol_1_13_1::SendBossBarAdd(UInt32 a_UniqueID, const cCompositeChat & case BossBarDivisionType::TwelveNotches: return 3U; case BossBarDivisionType::TwentyNotches: return 4U; } + UNREACHABLE("Unsupported boss bar property"); }()); { UInt8 Flags = 0x00; -- cgit v1.2.3