2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Furnace
|
|
|
|
--
|
|
|
|
|
|
|
|
function default.furnace_active_formspec(percent, item_percent)
|
2017-05-14 00:15:43 +02:00
|
|
|
local form = default.ui.get_page("default:2part")
|
2015-09-01 17:15:24 +02:00
|
|
|
form = form .. "list[current_player;main;0.25,4.75;8,4;]"
|
2015-09-01 17:41:00 +02:00
|
|
|
form = form .. "listring[current_player;main]"
|
2015-09-01 17:15:24 +02:00
|
|
|
form = form .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
|
|
|
|
form = form .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
|
|
|
|
|
|
|
|
form = form .. "list[current_name;src;2.25,0.75;1,1;]"
|
2015-09-01 17:41:00 +02:00
|
|
|
form = form .. "listring[current_name;src]"
|
2015-09-01 17:15:24 +02:00
|
|
|
form = form .. default.ui.get_itemslot_bg(2.25, 0.75, 1, 1)
|
|
|
|
|
|
|
|
form = form .. "list[current_name;fuel;2.25,2.75;1,1;]"
|
|
|
|
form = form .. default.ui.get_itemslot_bg(2.25, 2.75, 1, 1)
|
|
|
|
|
|
|
|
form = form .. "list[current_name;dst;4.25,1.25;2,2;]"
|
2015-09-01 17:41:00 +02:00
|
|
|
form = form .. "listring[current_name;dst]"
|
2015-09-01 17:15:24 +02:00
|
|
|
form = form .. default.ui.get_hotbar_itemslot_bg(4.25, 1.25, 2, 2)
|
|
|
|
|
|
|
|
form = form .. "image[2.25,1.75;1,1;ui_fire_bg.png^[lowpart:"
|
|
|
|
form = form .. (100-percent) .. ":ui_fire.png]"
|
|
|
|
form = form .. "image[3.25,1.75;1,1;ui_arrow_bg.png^[lowpart:"
|
|
|
|
form = form .. (item_percent) .. ":ui_arrow.png^[transformR270]"
|
|
|
|
|
2015-09-01 17:41:00 +02:00
|
|
|
return form
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-14 00:15:43 +02:00
|
|
|
local form_furnace = default.ui.get_page("default:2part")
|
2015-09-01 17:15:24 +02:00
|
|
|
form_furnace = form_furnace .. "list[current_player;main;0.25,4.75;8,4;]"
|
|
|
|
form_furnace = form_furnace .. "listring[current_player;main]"
|
|
|
|
form_furnace = form_furnace .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
|
|
|
|
form_furnace = form_furnace .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
|
|
|
|
|
|
|
|
form_furnace = form_furnace .. "list[current_name;src;2.25,0.75;1,1;]"
|
|
|
|
form_furnace = form_furnace .. "listring[current_name;src]"
|
|
|
|
form_furnace = form_furnace .. default.ui.get_itemslot_bg(2.25, 0.75, 1, 1)
|
|
|
|
|
|
|
|
form_furnace = form_furnace .. "list[current_name;fuel;2.25,2.75;1,1;]"
|
|
|
|
form_furnace = form_furnace .. default.ui.get_itemslot_bg(2.25, 2.75, 1, 1)
|
|
|
|
|
|
|
|
form_furnace = form_furnace .. "list[current_name;dst;4.25,1.25;2,2;]"
|
|
|
|
form_furnace = form_furnace .. "listring[current_name;dst]"
|
|
|
|
form_furnace = form_furnace .. default.ui.get_hotbar_itemslot_bg(4.25, 1.25, 2, 2)
|
|
|
|
|
|
|
|
form_furnace = form_furnace .. "image[2.25,1.75;1,1;ui_fire_bg.png]"
|
|
|
|
form_furnace = form_furnace .. "image[3.25,1.75;1,1;ui_arrow_bg.png^[transformR270]"
|
|
|
|
|
|
|
|
default.ui.register_page("default_furnace_inactive", form_furnace)
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_node(
|
2015-09-01 17:15:24 +02:00
|
|
|
"default:furnace",
|
|
|
|
{
|
|
|
|
description = "Furnace",
|
|
|
|
tiles ={"default_furnace_top.png", "default_furnace_top.png", "default_furnace_sides.png",
|
|
|
|
"default_furnace_sides.png", "default_furnace_sides.png", "default_furnace_front.png"},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {cracky = 2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
on_construct = function(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
meta:set_string("formspec", default.ui.get_page("default_furnace_inactive"))
|
|
|
|
meta:set_string("infotext", "Furnace")
|
|
|
|
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("fuel", 1)
|
|
|
|
inv:set_size("src", 1)
|
|
|
|
inv:set_size("dst", 4)
|
|
|
|
end,
|
|
|
|
can_dig = function(pos,player)
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos);
|
2015-09-01 17:15:24 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if not inv:is_empty("fuel") then
|
|
|
|
return false
|
|
|
|
elseif not inv:is_empty("dst") then
|
|
|
|
return false
|
|
|
|
elseif not inv:is_empty("src") then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_node(
|
2015-09-01 17:15:24 +02:00
|
|
|
"default:furnace_active",
|
|
|
|
{
|
|
|
|
description = "Furnace",
|
|
|
|
tiles ={"default_furnace_top.png", "default_furnace_top.png", "default_furnace_sides.png",
|
|
|
|
"default_furnace_sides.png", "default_furnace_sides.png", "default_furnace_front.png^default_furnace_flame.png"},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
light_source = 8,
|
|
|
|
drop = "default:furnace",
|
|
|
|
groups = {cracky = 2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
on_construct = function(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
meta:set_string("formspec", default.ui.get_page("default_furnace_inactive"))
|
|
|
|
meta:set_string("infotext", "Furnace");
|
|
|
|
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("fuel", 1)
|
|
|
|
inv:set_size("src", 1)
|
|
|
|
inv:set_size("dst", 4)
|
|
|
|
end,
|
|
|
|
can_dig = function(pos,player)
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos);
|
2015-09-01 17:15:24 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if not inv:is_empty("fuel") then
|
|
|
|
return false
|
|
|
|
elseif not inv:is_empty("dst") then
|
|
|
|
return false
|
|
|
|
elseif not inv:is_empty("src") then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
function swap_node(pos, name)
|
2017-05-12 04:29:55 +02:00
|
|
|
local node = minetest.get_node(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.swap_node(pos, node)
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_abm(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2017-05-19 23:04:11 +02:00
|
|
|
label = "Furnace",
|
2015-09-01 17:15:24 +02:00
|
|
|
nodenames = {"default:furnace", "default:furnace_active"},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
--
|
|
|
|
-- Initialize metadata
|
|
|
|
--
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
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
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Initialize inventory
|
|
|
|
--
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for listname, size in pairs(
|
|
|
|
{
|
|
|
|
src = 1,
|
|
|
|
fuel = 1,
|
|
|
|
dst = 4,
|
|
|
|
}) do
|
|
|
|
if inv:get_size(listname) ~= size then
|
|
|
|
inv:set_size(listname, size)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local srclist = inv:get_list("src")
|
|
|
|
local fuellist = inv:get_list("fuel")
|
|
|
|
local dstlist = inv:get_list("dst")
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Cooking
|
|
|
|
--
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
-- Check if we have cookable content
|
2017-05-12 04:29:55 +02:00
|
|
|
local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
2015-09-01 17:15:24 +02:00
|
|
|
local cookable = true
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if cooked.time == 0 then
|
|
|
|
cookable = false
|
|
|
|
end
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
-- Check if we have enough fuel to burn
|
|
|
|
if fuel_time < fuel_totaltime then
|
|
|
|
-- The furnace is currently active and has enough fuel
|
|
|
|
fuel_time = fuel_time + 1
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
-- If there is a cookable item then check if it is ready yet
|
|
|
|
if cookable then
|
|
|
|
src_time = src_time + 1
|
|
|
|
if src_time >= cooked.time then
|
|
|
|
-- Place result in dst list if possible
|
|
|
|
if inv:room_for_item("dst", cooked.item) then
|
|
|
|
inv:add_item("dst", cooked.item)
|
|
|
|
inv:set_stack("src", 1, aftercooked.items[1])
|
|
|
|
src_time = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Furnace ran out of fuel
|
|
|
|
if cookable then
|
|
|
|
-- We need to get new fuel
|
2017-05-12 04:29:55 +02:00
|
|
|
local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if fuel.time == 0 then
|
|
|
|
-- No valid fuel in fuel list
|
|
|
|
fuel_totaltime = 0
|
|
|
|
fuel_time = 0
|
|
|
|
src_time = 0
|
|
|
|
else
|
|
|
|
-- Take fuel from fuel list
|
|
|
|
inv:set_stack("fuel", 1, afterfuel.items[1])
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
fuel_totaltime = fuel.time
|
|
|
|
fuel_time = 0
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
-- We don't need to get new fuel since there is no cookable item
|
|
|
|
fuel_totaltime = 0
|
|
|
|
fuel_time = 0
|
|
|
|
src_time = 0
|
|
|
|
end
|
|
|
|
end
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Update formspec, infotext and node
|
|
|
|
--
|
|
|
|
local formspec = default.ui.get_page("default_furnace_inactive")
|
|
|
|
local item_state = ""
|
|
|
|
local item_percent = 0
|
|
|
|
if cookable then
|
|
|
|
item_percent = math.floor(src_time / cooked.time * 100)
|
|
|
|
item_state = item_percent .. "%"
|
|
|
|
else
|
|
|
|
if srclist[1]:is_empty() then
|
|
|
|
item_state = "Empty"
|
|
|
|
else
|
|
|
|
item_state = "Not cookable"
|
|
|
|
end
|
|
|
|
end
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local fuel_state = "Empty"
|
|
|
|
local active = "inactive "
|
|
|
|
if fuel_time <= fuel_totaltime and fuel_totaltime ~= 0 then
|
|
|
|
active = "active "
|
|
|
|
local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
|
|
|
|
fuel_state = fuel_percent .. "%"
|
|
|
|
formspec = default.furnace_active_formspec(fuel_percent, item_percent)
|
|
|
|
swap_node(pos, "default:furnace_active")
|
|
|
|
else
|
|
|
|
if not fuellist[1]:is_empty() then
|
|
|
|
fuel_state = "0%"
|
|
|
|
end
|
|
|
|
swap_node(pos, "default:furnace")
|
|
|
|
end
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
|
2017-05-14 00:15:43 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Set meta values
|
|
|
|
--
|
|
|
|
meta:set_float("fuel_totaltime", fuel_totaltime)
|
|
|
|
meta:set_float("fuel_time", fuel_time)
|
|
|
|
meta:set_float("src_time", src_time)
|
|
|
|
meta:set_string("formspec", formspec)
|
|
|
|
meta:set_string("infotext", infotext)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-05-14 00:15:43 +02:00
|
|
|
default.log("furnace", "loaded")
|