From fce548139b8c4643cd28f636d5c497d2ca8cd230 Mon Sep 17 00:00:00 2001 From: Mat Date: Sat, 28 Mar 2020 15:52:40 +0200 Subject: Inventory changes (#4561) Co-Authored-By: peterbell10 --- src/Protocol/Protocol_1_8.cpp | 12 ++++++------ src/Protocol/Protocol_1_9.cpp | 12 ++++++------ src/UI/Window.cpp | 7 ++----- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 00eaf4284..023fd640d 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -1630,7 +1630,7 @@ void cProtocol_1_8_0::SendWholeInventory(const cWindow & a_Window) ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktWindowItems); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(static_cast(a_Window.GetNumSlots())); cItems Slots; a_Window.GetSlots(*(m_Client->GetPlayer()), Slots); @@ -1649,7 +1649,7 @@ void cProtocol_1_8_0::SendWindowClose(const cWindow & a_Window) ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktWindowClose); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); } @@ -1667,7 +1667,7 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window) } cPacketizer Pkt(*this, pktWindowOpen); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); Pkt.WriteString(a_Window.GetWindowTypeName()); Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str())); @@ -1677,12 +1677,12 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window) case cWindow::wtEnchantment: case cWindow::wtAnvil: { - Pkt.WriteBEInt8(0); + Pkt.WriteBEUInt8(0); break; } default: { - Pkt.WriteBEInt8(static_cast(a_Window.GetNumNonInventorySlots())); + Pkt.WriteBEUInt8(static_cast(a_Window.GetNumNonInventorySlots())); break; } } @@ -1703,7 +1703,7 @@ void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, short a_Prope ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktWindowProperty); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(a_Property); Pkt.WriteBEInt16(a_Value); } diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index fa5215102..c9d460c9e 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -1686,7 +1686,7 @@ void cProtocol_1_9_0::SendWholeInventory(const cWindow & a_Window) ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktWindowItems); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(static_cast(a_Window.GetNumSlots())); cItems Slots; a_Window.GetSlots(*(m_Client->GetPlayer()), Slots); @@ -1705,7 +1705,7 @@ void cProtocol_1_9_0::SendWindowClose(const cWindow & a_Window) ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktWindowClose); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); } @@ -1723,7 +1723,7 @@ void cProtocol_1_9_0::SendWindowOpen(const cWindow & a_Window) } cPacketizer Pkt(*this, pktWindowOpen); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); Pkt.WriteString(a_Window.GetWindowTypeName()); Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str())); @@ -1733,12 +1733,12 @@ void cProtocol_1_9_0::SendWindowOpen(const cWindow & a_Window) case cWindow::wtEnchantment: case cWindow::wtAnvil: { - Pkt.WriteBEInt8(0); + Pkt.WriteBEUInt8(0); break; } default: { - Pkt.WriteBEInt8(static_cast(a_Window.GetNumNonInventorySlots())); + Pkt.WriteBEUInt8(static_cast(a_Window.GetNumNonInventorySlots())); break; } } @@ -1759,7 +1759,7 @@ void cProtocol_1_9_0::SendWindowProperty(const cWindow & a_Window, short a_Prope ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktWindowProperty); - Pkt.WriteBEInt8(a_Window.GetWindowID()); + Pkt.WriteBEUInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(a_Property); Pkt.WriteBEInt16(a_Value); } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 92e69e8b7..b59268ac4 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -28,15 +28,13 @@ Byte cWindow::m_WindowIDCounter = 0; cWindow::cWindow(WindowType a_WindowType, const AString & a_WindowTitle) : - m_WindowID(static_cast((++m_WindowIDCounter) % 127)), + m_WindowID(((++m_WindowIDCounter) % 127) + 1), m_WindowType(a_WindowType), m_WindowTitle(a_WindowTitle), m_IsDestroyed(false), m_Owner(nullptr) { - // The window ID is signed in protocol 1.7, unsigned in protocol 1.8. Keep out of trouble by using only 7 bits: - // Ref.: https://forum.cuberite.org/thread-1876.html - ASSERT((m_WindowID >= 0) && (m_WindowID < 127)); + ASSERT((m_WindowID > 0) && (m_WindowID <= 127)); if (a_WindowType == wtInventory) { @@ -768,4 +766,3 @@ void cWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player) - -- cgit v1.2.3