MCPcopy Create free account
hub / github.com/cuberite/cuberite / DistributeStack

Method DistributeStack

src/UI/SlotArea.cpp:245–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243
244
245void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots)
246{
247 for (int i = 0; i < m_NumSlots; i++)
248 {
249 const cItem * Slot = GetSlot(i, a_Player);
250 if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots))
251 {
252 // Different items
253 continue;
254 }
255 int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
256 if (NumFit <= 0)
257 {
258 // Full stack already
259 continue;
260 }
261 if (NumFit > a_ItemStack.m_ItemCount)
262 {
263 NumFit = a_ItemStack.m_ItemCount;
264 }
265 if (a_Apply)
266 {
267 cItem NewSlot(a_ItemStack);
268 NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit;
269 SetSlot(i, a_Player, NewSlot);
270 }
271 a_ItemStack.m_ItemCount -= NumFit;
272 if (a_ItemStack.IsEmpty())
273 {
274 return;
275 }
276 } // for i - Slots
277}
278
279
280

Callers 2

ShiftClickedMethod · 0.45
ShiftClickedResultMethod · 0.45

Calls 9

ItemHandlerFunction · 0.85
IsHelmetFunction · 0.85
IsChestPlateFunction · 0.85
IsLeggingsFunction · 0.85
IsBootsFunction · 0.85
IsEqualMethod · 0.80
CopyOneMethod · 0.80
IsEmptyMethod · 0.45
GetMaxStackSizeMethod · 0.45

Tested by

no test coverage detected