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

Method HowManyCanFit

src/ItemGrid.cpp:216–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214
215
216int cItemGrid::HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks)
217{
218 char NumLeft = a_ItemStack.m_ItemCount;
219 int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize();
220 for (int i = m_NumSlots - 1; i >= 0; i--)
221 {
222 if (m_Slots[i].IsEmpty())
223 {
224 if (a_AllowNewStacks)
225 {
226 NumLeft -= MaxStack;
227 }
228 }
229 else if (m_Slots[i].IsEqual(a_ItemStack))
230 {
231 NumLeft -= MaxStack - m_Slots[i].m_ItemCount;
232 }
233 if (NumLeft <= 0)
234 {
235 // All items fit
236 return a_ItemStack.m_ItemCount;
237 }
238 } // for i - m_Slots[]
239 return a_ItemStack.m_ItemCount - NumLeft;
240}
241
242
243

Callers 2

ScoopUpLiquidMethod · 0.45
EmptyLiquidBucketMethod · 0.45

Calls 4

ItemHandlerFunction · 0.85
IsEqualMethod · 0.80
GetMaxStackSizeMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected