//return "Furnace";
if(m_fuel_time >= m_fuel_totaltime)
{
- InventoryList *src_list = m_inventory->getList("src");
+ const InventoryList *src_list = m_inventory->getList("src");
assert(src_list);
- InventoryItem *src_item = src_list->getItem(0);
+ const InventoryItem *src_item = src_list->getItem(0);
- if(src_item)
+ if(src_item && src_item->isCookable()) {
+ InventoryList *dst_list = m_inventory->getList("dst");
+ if(!dst_list->roomForCookedItem(src_item))
+ return "Furnace is overloaded";
return "Furnace is out of fuel";
+ }
else
return "Furnace is inactive";
}
else
{
- std::string s = "Furnace is active (";
- s += itos(m_fuel_time/m_fuel_totaltime*100);
- s += "%)";
+ std::string s = "Furnace is active";
+ // Do this so it doesn't always show (0%) for weak fuel
+ if(m_fuel_totaltime > 3) {
+ s += " (";
+ s += itos(m_fuel_time/m_fuel_totaltime*100);
+ s += "%)";
+ }
return s;
}
}
+bool FurnaceNodeMetadata::nodeRemovalDisabled()
+{
+ /*
+ Disable removal if furnace is not empty
+ */
+ InventoryList *list[3] = {m_inventory->getList("src"),
+ m_inventory->getList("dst"), m_inventory->getList("fuel")};
+
+ for(int i = 0; i < 3; i++) {
+ if(list[i] == NULL)
+ continue;
+ if(list[i]->getUsedSlots() == 0)
+ continue;
+ return true;
+ }
+ return false;
+
+}
void FurnaceNodeMetadata::inventoryModified()
{
dstream<<"Furnace inventory modification callback"<<std::endl;
assert(src_list);
InventoryItem *src_item = src_list->getItem(0);
+ bool room_available = false;
+
+ if(src_item && src_item->isCookable())
+ room_available = dst_list->roomForCookedItem(src_item);
+
// Start only if there are free slots in dst, so that it can
// accomodate any result item
- if(dst_list->getFreeSlots() > 0 && src_item && src_item->isCookable())
+ if(room_available)
{
m_src_totaltime = 3;
}
m_src_totaltime = 0;
}
changed = true;
- continue;
+
+ // If the fuel was not used up this step, just keep burning it
+ if(m_fuel_time < m_fuel_totaltime)
+ continue;
}
/*
- If there is no source item or source item is not cookable, stop loop.
+ Get the source again in case it has all burned
+ */
+ src_item = src_list->getItem(0);
+
+ /*
+ If there is no source item, or the source item is not cookable,
+ or the furnace is still cooking, or the furnace became overloaded, stop loop.
*/
- if(src_item == NULL || m_src_totaltime < 0.001)
+ if(src_item == NULL || !room_available || m_fuel_time < m_fuel_totaltime ||
+ dst_list->roomForCookedItem(src_item) == false)
{
m_step_accumulator = 0;
break;
InventoryList *fuel_list = m_inventory->getList("fuel");
assert(fuel_list);
- InventoryItem *fuel_item = fuel_list->getItem(0);
+ const InventoryItem *fuel_item = fuel_list->getItem(0);
if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(fuel_item))
{