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 "listring[current_name;dst]"..
22 "listring[current_player;main]"..
23 "listring[current_name;src]"..
24 "listring[current_player;main]"..
25 default.get_hotbar_bg(0, 4.25)
29 local inactive_formspec =
34 "list[current_name;src;2.75,0.5;1,1;]"..
35 "list[current_name;fuel;2.75,2.5;1,1;]"..
36 "image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
37 "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
38 "list[current_name;dst;4.75,0.96;2,2;]"..
39 "list[current_player;main;0,4.25;8,1;]"..
40 "list[current_player;main;0,5.5;8,3;8]"..
41 "listring[current_name;dst]"..
42 "listring[current_player;main]"..
43 "listring[current_name;src]"..
44 "listring[current_player;main]"..
45 default.get_hotbar_bg(0, 4.25)
48 -- Node callback functions that are the same for active and inactive furnace
51 local function can_dig(pos, player)
52 local meta = minetest.get_meta(pos);
53 local inv = meta:get_inventory()
54 return inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src")
57 local function allow_metadata_inventory_put(pos, listname, index, stack, player)
58 if minetest.is_protected(pos, player:get_player_name()) then
61 local meta = minetest.get_meta(pos)
62 local inv = meta:get_inventory()
63 if listname == "fuel" then
64 if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
65 if inv:is_empty("src") then
66 meta:set_string("infotext", "Furnace is empty")
68 return stack:get_count()
72 elseif listname == "src" then
73 return stack:get_count()
74 elseif listname == "dst" then
79 local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
80 local meta = minetest.get_meta(pos)
81 local inv = meta:get_inventory()
82 local stack = inv:get_stack(from_list, from_index)
83 return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
86 local function allow_metadata_inventory_take(pos, listname, index, stack, player)
87 if minetest.is_protected(pos, player:get_player_name()) then
90 return stack:get_count()
97 minetest.register_node("default:furnace", {
98 description = "Furnace",
100 "default_furnace_top.png", "default_furnace_bottom.png",
101 "default_furnace_side.png", "default_furnace_side.png",
102 "default_furnace_side.png", "default_furnace_front.png"
104 paramtype2 = "facedir",
106 legacy_facedir_simple = true,
107 is_ground_content = false,
108 sounds = default.node_sound_stone_defaults(),
112 allow_metadata_inventory_put = allow_metadata_inventory_put,
113 allow_metadata_inventory_move = allow_metadata_inventory_move,
114 allow_metadata_inventory_take = allow_metadata_inventory_take,
117 minetest.register_node("default:furnace_active", {
118 description = "Furnace",
120 "default_furnace_top.png", "default_furnace_bottom.png",
121 "default_furnace_side.png", "default_furnace_side.png",
122 "default_furnace_side.png",
124 image = "default_furnace_front_active.png",
125 backface_culling = false,
127 type = "vertical_frames",
134 paramtype2 = "facedir",
136 drop = "default:furnace",
137 groups = {cracky=2, not_in_creative_inventory=1},
138 legacy_facedir_simple = true,
139 is_ground_content = false,
140 sounds = default.node_sound_stone_defaults(),
144 allow_metadata_inventory_put = allow_metadata_inventory_put,
145 allow_metadata_inventory_move = allow_metadata_inventory_move,
146 allow_metadata_inventory_take = allow_metadata_inventory_take,
153 local function swap_node(pos, name)
154 local node = minetest.get_node(pos)
155 if node.name == name then
159 minetest.swap_node(pos, node)
162 minetest.register_abm({
163 nodenames = {"default:furnace", "default:furnace_active"},
166 action = function(pos, node, active_object_count, active_object_count_wider)
168 -- Inizialize metadata
170 local meta = minetest.get_meta(pos)
171 local fuel_time = meta:get_float("fuel_time") or 0
172 local src_time = meta:get_float("src_time") or 0
173 local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
176 -- Inizialize inventory
178 local inv = meta:get_inventory()
179 for listname, size in pairs({
184 if inv:get_size(listname) ~= size then
185 inv:set_size(listname, size)
188 local srclist = inv:get_list("src")
189 local fuellist = inv:get_list("fuel")
190 local dstlist = inv:get_list("dst")
196 -- Check if we have cookable content
197 local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
198 local cookable = true
200 if cooked.time == 0 then
204 -- Check if we have enough fuel to burn
205 if fuel_time < fuel_totaltime then
206 -- The furnace is currently active and has enough fuel
207 fuel_time = fuel_time + 1
209 -- If there is a cookable item then check if it is ready yet
211 src_time = src_time + 1
212 if src_time >= cooked.time then
213 -- Place result in dst list if possible
214 if inv:room_for_item("dst", cooked.item) then
215 inv:add_item("dst", cooked.item)
216 inv:set_stack("src", 1, aftercooked.items[1])
222 -- Furnace ran out of fuel
224 -- We need to get new fuel
225 local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
227 if fuel.time == 0 then
228 -- No valid fuel in fuel list
233 -- Take fuel from fuel list
234 inv:set_stack("fuel", 1, afterfuel.items[1])
236 fuel_totaltime = fuel.time
241 -- We don't need to get new fuel since there is no cookable item
249 -- Update formspec, infotext and node
251 local formspec = inactive_formspec
252 local item_state = ""
253 local item_percent = 0
255 item_percent = math.floor(src_time / cooked.time * 100)
256 item_state = item_percent .. "%"
258 if srclist[1]:is_empty() then
261 item_state = "Not cookable"
265 local fuel_state = "Empty"
266 local active = "inactive "
267 if fuel_time <= fuel_totaltime and fuel_totaltime ~= 0 then
269 local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
270 fuel_state = fuel_percent .. "%"
271 formspec = active_formspec(fuel_percent, item_percent)
272 swap_node(pos, "default:furnace_active")
274 if not fuellist[1]:is_empty() then
277 swap_node(pos, "default:furnace")
280 local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
285 meta:set_float("fuel_totaltime", fuel_totaltime)
286 meta:set_float("fuel_time", fuel_time)
287 meta:set_float("src_time", src_time)
288 meta:set_string("formspec", formspec)
289 meta:set_string("infotext", infotext)