- on_activate = function(self, staticdata, dtime_s)
- if string.sub(staticdata, 1, string.len("return")) == "return" then
- local data = minetest.deserialize(staticdata)
- if data and type(data) == "table" then
- self.itemstring = data.itemstring
- self.count = data.count
- end
- else
- self.itemstring = staticdata
- end
- self.object:set_armor_groups({immortal = 1})
- self.object:set_velocity({x = 0, y = 0, z = 0})
- self.object:set_acceleration({x = 0, y = 0, z = 0})
- self:set_item()
- end,
-
- on_rightclick = function(self, clicker)
-
- if not clicker or not clicker:is_player() then
- return
- end
-
- local stack = clicker:get_wielded_item()
-
- local item = stack:get_name()
- local count = stack:get_count()
- if stack:get_name() == "utility:nothing" then
- count = 0
- end
-
- --shoot out existing item
- if self.itemstring ~= item.." "..count and self.itemstring ~= "utility:nothing" then
- local pos = self.object:getpos()
- local pos2 = clicker:getpos()
- pos2.y = pos2.y + 1.25
- local obj = minetest.add_item(pos,self.itemstring)
- local dir = vector.subtract(pos2,pos)
- vector.multiply(dir,5)
-
- if obj then
- obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
- obj:get_luaentity().collection_timer = 2
- else
- print("ERROR FURNACE RELEASED NON ITEM")
- end
- end
-
- if (item == "" or item == "hand:player") then
- self.set_item(self,"utility:nothing")
- self.object:set_nametag_attributes({
- color = "red",
- text = "",
- })
- return
- end
-
- self.set_item(self, item.." "..count)
-
- self.object:set_nametag_attributes({
- color = "red",
- text = minetest.registered_items[item].description.." "..count,
- })
-
- stack = stack:clear()
- clicker:set_wielded_item("")
- end,
-
- on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
- if not puncher or not puncher:is_player() then
- return
- end
-
- if self.itemstring == "utility:nothing" then
- return
- end
-
- local pos = self.object:getpos()
- local pos2 = puncher:getpos()
- pos2.y = pos2.y + 1.25
-
- local obj = minetest.add_item(pos,self.itemstring)
- local dir = vector.subtract(pos2,pos)
- vector.multiply(dir,5)
-
- self.set_item(self,"utility:nothing")
- self.object:set_nametag_attributes({
- color = "red",
- text = "",
- })
-
- if obj then
- obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
- obj:get_luaentity().collection_timer = 2
- else
- print("ERROR FURNACE RELEASED NON ITEM")
+local function furnace_node_timer(pos, elapsed)
+ --
+ -- Initialize metadata
+ --
+ local meta = minetest.get_meta(pos)
+ local fuel_time = meta:get_float("fuel_time") or 0
+ local src_time = meta:get_float("src_time") or 0
+ local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
+
+ local inv = meta:get_inventory()
+ local srclist, fuellist
+ local dst_full = false
+
+ local cookable, cooked
+ local fuel
+
+ local update = true
+ while elapsed > 0 and update do
+ update = false
+
+ srclist = inv:get_list("src")
+ fuellist = inv:get_list("fuel")
+
+ --
+ -- Cooking
+ --
+
+ -- Check if we have cookable content
+ local aftercooked
+ cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
+ cookable = cooked.time ~= 0
+
+ local el = math.min(elapsed, fuel_totaltime - fuel_time)
+ if cookable then -- fuel lasts long enough, adjust el to cooking duration
+ el = math.min(el, cooked.time - src_time)