Exemple #1
0
/// Moves items from the specified ItemGrid into this hopper. Returns true if contents have changed.
bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
{
	int NumSlots = a_Grid.GetNumSlots();
	
	// First try adding items of types already in the hopper:
	for (int i = 0; i < NumSlots; i++)
	{
		if (a_Grid.IsSlotEmpty(i))
		{
			continue;
		}
		if (MoveItemsFromSlot(a_Grid.GetSlot(i), false))
		{
			a_Grid.ChangeSlotCount(i, -1);
			return true;
		}
	}

	// No already existing stack can be topped up, try again with allowing new stacks:
	for (int i = 0; i < NumSlots; i++)
	{
		if (a_Grid.IsSlotEmpty(i))
		{
			continue;
		}
		if (MoveItemsFromSlot(a_Grid.GetSlot(i), true))
		{
			a_Grid.ChangeSlotCount(i, -1);
			return true;
		}
	}
	return false;
}
void cEnderChestEntity::SaveToJson(Json::Value & a_Value, const cItemGrid & a_Grid)
{
	for (int i = 0; i < a_Grid.GetNumSlots(); i++)
	{
		Json::Value Slot;
		a_Grid.GetSlot(i).GetJson(Slot);
		a_Value.append(Slot);
	}
}
void cNBTChunkSerializer::AddItemGrid(const cItemGrid & a_Grid, int a_BeginSlotNum)
{
	int NumSlots = a_Grid.GetNumSlots();
	for (int i = 0; i < NumSlots; i++)
	{
		const cItem & Item = a_Grid.GetSlot(i);
		if (Item.IsEmpty())
		{
			continue;
		}
		AddItem(Item, i + a_BeginSlotNum);
	}  // for i - chest slots[]
}
Exemple #4
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 #5
0
cSlotAreaItemGrid::cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow) :
	super(a_ItemGrid.GetNumSlots(), a_ParentWindow),
	m_ItemGrid(a_ItemGrid)
{
	m_ItemGrid.AddListener(*this);
}