Improved bonfire
To work bonfire must be enabled by sticks. Fuel can burn without source.
This commit is contained in:
parent
486fdaedba
commit
3becd079fb
@ -2,15 +2,10 @@ bonfire = {}
|
||||
|
||||
bonfire.formspec =
|
||||
"invsize[8,9;]"..
|
||||
"image[0,2;1,1;default_furnace_fire_bg.png]"..
|
||||
"list[current_name;fuel;0,1;1,1;]"..
|
||||
"list[current_name;src;3,1;1,1;]"..
|
||||
"list[current_name;dst;2,3;2,1;]"..
|
||||
"list[current_name;add;5,1;2,2;]"..
|
||||
"label[3,0;Source:]"..
|
||||
"label[0,0;Fuel:]"..
|
||||
"label[2,2;Output:]"..
|
||||
"label[5,0;Additional:]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]"
|
||||
|
||||
minetest.register_node("bonfire:self", {
|
||||
@ -37,25 +32,19 @@ minetest.register_node("bonfire:self", {
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", bonfire.formspec)
|
||||
meta:set_string("infotext", "Bonfire")
|
||||
meta:set_int("active", 0)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 2)
|
||||
inv:set_size("add", 4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("fuel") then
|
||||
return false
|
||||
elseif not inv:is_empty("src") then
|
||||
return false
|
||||
elseif not inv:is_empty("dst") then
|
||||
return false
|
||||
elseif not inv:is_empty("add") then
|
||||
return false
|
||||
if inv:is_empty("fuel") and inv:is_empty("src") and inv:is_empty("dst") then
|
||||
return true
|
||||
end
|
||||
return true
|
||||
return false
|
||||
end,
|
||||
})
|
||||
|
||||
@ -84,25 +73,19 @@ minetest.register_node("bonfire:self_active", {
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", bonfire.formspec)
|
||||
meta:set_string("infotext", "Bonfire")
|
||||
meta:set_int("active", 0)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 2)
|
||||
inv:set_size("add", 4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("fuel") then
|
||||
return false
|
||||
elseif not inv:is_empty("src") then
|
||||
return false
|
||||
elseif not inv:is_empty("dst") then
|
||||
return false
|
||||
elseif not inv:is_empty("add") then
|
||||
return false
|
||||
if inv:is_empty("fuel") and inv:is_empty("src") and inv:is_empty("dst") then
|
||||
return true
|
||||
end
|
||||
return true
|
||||
return false
|
||||
end,
|
||||
})
|
||||
|
||||
@ -136,92 +119,81 @@ minetest.register_abm({
|
||||
meta:set_float(name, 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
if meta:get_int("active") == 1 then
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local srclist = inv:get_list("src")
|
||||
local cooked = nil
|
||||
local srclist = inv:get_list("src")
|
||||
local cooked = nil
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
|
||||
local was_active = false
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
was_active = true
|
||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||
-- check if there's room for output in "dst" list
|
||||
if inv:room_for_item("dst",cooked.item) then
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
--else
|
||||
--print("Could not insert '"..cooked.item.."'")
|
||||
end
|
||||
meta:set_string("src_time", 0)
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
end
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
local percent = math.floor(meta:get_float("fuel_time") /
|
||||
meta:get_float("fuel_totaltime") * 100)
|
||||
meta:set_string("infotext","Bonfire active: "..percent.."%")
|
||||
hacky_swap_node(pos,"bonfire:self_active")
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"image[0,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
(100-percent)..":default_furnace_fire_fg.png]"..
|
||||
"list[current_name;fuel;0,1;1,1;]"..
|
||||
"list[current_name;src;3,1;1,1;]"..
|
||||
"list[current_name;dst;2,3;2,1;]"..
|
||||
"list[current_name;add;5,1;2,2;]"..
|
||||
"label[3,0;Source:]"..
|
||||
"label[0,0;Fuel:]"..
|
||||
"label[2,2;Output:]"..
|
||||
"label[5,0;Additional:]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
return
|
||||
end
|
||||
|
||||
local fuel = nil
|
||||
local cooked = nil
|
||||
local fuellist = inv:get_list("fuel")
|
||||
local srclist = inv:get_list("src")
|
||||
local was_active = false
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
if fuellist then
|
||||
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||
end
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
was_active = true
|
||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||
-- check if there's room for output in "dst" list
|
||||
if inv:room_for_item("dst",cooked.item) then
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
--else
|
||||
--print("Could not insert '"..cooked.item.."'")
|
||||
end
|
||||
meta:set_string("src_time", 0)
|
||||
end
|
||||
end
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
local percent = math.floor(meta:get_float("fuel_time") /
|
||||
meta:get_float("fuel_totaltime") * 100)
|
||||
meta:set_string("infotext","Bonfire active: "..percent.."%")
|
||||
hacky_swap_node(pos,"bonfire:self_active")
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
(100-percent)..":default_furnace_fire_fg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
return
|
||||
end
|
||||
|
||||
if fuel.time <= 0 then
|
||||
meta:set_string("infotext","Bonfire out of fuel")
|
||||
hacky_swap_node(pos,"bonfire:self")
|
||||
meta:set_string("formspec", bonfire.formspec)
|
||||
return
|
||||
end
|
||||
local fuel = nil
|
||||
local cooked = nil
|
||||
local fuellist = inv:get_list("fuel")
|
||||
local srclist = inv:get_list("src")
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
if fuellist then
|
||||
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||
end
|
||||
|
||||
if cooked.item:is_empty() then
|
||||
if was_active then
|
||||
meta:set_string("infotext","Bonfire is empty")
|
||||
if fuel.time <= 0 then
|
||||
meta:set_string("infotext","Bonfire out of fuel")
|
||||
hacky_swap_node(pos,"bonfire:self")
|
||||
meta:set_string("formspec", bonfire.formspec)
|
||||
meta:set_int("active", 0)
|
||||
return
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
meta:set_string("fuel_totaltime", fuel.time)
|
||||
meta:set_string("fuel_time", 0)
|
||||
meta:set_string("fuel_totaltime", fuel.time)
|
||||
meta:set_string("fuel_time", 0)
|
||||
|
||||
local stack = inv:get_stack("fuel", 1)
|
||||
stack:take_item()
|
||||
inv:set_stack("fuel", 1, stack)
|
||||
local stack = inv:get_stack("fuel", 1)
|
||||
stack:take_item()
|
||||
inv:set_stack("fuel", 1, stack)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -4,7 +4,7 @@ minetest.register_tool("sticks:sticks", {
|
||||
on_use = function(item, user, pointed_thing)
|
||||
local pos
|
||||
if pointed_thing.type == "node" then
|
||||
if minetest.env:get_node(pointed_thing.under).name == "furnace:self" then
|
||||
if minetest.env:get_node(pointed_thing.under).name == "furnace:self" or minetest.env:get_node(pointed_thing.under).name == "bonfire:self" then
|
||||
local meta = minetest.env:get_meta(pointed_thing.under)
|
||||
meta:set_int("active", 1)
|
||||
item:add_wear(65535/10)
|
||||
@ -63,7 +63,6 @@ minetest.register_tool("sticks:sticks", {
|
||||
"list[current_name;fuel;3.5,5;1,1;]"..
|
||||
"list[current_player;main;0,6;8,4;]")
|
||||
if furnaceb > 9 then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:add_item("fuel", "default:coal_lump "..furnaceb-9)
|
||||
end
|
||||
@ -71,6 +70,18 @@ minetest.register_tool("sticks:sticks", {
|
||||
end
|
||||
if bonfireb >= 10 and minetest.env:get_node(pos).name == "air" then
|
||||
minetest.env:set_node(pos, {name = "bonfire:self"})
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_int("active", 1)
|
||||
meta:set_float("fuel_time", 0)
|
||||
meta:set_float("fuel_totaltime", 20)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png"..
|
||||
"^[lowpart:100:default_furnace_fire_fg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
end
|
||||
end
|
||||
item:add_wear(65535/10)
|
||||
|
Loading…
x
Reference in New Issue
Block a user