6 local function active_formspec(fuel_percent, item_percent)
12 "list[current_name;src;2.75,0.5;1,1;]"..
13 "list[current_name;fuel;2.75,2.5;1,1;]"..
14 "image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
15 (100-fuel_percent)..":default_furnace_fire_fg.png]"..
16 "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
17 (item_percent)..":gui_furnace_arrow_fg.png^[transformR270]"..
18 "list[current_name;dst;4.75,0.96;2,2;]"..
19 "list[current_player;main;0,4.25;8,1;]"..
20 "list[current_player;main;0,5.5;8,3;8]"..
21 default.get_hotbar_bg(0, 4.25)
25 local inactive_formspec =
30 "list[current_name;src;2.75,0.5;1,1;]"..
31 "list[current_name;fuel;2.75,2.5;1,1;]"..
32 "image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
33 "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
34 "list[current_name;dst;4.75,0.96;2,2;]"..
35 "list[current_player;main;0,4.25;8,1;]"..
36 "list[current_player;main;0,5.5;8,3;8]"..
37 default.get_hotbar_bg(0, 4.25)
40 -- Node callback functions that are the same for active and inactive furnace
43 local function can_dig(pos, player)
44 local meta = minetest.get_meta(pos);
45 local inv = meta:get_inventory()
46 return inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src")
49 local function allow_metadata_inventory_put(pos, listname, index, stack, player)
50 if minetest.is_protected(pos, player:get_player_name()) then
53 local meta = minetest.get_meta(pos)
54 local inv = meta:get_inventory()
55 if listname == "fuel" then
56 if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
57 if inv:is_empty("src") then
58 meta:set_string("infotext", "Furnace is empty")
60 return stack:get_count()
64 elseif listname == "src" then
65 return stack:get_count()
66 elseif listname == "dst" then
71 local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
72 local meta = minetest.get_meta(pos)
73 local inv = meta:get_inventory()
74 local stack = inv:get_stack(from_list, from_index)
75 return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
78 local function allow_metadata_inventory_take(pos, listname, index, stack, player)
79 if minetest.is_protected(pos, player:get_player_name()) then
82 return stack:get_count()
89 minetest.register_node("default:furnace", {
90 description = "Furnace",
92 "default_furnace_top.png", "default_furnace_bottom.png",
93 "default_furnace_side.png", "default_furnace_side.png",
94 "default_furnace_side.png", "default_furnace_front.png"
96 paramtype2 = "facedir",
98 legacy_facedir_simple = true,
99 is_ground_content = false,
100 sounds = default.node_sound_stone_defaults(),
104 allow_metadata_inventory_put = allow_metadata_inventory_put,
105 allow_metadata_inventory_move = allow_metadata_inventory_move,
106 allow_metadata_inventory_take = allow_metadata_inventory_take,
109 minetest.register_node("default:furnace_active", {
110 description = "Furnace",
112 "default_furnace_top.png", "default_furnace_bottom.png",
113 "default_furnace_side.png", "default_furnace_side.png",
114 "default_furnace_side.png",
116 image = "default_furnace_front_active.png",
117 backface_culling = false,
119 type = "vertical_frames",
126 paramtype2 = "facedir",
128 drop = "default:furnace",
129 groups = {cracky=2, not_in_creative_inventory=1},
130 legacy_facedir_simple = true,
131 is_ground_content = false,
132 sounds = default.node_sound_stone_defaults(),
136 aallow_metadata_inventory_put = allow_metadata_inventory_put,
137 allow_metadata_inventory_move = allow_metadata_inventory_move,
138 allow_metadata_inventory_take = allow_metadata_inventory_take,
145 local function swap_node(pos, name)
146 local node = minetest.get_node(pos)
147 if node.name == name then
151 minetest.swap_node(pos, node)
154 minetest.register_abm({
155 nodenames = {"default:furnace", "default:furnace_active"},
158 action = function(pos, node, active_object_count, active_object_count_wider)
160 -- Inizialize metadata
162 local meta = minetest.get_meta(pos)
163 local fuel_time = meta:get_float("fuel_time") or 0
164 local src_time = meta:get_float("src_time") or 0
165 local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
168 -- Inizialize inventory
170 local inv = meta:get_inventory()
171 for listname, size in pairs({
176 if inv:get_size(listname) ~= size then
177 inv:set_size(listname, size)
180 local srclist = inv:get_list("src")
181 local fuellist = inv:get_list("fuel")
182 local dstlist = inv:get_list("dst")
188 -- Check if we have cookable content
189 local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
190 local cookable = true
192 if cooked.time == 0 then
196 -- Check if we have enough fuel to burn
197 if fuel_time < fuel_totaltime then
198 -- The furnace is currently active and has enough fuel
199 fuel_time = fuel_time + 1
201 -- If there is a cookable item then check if it is ready yet
203 src_time = src_time + 1
204 if src_time >= cooked.time then
205 -- Place result in dst list if possible
206 if inv:room_for_item("dst", cooked.item) then
207 inv:add_item("dst", cooked.item)
208 inv:set_stack("src", 1, aftercooked.items[1])
214 -- Furnace ran out of fuel
216 -- We need to get new fuel
217 local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
219 if fuel.time == 0 then
220 -- No valid fuel in fuel list
225 -- Take fuel from fuel list
226 inv:set_stack("fuel", 1, afterfuel.items[1])
228 fuel_totaltime = fuel.time
233 -- We don't need to get new fuel since there is no cookable item
241 -- Update formspec, infotext and node
243 local formspec = inactive_formspec
244 local item_state = ""
245 local item_percent = 0
247 item_percent = math.floor(src_time / cooked.time * 100)
248 item_state = item_percent .. "%"
250 if srclist[1]:is_empty() then
253 item_state = "Not cookable"
257 local fuel_state = "Empty"
258 local active = "inactive "
259 if fuel_time <= fuel_totaltime and fuel_totaltime ~= 0 then
261 local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
262 fuel_state = fuel_percent .. "%"
263 formspec = active_formspec(fuel_percent, item_percent)
264 swap_node(pos, "default:furnace_active")
266 if not fuellist[1]:is_empty() then
269 swap_node(pos, "default:furnace")
272 local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
277 meta:set_float("fuel_totaltime", fuel_totaltime)
278 meta:set_float("fuel_time", fuel_time)
279 meta:set_float("src_time", src_time)
280 meta:set_string("formspec", formspec)
281 meta:set_string("infotext", infotext)