1
0

Merge pull request #2061 from mc-server/fixes

Fixes
This commit is contained in:
Alexander Harkness 2015-05-27 12:21:17 +01:00
commit da4a76bb50
8 changed files with 43 additions and 28 deletions

View File

@ -228,6 +228,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest)
m_Item.m_ItemCount -= NumAdded; m_Item.m_ItemCount -= NumAdded;
m_World->BroadcastCollectEntity(*this, a_Dest); m_World->BroadcastCollectEntity(*this, a_Dest);
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) // 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)); m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
if (m_Item.m_ItemCount <= 0) if (m_Item.m_ItemCount <= 0)

View File

@ -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); cItem ToAdd(a_Item);
int res = 0; 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; ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
if (ToAdd.m_ItemCount == 0) if (ToAdd.m_ItemCount == 0)
{ {
return res; 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; int TotalAdded = 0;
for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();) 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) if (itr->m_ItemCount == NumAdded)
{ {
itr = a_ItemStackList.erase(itr); itr = a_ItemStackList.erase(itr);

View File

@ -70,23 +70,17 @@ public:
/** Adds as many items out of a_ItemStack as can fit. /** 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 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_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. 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. /** Same as AddItem, but works on an entire list of item stacks.
The a_ItemStackList is modified to reflect the leftover items. 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 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_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. 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. /** 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. */ Returns the number of items that were removed. */

View File

@ -103,7 +103,7 @@ public:
ASSERT(!"Inventory bucket mismatch"); ASSERT(!"Inventory bucket mismatch");
return true; 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: // The bucket didn't fit, toss it as a pickup:
a_Player->TossPickup(cItem(NewItem)); a_Player->TossPickup(cItem(NewItem));
@ -151,7 +151,7 @@ public:
return false; return false;
} }
cItem Item(E_ITEM_BUCKET, 1); cItem Item(E_ITEM_BUCKET, 1);
if (!a_Player->GetInventory().AddItem(Item, true, true)) if (!a_Player->GetInventory().AddItem(Item))
{ {
return false; return false;
} }

View File

@ -60,7 +60,7 @@ public:
return true; 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; return true;
} }

View File

@ -41,7 +41,7 @@ public:
// Return a bowl to the inventory // Return a bowl to the inventory
if (!a_Player->IsGameModeCreative()) if (!a_Player->IsGameModeCreative())
{ {
a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL), true, true); a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL));
} }
return true; return true;
} }

View File

@ -1394,7 +1394,7 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
// cSlotAreaEnchanting: // cSlotAreaEnchanting:
cSlotAreaEnchanting::cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) : 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_BlockX(a_BlockX),
m_BlockY(a_BlockY), m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ) m_BlockZ(a_BlockZ)
@ -2154,10 +2154,10 @@ bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item)
{ {
switch (a_SlotNum) 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 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType);
case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType); case 2: return ItemCategory::IsLeggings(a_Item.m_ItemType);
case 3: return ItemCategory::IsBoots (a_Item.m_ItemType); case 3: return ItemCategory::IsBoots(a_Item.m_ItemType);
} }
return false; return false;
} }

View File

@ -92,9 +92,9 @@ const AString cWindow::GetWindowTypeName(void) const
int cWindow::GetNumSlots(void) const int cWindow::GetNumSlots(void) const
{ {
int res = 0; 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[] } // for itr - m_SlotAreas[]
return res; return res;
} }
@ -261,16 +261,14 @@ void cWindow::Clicked(
} }
int LocalSlotNum = a_SlotNum; int LocalSlotNum = a_SlotNum;
int idx = 0; for (const auto & itr : m_SlotAreas)
for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
{ {
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; return;
} }
LocalSlotNum -= (*itr)->GetNumSlots(); LocalSlotNum -= itr->GetNumSlots();
idx++;
} }
LOGWARNING("Slot number higher than available window slots: %d, max %d received from \"%s\"; ignoring.", LOGWARNING("Slot number higher than available window slots: %d, max %d received from \"%s\"; ignoring.",