summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-07-20 01:22:58 +0200
committerHowaner <franzi.moos@googlemail.com>2014-07-20 01:22:58 +0200
commit897d68dc35620f0e6c33fe4a6083a76ab43a9a57 (patch)
treeb301f4317e3fb9fff1ea1300bf5b5bd899358a6b
parentMoved comment. (diff)
downloadcuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.tar
cuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.tar.gz
cuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.tar.bz2
cuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.tar.lz
cuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.tar.xz
cuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.tar.zst
cuberite-897d68dc35620f0e6c33fe4a6083a76ab43a9a57.zip
-rw-r--r--src/Inventory.cpp13
-rw-r--r--src/UI/SlotArea.cpp4
-rw-r--r--src/UI/SlotArea.h2
3 files changed, 16 insertions, 3 deletions
diff --git a/src/Inventory.cpp b/src/Inventory.cpp
index 18154bafd..fff6e4a4e 100644
--- a/src/Inventory.cpp
+++ b/src/Inventory.cpp
@@ -103,6 +103,19 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
cItem ToAdd(a_Item);
int res = 0;
+ // When the item is a armor, try to set it directly to the armor slot.
+ if (ItemCategory::IsArmor(a_Item.m_ItemType))
+ {
+ for (size_t i = 0; i < (size_t)m_ArmorSlots.GetNumSlots(); i++)
+ {
+ if (m_ArmorSlots.GetSlot(i).IsEmpty() && cSlotAreaArmor::CanPlaceArmorInSlot(i, a_Item))
+ {
+ m_ArmorSlots.SetSlot(i, a_Item);
+ return a_Item.m_ItemCount;
+ }
+ }
+ }
+
res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1);
ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
if (ToAdd.m_ItemCount == 0)
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 6f4f65ca3..e9b1ef8e0 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -1926,7 +1926,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
return;
}
- if (DraggingItem.IsEmpty() || CanPlaceInSlot(a_SlotNum, DraggingItem))
+ if (DraggingItem.IsEmpty() || CanPlaceArmorInSlot(a_SlotNum, DraggingItem))
{
// Swap contents
cItem tmp(DraggingItem);
@@ -1945,7 +1945,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
-bool cSlotAreaArmor::CanPlaceInSlot(int a_SlotNum, const cItem & a_Item)
+bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item)
{
switch (a_SlotNum)
{
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 7f37159b7..fa842bb81 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -161,7 +161,7 @@ public:
/** Called when a player clicks in the window. Parameters taken from the click packet. */
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
- bool CanPlaceInSlot(int a_SlotNum, const cItem & a_Item);
+ static bool CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item);
} ;