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

Method MoveItemsToSlot

src/BlockEntities/HopperEntity.cpp:599–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

597
598
599bool cHopperEntity::MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstSlotNum)
600{
601 cItemGrid & Grid = a_Entity.GetContents();
602 if (Grid.IsSlotEmpty(a_DstSlotNum))
603 {
604 // The slot is empty, move the first non-empty slot from our contents:
605 for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
606 {
607 if (!m_Contents.IsSlotEmpty(i))
608 {
609 if (cPluginManager::Get()->CallHookHopperPushingItem(*m_World, *this, i, a_Entity, a_DstSlotNum))
610 {
611 // A plugin disagrees with the move
612 continue;
613 }
614 Grid.SetSlot(a_DstSlotNum, m_Contents.GetSlot(i).CopyOne());
615 m_Contents.ChangeSlotCount(i, -1);
616 return true;
617 }
618 }
619 return false;
620 }
621 else
622 {
623 // The slot is taken, try to top it up:
624 const cItem & DestSlot = Grid.GetSlot(a_DstSlotNum);
625 if (DestSlot.IsFullStack())
626 {
627 return false;
628 }
629 for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
630 {
631 if (m_Contents.GetSlot(i).IsEqual(DestSlot))
632 {
633 if (cPluginManager::Get()->CallHookHopperPushingItem(*m_World, *this, i, a_Entity, a_DstSlotNum))
634 {
635 // A plugin disagrees with the move
636 continue;
637 }
638 Grid.ChangeSlotCount(a_DstSlotNum, 1);
639 m_Contents.ChangeSlotCount(i, -1);
640 return true;
641 }
642 }
643 return false;
644 }
645}
646
647
648

Callers

nothing calls this directly

Calls 8

IsSlotEmptyMethod · 0.80
CopyOneMethod · 0.80
IsFullStackMethod · 0.80
IsEqualMethod · 0.80
SetSlotMethod · 0.45
GetSlotMethod · 0.45
ChangeSlotCountMethod · 0.45

Tested by

no test coverage detected