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

Method LoadFromJson

src/Inventory.cpp:589–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587
588
589bool cInventory::LoadFromJson(Json::Value & a_Value)
590{
591 int SlotIdx = 0;
592
593 for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr, SlotIdx++)
594 {
595 cItem Item;
596 Item.FromJson(*itr);
597
598 // The JSON originally included the 4 crafting slots and the result slot, so we need to skip the first 5 items:
599 if (SlotIdx < 5)
600 {
601 continue;
602 }
603
604 // If we loaded all the slots, stop now, even if the JSON has more:
605 if (SlotIdx - 5 >= invNumSlots)
606 {
607 break;
608 }
609
610 int GridSlotNum = 0;
611 cItemGrid * Grid = GetGridForSlotNum(SlotIdx - 5, GridSlotNum);
612 ASSERT(Grid != NULL);
613 Grid->SetSlot(GridSlotNum, Item);
614 } // for itr - a_Value[]
615 return true;
616}
617
618
619

Callers

nothing calls this directly

Calls 4

beginMethod · 0.80
endMethod · 0.80
FromJsonMethod · 0.80
SetSlotMethod · 0.45

Tested by

no test coverage detected