summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/BlockEntities/BrewingstandEntity.cpp2
-rw-r--r--src/BlockEntities/BrewingstandEntity.h2
-rw-r--r--src/BlockEntities/FurnaceEntity.cpp2
-rw-r--r--src/BlockEntities/FurnaceEntity.h2
-rw-r--r--src/ClientHandle.cpp2
-rw-r--r--src/ClientHandle.h2
-rw-r--r--src/Protocol/Protocol.h2
-rw-r--r--src/Protocol/Protocol_1_8.cpp4
-rw-r--r--src/Protocol/Protocol_1_8.h2
-rw-r--r--src/UI/EnchantingWindow.cpp29
-rw-r--r--src/UI/EnchantingWindow.h10
-rw-r--r--src/UI/SlotArea.cpp20
-rw-r--r--src/UI/SlotArea.h2
-rw-r--r--src/UI/Window.cpp150
-rw-r--r--src/UI/Window.h11
15 files changed, 99 insertions, 143 deletions
diff --git a/src/BlockEntities/BrewingstandEntity.cpp b/src/BlockEntities/BrewingstandEntity.cpp
index 27dabf177..9c43f257f 100644
--- a/src/BlockEntities/BrewingstandEntity.cpp
+++ b/src/BlockEntities/BrewingstandEntity.cpp
@@ -189,7 +189,7 @@ bool cBrewingstandEntity::UsedBy(cPlayer * a_Player)
-void cBrewingstandEntity::BroadcastProgress(short a_ProgressbarID, short a_Value)
+void cBrewingstandEntity::BroadcastProgress(size_t a_ProgressbarID, short a_Value)
{
cWindow * Window = GetWindow();
if (Window != nullptr)
diff --git a/src/BlockEntities/BrewingstandEntity.h b/src/BlockEntities/BrewingstandEntity.h
index 44d977966..90c6003df 100644
--- a/src/BlockEntities/BrewingstandEntity.h
+++ b/src/BlockEntities/BrewingstandEntity.h
@@ -137,7 +137,7 @@ protected:
short m_RemainingFuel;
/** Sends the specified progressbar value to all clients of the window */
- void BroadcastProgress(short a_ProgressbarID, short a_Value);
+ void BroadcastProgress(size_t a_ProgressbarID, short a_Value);
// /** Broadcasts progressbar updates, if needed */
void UpdateProgressBars(bool a_ForceUpdate = false);
diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp
index e8e981065..b325f4e5c 100644
--- a/src/BlockEntities/FurnaceEntity.cpp
+++ b/src/BlockEntities/FurnaceEntity.cpp
@@ -192,7 +192,7 @@ int cFurnaceEntity::GetAndResetReward(void)
-void cFurnaceEntity::BroadcastProgress(short a_ProgressbarID, short a_Value)
+void cFurnaceEntity::BroadcastProgress(size_t a_ProgressbarID, short a_Value)
{
cWindow * Window = GetWindow();
if (Window != nullptr)
diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h
index 64b76a9ec..454c23785 100644
--- a/src/BlockEntities/FurnaceEntity.h
+++ b/src/BlockEntities/FurnaceEntity.h
@@ -145,7 +145,7 @@ protected:
bool m_IsLoading;
/** Sends the specified progressbar value to all clients of the window */
- void BroadcastProgress(short a_ProgressbarID, short a_Value);
+ void BroadcastProgress(size_t a_ProgressbarID, short a_Value);
/** One item finished cooking */
void FinishOne();
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index e8c684e68..c7d96f9b3 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -3251,7 +3251,7 @@ void cClientHandle::SendWindowOpen(const cWindow & a_Window)
-void cClientHandle::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value)
+void cClientHandle::SendWindowProperty(const cWindow & a_Window, size_t a_Property, short a_Value)
{
m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value);
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 5b80d8c54..ab6e5e730 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -233,7 +233,7 @@ public: // tolua_export
void SendWholeInventory (const cWindow & a_Window);
void SendWindowClose (const cWindow & a_Window);
void SendWindowOpen (const cWindow & a_Window);
- void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value);
+ void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value);
// tolua_begin
const AString & GetUsername(void) const;
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 9d3cd77f2..cf3458040 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -440,7 +440,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) = 0;
virtual void SendWindowClose (const cWindow & a_Window) = 0;
virtual void SendWindowOpen (const cWindow & a_Window) = 0;
- virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0;
+ virtual void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value) = 0;
/** Returns the ServerID used for authentication through session.minecraft.net */
virtual AString GetAuthServerID(void) = 0;
diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp
index c6b21fc3d..ae3137eb6 100644
--- a/src/Protocol/Protocol_1_8.cpp
+++ b/src/Protocol/Protocol_1_8.cpp
@@ -1694,13 +1694,13 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window)
-void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value)
+void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, size_t a_Property, short a_Value)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, pktWindowProperty);
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Window.GetWindowID()));
- Pkt.WriteBEInt16(a_Property);
+ Pkt.WriteBEInt16(static_cast<Int16>(a_Property));
Pkt.WriteBEInt16(a_Value);
}
diff --git a/src/Protocol/Protocol_1_8.h b/src/Protocol/Protocol_1_8.h
index ced7cf62a..44415758f 100644
--- a/src/Protocol/Protocol_1_8.h
+++ b/src/Protocol/Protocol_1_8.h
@@ -120,7 +120,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) override;
virtual void SendWindowClose (const cWindow & a_Window) override;
virtual void SendWindowOpen (const cWindow & a_Window) override;
- virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override;
+ virtual void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value) override;
virtual AString GetAuthServerID(void) override { return m_AuthServerID; }
diff --git a/src/UI/EnchantingWindow.cpp b/src/UI/EnchantingWindow.cpp
index 15d27fc63..9ebb70f32 100644
--- a/src/UI/EnchantingWindow.cpp
+++ b/src/UI/EnchantingWindow.cpp
@@ -26,25 +26,9 @@ cEnchantingWindow::cEnchantingWindow(Vector3i a_BlockPos, const AString & a_Titl
-void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
+void cEnchantingWindow::SetProperty(size_t a_Property, short a_Value)
{
- ASSERT(a_Property >= 0);
- if (static_cast<size_t>(a_Property) < m_PropertyValue.size())
- {
- m_PropertyValue[a_Property] = a_Value;
- }
-
- Super::SetProperty(a_Property, a_Value, a_Player);
-}
-
-
-
-
-
-void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
-{
- ASSERT(a_Property >= 0);
- if (static_cast<size_t>(a_Property) < m_PropertyValue.size())
+ if (a_Property < m_PropertyValue.size())
{
m_PropertyValue[a_Property] = a_Value;
}
@@ -56,14 +40,9 @@ void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
-short cEnchantingWindow::GetProperty(short a_Property)
+short cEnchantingWindow::GetProperty(size_t a_Property)
{
- if ((a_Property < 0) || (static_cast<size_t>(a_Property) >= m_PropertyValue.size()))
- {
- ASSERT(!"a_Property is invalid");
- return 0;
- }
-
+ ASSERT(a_Property < m_PropertyValue.size());
return m_PropertyValue[a_Property];
}
diff --git a/src/UI/EnchantingWindow.h b/src/UI/EnchantingWindow.h
index 2b32f078a..e166fd1de 100644
--- a/src/UI/EnchantingWindow.h
+++ b/src/UI/EnchantingWindow.h
@@ -21,7 +21,7 @@ class cSlotAreaEnchanting;
-class cEnchantingWindow:
+class cEnchantingWindow final :
public cWindow
{
using Super = cWindow;
@@ -32,14 +32,10 @@ public:
/** Sends enchantment properties to the client.
If the property represents a level requirement, stores it for later GetProperty retrieval. */
- virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override;
-
- /** Sends enchantment properties to the client.
- If the property represents a level requirement, stores it for later GetProperty retrieval. */
- virtual void SetProperty(short a_Property, short a_Value) override;
+ virtual void SetProperty(size_t a_Property, short a_Value) override;
/** Return the level requirement of the given enchantment slot. */
- short GetProperty(short a_Property);
+ short GetProperty(size_t a_Property);
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index bb597b2c9..53d406e65 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -1059,7 +1059,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
{
SetSlot(1, a_Player, cItem());
}
- m_ParentWindow.SetProperty(0, static_cast<short>(m_MaximumCost), a_Player);
+ m_ParentWindow.SetProperty(0, static_cast<short>(m_MaximumCost));
m_MaximumCost = 0;
static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr);
@@ -1135,7 +1135,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
{
Output.Empty();
SetSlot(2, a_Player, Output);
- m_ParentWindow.SetProperty(0, 0, a_Player);
+ m_ParentWindow.SetProperty(0, 0);
return;
}
@@ -1157,7 +1157,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// No enchantment
Output.Empty();
SetSlot(2, a_Player, Output);
- m_ParentWindow.SetProperty(0, 0, a_Player);
+ m_ParentWindow.SetProperty(0, 0);
return;
}
@@ -1180,7 +1180,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// No enchantment
Output.Empty();
SetSlot(2, a_Player, Output);
- m_ParentWindow.SetProperty(0, 0, a_Player);
+ m_ParentWindow.SetProperty(0, 0);
return;
}
@@ -1264,7 +1264,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
}
SetSlot(2, a_Player, Input);
- m_ParentWindow.SetProperty(0, static_cast<Int16>(m_MaximumCost), a_Player);
+ m_ParentWindow.SetProperty(0, static_cast<Int16>(m_MaximumCost));
}
@@ -1700,10 +1700,10 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
// Properties set according to: https://wiki.vg/Protocol#Window_Property
// Fake a "seed" for the client to draw Standard Galactic Alphabet glyphs:
- m_ParentWindow.SetProperty(3, Random.RandInt<short>(), a_Player);
+ m_ParentWindow.SetProperty(3, Random.RandInt<short>());
// Calculate an enchanting possibility for each option (top, middle and bottom) and send details to window:
- for (short i = 0; i != OptionLevels.size(); i++)
+ for (size_t i = 0; i != OptionLevels.size(); i++)
{
// A copy of the item.
cItem EnchantedItem = Item.CopyOne();
@@ -1714,20 +1714,20 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
LOGD("Generated enchanted item %d with enchantments: %s", i, EnchantedItem.m_Enchantments.ToString());
// Send the level requirement for the enchantment option:
- m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i]), a_Player);
+ m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i]));
// Get the first enchantment ID, which must exist:
ASSERT(EnchantedItem.m_Enchantments.begin() != EnchantedItem.m_Enchantments.end());
const short EnchantmentID = static_cast<short>(EnchantedItem.m_Enchantments.begin()->first);
// Send the enchantment ID of the first enchantment on our item:
- m_ParentWindow.SetProperty(4 + i, EnchantmentID, a_Player);
+ m_ParentWindow.SetProperty(4 + i, EnchantmentID);
const short EnchantmentLevel = static_cast<short>(EnchantedItem.m_Enchantments.GetLevel(EnchantmentID));
ASSERT(EnchantmentLevel > 0);
// Send the level for the first enchantment on our item:
- m_ParentWindow.SetProperty(7 + i, EnchantmentLevel, a_Player);
+ m_ParentWindow.SetProperty(7 + i, EnchantmentLevel);
// Store the item we've enchanted as an option to be retrieved later:
m_EnchantedItemOptions[i] = std::move(EnchantedItem);
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index acf8c404b..96ea95c37 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -379,7 +379,7 @@ protected:
-class cSlotAreaEnchanting:
+class cSlotAreaEnchanting final :
public cSlotAreaTemporary
{
using Super = cSlotAreaTemporary;
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index b59268ac4..07b84916d 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -347,6 +347,75 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse)
+void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
+{
+ // Translate local slot num into global slot num:
+ int SlotNum = 0;
+ bool HasFound = false;
+ for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
+ {
+ if (a_Area == *itr)
+ {
+ SlotNum += a_LocalSlotNum;
+ HasFound = true;
+ break;
+ }
+ SlotNum += (*itr)->GetNumSlots();
+ } // for itr - m_SlotAreas[]
+ if (!HasFound)
+ {
+ LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
+ ASSERT(!"Invalid slot area");
+ return;
+ }
+
+ // Broadcast the update packet:
+ cCSLock Lock(m_CS);
+ for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
+ {
+ (*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, static_cast<short>(SlotNum), *a_Area->GetSlot(a_LocalSlotNum, **itr));
+ } // for itr - m_OpenedBy[]
+}
+
+
+
+
+
+void cWindow::SendWholeWindow(cClientHandle & a_Client)
+{
+ a_Client.SendWholeInventory(*this);
+}
+
+
+
+
+
+void cWindow::BroadcastWholeWindow(void)
+{
+ cCSLock Lock(m_CS);
+ for (auto Player : m_OpenedBy)
+ {
+ SendWholeWindow(*Player->GetClientHandle());
+ }
+}
+
+
+
+
+
+void cWindow::SetProperty(size_t a_Property, short a_Value)
+{
+ cCSLock Lock(m_CS);
+ for (auto Player : m_OpenedBy)
+ {
+ Player->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
+ }
+}
+
+
+
+
+
void cWindow::OwnerDestroyed()
{
m_Owner = nullptr;
@@ -685,84 +754,3 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int
} // for itr - SlotNums[]
return NumDistributed;
}
-
-
-
-
-
-void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
-{
- // Translate local slot num into global slot num:
- int SlotNum = 0;
- bool HasFound = false;
- for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
- {
- if (a_Area == *itr)
- {
- SlotNum += a_LocalSlotNum;
- HasFound = true;
- break;
- }
- SlotNum += (*itr)->GetNumSlots();
- } // for itr - m_SlotAreas[]
- if (!HasFound)
- {
- LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
- ASSERT(!"Invalid slot area");
- return;
- }
-
- // Broadcast the update packet:
- cCSLock Lock(m_CS);
- for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
- {
- (*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, static_cast<short>(SlotNum), *a_Area->GetSlot(a_LocalSlotNum, **itr));
- } // for itr - m_OpenedBy[]
-}
-
-
-
-
-
-void cWindow::SendWholeWindow(cClientHandle & a_Client)
-{
- a_Client.SendWholeInventory(*this);
-}
-
-
-
-
-
-void cWindow::BroadcastWholeWindow(void)
-{
- cCSLock Lock(m_CS);
- for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
- {
- SendWholeWindow(*(*itr)->GetClientHandle());
- } // for itr - m_OpenedBy[]
-}
-
-
-
-
-
-void cWindow::SetProperty(short a_Property, short a_Value)
-{
- cCSLock Lock(m_CS);
- for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
- {
- (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
- } // for itr - m_OpenedBy[]
-}
-
-
-
-
-
-void cWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
-{
- a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
-}
-
-
-
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 65fbc3756..46935acef 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -142,11 +142,7 @@ public:
/** Updates a numerical property associated with the window. Typically used for furnace progressbars.
Sends the UpdateWindowProperty packet to all clients of the window */
- virtual void SetProperty(short a_Property, short a_Value);
-
- /** Updates a numerical property associated with the window. Typically used for furnace progressbars.
- Sends the UpdateWindowProperty packet only to the specified player */
- virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player);
+ virtual void SetProperty(size_t a_Property, short a_Value);
// tolua_end
@@ -179,6 +175,7 @@ public:
void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum);
protected:
+
cSlotAreas m_SlotAreas;
char m_WindowID;
@@ -227,7 +224,3 @@ protected:
@param a_LimitItems if false, no checks are performed on a_Item.m_ItemCount. */
int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems = true);
} ; // tolua_export
-
-
-
-