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

Method SetSlot

src/Inventory.cpp:191–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189
190
191void cInventory::SetSlot(int a_SlotNum, const cItem & a_Item)
192{
193 if ((a_SlotNum < 0) || (a_SlotNum >= invNumSlots))
194 {
195 LOGWARNING("%s: requesting an invalid slot index: %d out of %d. Ignoring.", __FUNCTION__, a_SlotNum, invNumSlots - 1);
196 return;
197 }
198
199 int GridSlotNum = 0;
200 cItemGrid * Grid = GetGridForSlotNum(a_SlotNum, GridSlotNum);
201 if (Grid == NULL)
202 {
203 LOGWARNING("%s(%d): requesting an invalid itemgrid. Ignoring.", __FUNCTION__, a_SlotNum);
204 return;
205 }
206 Grid->SetSlot(GridSlotNum, a_Item);
207
208 // Broadcast the Equipped Item, if the Slot is changed.
209 if ((Grid == &m_HotbarSlots) && (m_EquippedSlotNum == (a_SlotNum - invHotbarOffset)))
210 {
211 m_Owner.GetWorld()->BroadcastEntityEquipment(m_Owner, 0, a_Item, m_Owner.GetClientHandle());
212 }
213}
214
215
216

Callers 4

SetArmorSlotMethod · 0.45
SetInventorySlotMethod · 0.45
SetHotbarSlotMethod · 0.45
LoadFromJsonMethod · 0.45

Calls 3

GetClientHandleMethod · 0.80
GetWorldMethod · 0.45

Tested by

no test coverage detected