void cEnderChestEntity::LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid)
{
	int SlotIdx = 0;
	for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr)
	{
		cItem Item;
		Item.FromJson(*itr);
		a_Grid.SetSlot(SlotIdx, Item);
		SlotIdx++;
	}
}
Exemple #2
0
void cWSSAnvil::LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a_NBT, int a_ItemsTagIdx, int a_SlotOffset)
{
    int NumSlots = a_ItemGrid.GetNumSlots();
    for (int Child = a_NBT.GetFirstChild(a_ItemsTagIdx); Child != -1; Child = a_NBT.GetNextSibling(Child))
    {
        int SlotTag = a_NBT.FindChildByName(Child, "Slot");
        if ((SlotTag < 0) || (a_NBT.GetType(SlotTag) != TAG_Byte))
        {
            continue;
        }
        int SlotNum = (int)(a_NBT.GetByte(SlotTag)) - a_SlotOffset;
        if ((SlotNum < 0) || (SlotNum >= NumSlots))
        {
            // SlotNum outside of the range
            continue;
        }
        cItem Item;
        if (LoadItemFromNBT(Item, a_NBT, Child))
        {
            a_ItemGrid.SetSlot(SlotNum, Item);
        }
    }  // for itr - ItemDefs[]
}
Exemple #3
0
/// Moves one piece to the specified ItemGrid's slot. Returns true if contents have changed.
bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
{
	if (a_ItemGrid.IsSlotEmpty(a_DestSlotNum))
	{
		// The slot is empty, move the first non-empty slot from our contents:
		for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
		{
			if (!m_Contents.IsSlotEmpty(i))
			{
				a_ItemGrid.SetSlot(a_DestSlotNum, m_Contents.GetSlot(i).CopyOne());
				m_Contents.ChangeSlotCount(i, -1);
				return true;
			}
		}
		return false;
	}
	else
	{
		// The slot is taken, try to top it up:
		const cItem & DestSlot = a_ItemGrid.GetSlot(a_DestSlotNum);
		if (DestSlot.IsFullStack())
		{
			return false;
		}
		for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
		{
			if (m_Contents.GetSlot(i).IsStackableWith(DestSlot))
			{
				a_ItemGrid.ChangeSlotCount(a_DestSlotNum, 1);
				m_Contents.ChangeSlotCount(i, -1);
				return true;
			}
		}
		return false;
	}
}