From 4aef80b47eb6941d7fc41e57efe147af0ece1f9b Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 3 Jan 2020 17:31:13 +0100 Subject: Added temporary block type mapping for 1.13+ protocols. --- src/Protocol/Protocol_1_13.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 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 f84e8d1bd..e2cd72693 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -11,6 +11,7 @@ Implements the 1.13 protocol classes: #include "ProtocolRecognizer.h" #include "ChunkDataSerializer.h" #include "Packetizer.h" +#include "ProtocolPalettes.h" #include "../Entities/Boat.h" #include "../Entities/Minecart.h" @@ -21,9 +22,11 @@ Implements the 1.13 protocol classes: #include "../Entities/FireworkEntity.h" #include "../Entities/SplashPotionEntity.h" +#include "../BlockTypePalette.h" +#include "../ClientHandle.h" #include "../Root.h" #include "../Server.h" -#include "../ClientHandle.h" + #include "../Bindings/PluginManager.h" @@ -69,6 +72,25 @@ cProtocol_1_13::cProtocol_1_13(cClientHandle * a_Client, const AString & a_Serve +void cProtocol_1_13::Initialize(cClientHandle & a_Client) +{ + // Get the palettes; fail if not available: + auto paletteVersion = this->GetPaletteVersion(); + m_BlockTypePalette = cRoot::Get()->GetProtocolPalettes().blockTypePalette(paletteVersion); + if (m_BlockTypePalette == nullptr) + { + throw std::runtime_error(Printf("This server doesn't support protocol %s.", paletteVersion)); + } + + // Process the palette into the temporary BLOCKTYPE -> NetBlockID map: + auto upg = cRoot::Get()->GetUpgradeBlockTypePalette(); + m_BlockTypeMap = m_BlockTypePalette->createTransformMapWithFallback(upg, 0); +} + + + + + UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) { switch (a_PacketType) @@ -132,6 +154,15 @@ UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) +AString cProtocol_1_13::GetPaletteVersion() const +{ + return "1.13"; +} + + + + + bool cProtocol_1_13::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { if (m_State != 3) @@ -292,7 +323,7 @@ void cProtocol_1_13::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSeriali { ASSERT(m_State == 3); // In game mode? - const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_13, a_ChunkX, a_ChunkZ); + const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_13, a_ChunkX, a_ChunkZ, m_BlockTypeMap); cCSLock Lock(m_CSPacket); SendData(ChunkData.data(), ChunkData.size()); } -- cgit v1.2.3