diff options
author | sebi.noreply@gmail.com <sebi.noreply@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-24 14:48:25 +0200 |
---|---|---|
committer | sebi.noreply@gmail.com <sebi.noreply@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-24 14:48:25 +0200 |
commit | e33e9111abe5bb7968f48bd2801bf182754e554c (patch) | |
tree | eece777a96e41238cbe1ecb6e569aa81d94905d2 /source/Inventory.cpp | |
parent | #grammarnazi: fixed tabs to spaces and alpha-sort (diff) | |
download | cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.tar cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.tar.gz cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.tar.bz2 cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.tar.lz cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.tar.xz cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.tar.zst cuberite-e33e9111abe5bb7968f48bd2801bf182754e554c.zip |
Diffstat (limited to 'source/Inventory.cpp')
-rw-r--r-- | source/Inventory.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/source/Inventory.cpp b/source/Inventory.cpp index 5ed2e0763..9417f6a14 100644 --- a/source/Inventory.cpp +++ b/source/Inventory.cpp @@ -89,6 +89,36 @@ bool cInventory::AddItem( cItem & a_Item ) +bool cInventory::AddItemAnyAmount( cItem & a_Item ) +{ + bool ChangedSlots[c_NumSlots]; + memset( ChangedSlots, false, c_NumSlots * sizeof( bool ) ); + + char StartCount = a_Item.m_ItemCount; + if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_HotOffset, c_HotSlots, ChangedSlots, 0 ); + if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_MainOffset, c_MainSlots, ChangedSlots, 0 ); + if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_HotOffset, c_HotSlots, ChangedSlots, 2 ); + if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_MainOffset, c_MainSlots, ChangedSlots, 2 ); + + if (a_Item.m_ItemCount == StartCount) + return false; + + for (unsigned int i = 0; i < c_NumSlots; i++) + { + if (ChangedSlots[i]) + { + LOGD("cInventory::AddItemAnyAmount(): Item was added to %i ID:%i Count:%i", i, m_Slots[i].m_ItemID, m_Slots[i].m_ItemCount); + SendSlot(i); + } + } + + return true; +} + + + + + // TODO: Right now if you dont have enough items, the items you did have are removed, and the function returns false anyway bool cInventory::RemoveItem( cItem & a_Item ) { @@ -347,11 +377,12 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, // Fill already present stacks if( a_Mode < 2 ) { + int MaxStackSize = cItemHandler::GetItemHandler(a_Item.m_ItemType)->GetMaxStackSize(); for(int i = 0; i < a_Size; i++) { - if( m_Slots[i + a_Offset].m_ItemID == a_Item.m_ItemID && m_Slots[i + a_Offset].m_ItemCount < 64 && m_Slots[i + a_Offset].m_ItemHealth == a_Item.m_ItemHealth ) + if( m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemHealth == a_Item.m_ItemHealth ) { - int NumFree = 64 - m_Slots[i + a_Offset].m_ItemCount; + int NumFree = MaxStackSize - m_Slots[i + a_Offset].m_ItemCount; if( NumFree >= a_Item.m_ItemCount ) { @@ -377,7 +408,7 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, // If we got more left, find first empty slot for(int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++) { - if( m_Slots[i + a_Offset].m_ItemID == -1 ) + if( m_Slots[i + a_Offset].m_ItemType == -1 ) { m_Slots[i + a_Offset] = a_Item; a_Item.m_ItemCount = 0; |