summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-26 16:34:26 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-26 16:34:26 +0200
commitb4522bf14e2552217611b578b1847298c0ed5ac5 (patch)
treed8f945cc5105ac623dc069ea8ac237bcf1992f2d /source
parentAlpha-sorted the block meta list (diff)
downloadcuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.tar
cuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.tar.gz
cuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.tar.bz2
cuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.tar.lz
cuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.tar.xz
cuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.tar.zst
cuberite-b4522bf14e2552217611b578b1847298c0ed5ac5.zip
Diffstat (limited to 'source')
-rw-r--r--source/ItemGrid.cpp47
-rw-r--r--source/ItemGrid.h6
2 files changed, 53 insertions, 0 deletions
diff --git a/source/ItemGrid.cpp b/source/ItemGrid.cpp
index 0495105f2..5a432e80f 100644
--- a/source/ItemGrid.cpp
+++ b/source/ItemGrid.cpp
@@ -355,6 +355,53 @@ int cItemGrid::ChangeSlotCount(int a_X, int a_Y, int a_AddToCount)
+cItem cItemGrid::RemoveOneItem(int a_SlotNum)
+{
+ if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots))
+ {
+ LOGWARNING("%s: Invalid slot number %d out of %d slots, ignoring the call, returning empty item",
+ __FUNCTION__, a_SlotNum, m_NumSlots
+ );
+ return cItem();
+ }
+
+ // If the slot is empty, return an empty item
+ if (m_Slots[a_SlotNum].IsEmpty())
+ {
+ return cItem();
+ }
+
+ // Make a copy of the item in slot, set count to 1 and remove one from the slot
+ cItem res = m_Slots[a_SlotNum];
+ res.m_ItemCount = 1;
+ m_Slots[a_SlotNum].m_ItemCount -= 1;
+
+ // Emptying the slot correctly if appropriate
+ if (m_Slots[a_SlotNum].m_ItemCount == 0)
+ {
+ m_Slots[a_SlotNum].Empty();
+ }
+
+ // Notify everyone of the change
+ TriggerListeners(a_SlotNum);
+
+ // Return the stored one item
+ return res;
+}
+
+
+
+
+
+cItem cItemGrid::RemoveOneItem(int a_X, int a_Y)
+{
+ return RemoveOneItem(GetSlotNum(a_X, a_Y));
+}
+
+
+
+
+
int cItemGrid::HowManyItems(const cItem & a_Item)
{
int res = 0;
diff --git a/source/ItemGrid.h b/source/ItemGrid.h
index 22d64f076..82898537c 100644
--- a/source/ItemGrid.h
+++ b/source/ItemGrid.h
@@ -98,6 +98,12 @@ public:
*/
int ChangeSlotCount(int a_X, int a_Y, int a_AddToCount);
+ /// Removes one item from the specified slot, and returns it. If the slot was empty, returns an empty item
+ cItem RemoveOneItem(int a_SlotNum);
+
+ /// Removes one item from the specified slot, and returns it. If the slot was empty, returns an empty item
+ cItem RemoveOneItem(int a_X, int a_Y);
+
/// Returns the number of items of type a_Item that are stored
int HowManyItems(const cItem & a_Item);