diff options
author | Alexander Harkness <me@bearbin.net> | 2015-05-27 13:21:17 +0200 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2015-05-27 13:21:17 +0200 |
commit | da4a76bb5043d072513b74823dc79279c75dd70c (patch) | |
tree | 5c46cca70beb5e0b0d0161b5ccb306425e6426dd /src | |
parent | Merge pull request #2143 from jammet/patch-6 (diff) | |
parent | Fixes #2041 (diff) | |
download | cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.gz cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.bz2 cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.lz cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.xz cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.zst cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Entities/Pickup.cpp | 1 | ||||
-rw-r--r-- | src/Inventory.cpp | 30 | ||||
-rw-r--r-- | src/Inventory.h | 10 | ||||
-rw-r--r-- | src/Items/ItemBucket.h | 4 | ||||
-rw-r--r-- | src/Items/ItemEmptyMap.h | 2 | ||||
-rw-r--r-- | src/Items/ItemMushroomSoup.h | 2 | ||||
-rw-r--r-- | src/UI/SlotArea.cpp | 8 | ||||
-rw-r--r-- | src/UI/Window.cpp | 14 |
8 files changed, 43 insertions, 28 deletions
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index f2f76dbf9..520765b29 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -228,6 +228,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) m_Item.m_ItemCount -= NumAdded; m_World->BroadcastCollectEntity(*this, a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); if (m_Item.m_ItemCount <= 0) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index c595da5b0..f08dd1896 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -98,7 +98,7 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int -int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) +int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks) { cItem ToAdd(a_Item); int res = 0; @@ -116,8 +116,30 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT } } - res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1); + for (int SlotIdx = 0; SlotIdx < m_InventorySlots.GetNumSlots(); ++SlotIdx) + { + auto & Slot = m_InventorySlots.GetSlot(SlotIdx); + if (Slot.IsEqual(a_Item)) + { + cItemHandler Handler(Slot.m_ItemType); + int AmountToAdd = std::min(static_cast<char>(Handler.GetMaxStackSize() - Slot.m_ItemCount), ToAdd.m_ItemCount); + res += AmountToAdd; + + cItem SlotAdjusted(Slot); + SlotAdjusted.m_ItemCount += AmountToAdd; + m_InventorySlots.SetSlot(SlotIdx, SlotAdjusted); + + ToAdd.m_ItemCount -= AmountToAdd; + if (ToAdd.m_ItemCount == 0) + { + return res; + } + } + } + + res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks); ToAdd.m_ItemCount = a_Item.m_ItemCount - res; + if (ToAdd.m_ItemCount == 0) { return res; @@ -131,12 +153,12 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT -int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) +int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks) { int TotalAdded = 0; for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();) { - int NumAdded = AddItem(*itr, a_AllowNewStacks, a_tryToFillEquippedFirst); + int NumAdded = AddItem(*itr, a_AllowNewStacks); if (itr->m_ItemCount == NumAdded) { itr = a_ItemStackList.erase(itr); diff --git a/src/Inventory.h b/src/Inventory.h index b2a8f658b..5501399bd 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -70,23 +70,17 @@ public: /** Adds as many items out of a_ItemStack as can fit. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. - If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or - compatible with added items) - if a_tryToFillEquippedFirst is set to false, the regular order applies. Returns the number of items that fit. */ - int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true, bool a_tryToFillEquippedFirst = false); + int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true); /** Same as AddItem, but works on an entire list of item stacks. The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. - If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or - compatible with added items) - if a_tryToFillEquippedFirst is set to false, the regular order applies. Returns the total number of items that fit. */ - int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst); + int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks); /** Removes the specified item from the inventory, as many as possible, up to a_ItemStack.m_ItemCount. Returns the number of items that were removed. */ diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 45b4030a3..0689670f9 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -103,7 +103,7 @@ public: ASSERT(!"Inventory bucket mismatch"); return true; } - if (a_Player->GetInventory().AddItem(cItem(NewItem), true, true) != 1) + if (a_Player->GetInventory().AddItem(cItem(NewItem)) != 1) { // The bucket didn't fit, toss it as a pickup: a_Player->TossPickup(cItem(NewItem)); @@ -151,7 +151,7 @@ public: return false; } cItem Item(E_ITEM_BUCKET, 1); - if (!a_Player->GetInventory().AddItem(Item, true, true)) + if (!a_Player->GetInventory().AddItem(Item)) { return false; } diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 6e944b4da..fba8c0a2c 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -60,7 +60,7 @@ public: return true; } - a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff))); return true; } diff --git a/src/Items/ItemMushroomSoup.h b/src/Items/ItemMushroomSoup.h index dba313ec5..1a761cbf1 100644 --- a/src/Items/ItemMushroomSoup.h +++ b/src/Items/ItemMushroomSoup.h @@ -41,7 +41,7 @@ public: // Return a bowl to the inventory if (!a_Player->IsGameModeCreative()) { - a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL)); } return true; } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 37683a8e5..5b58b18b6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1394,7 +1394,7 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) // cSlotAreaEnchanting: cSlotAreaEnchanting::cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) : - cSlotAreaTemporary(1, a_ParentWindow), + cSlotAreaTemporary(2, a_ParentWindow), m_BlockX(a_BlockX), m_BlockY(a_BlockY), m_BlockZ(a_BlockZ) @@ -2154,10 +2154,10 @@ bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item) { switch (a_SlotNum) { - case 0: return ItemCategory::IsHelmet (a_Item.m_ItemType); + case 0: return (ItemCategory::IsHelmet(a_Item.m_ItemType) || (a_Item.m_ItemType == E_BLOCK_PUMPKIN)); case 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType); - case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType); - case 3: return ItemCategory::IsBoots (a_Item.m_ItemType); + case 2: return ItemCategory::IsLeggings(a_Item.m_ItemType); + case 3: return ItemCategory::IsBoots(a_Item.m_ItemType); } return false; } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index d1c08acec..61e25651b 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -92,9 +92,9 @@ const AString cWindow::GetWindowTypeName(void) const int cWindow::GetNumSlots(void) const { int res = 0; - for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) + for (const auto & itr : m_SlotAreas) { - res += (*itr)->GetNumSlots(); + res += itr->GetNumSlots(); } // for itr - m_SlotAreas[] return res; } @@ -261,16 +261,14 @@ void cWindow::Clicked( } int LocalSlotNum = a_SlotNum; - int idx = 0; - for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) + for (const auto & itr : m_SlotAreas) { - if (LocalSlotNum < (*itr)->GetNumSlots()) + if (LocalSlotNum < itr->GetNumSlots()) { - (*itr)->Clicked(a_Player, LocalSlotNum, a_ClickAction, a_ClickedItem); + itr->Clicked(a_Player, LocalSlotNum, a_ClickAction, a_ClickedItem); return; } - LocalSlotNum -= (*itr)->GetNumSlots(); - idx++; + LocalSlotNum -= itr->GetNumSlots(); } LOGWARNING("Slot number higher than available window slots: %d, max %d received from \"%s\"; ignoring.", |