/// 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; }
/// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) { cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); if (Furnace == NULL) { LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); return false; } // Try move from the output slot: if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsOutput, true)) { cItem NewOutput(Furnace->GetOutputSlot()); Furnace->SetOutputSlot(NewOutput.AddCount(-1)); return true; } // No output moved, check if we can move an empty bucket out of the fuel slot: if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET) { if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsFuel, true)) { Furnace->SetFuelSlot(cItem()); return true; } } // Nothing can be moved return false; }
/// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) { cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); ASSERT(Furnace != NULL); // Try move from the output slot: if (MoveItemsFromSlot(Furnace->GetOutputSlot(), true)) { cItem NewOutput(Furnace->GetOutputSlot()); Furnace->SetOutputSlot(NewOutput.AddCount(-1)); return true; } // No output moved, check if we can move an empty bucket out of the fuel slot: if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET) { if (MoveItemsFromSlot(Furnace->GetFuelSlot(), true)) { Furnace->SetFuelSlot(cItem()); return true; } } // Nothing can be moved return false; }
bool cHopperEntity::MoveItemsFromGrid(cBlockEntityWithItems & a_Entity) { cItemGrid & Grid = a_Entity.GetContents(); int NumSlots = Grid.GetNumSlots(); for (int i = 0; i < NumSlots; i++) { if (Grid.IsSlotEmpty(i)) { continue; } if (MoveItemsFromSlot(a_Entity, i)) { Grid.ChangeSlotCount(i, -1); return true; } } return false; }