Improved bonfire

To work bonfire must be enabled by sticks. Fuel can burn without source.
This commit is contained in:
Kotolegokot 2012-10-14 15:37:57 +06:00
parent 486fdaedba
commit 3becd079fb
2 changed files with 91 additions and 108 deletions

View File

@ -2,15 +2,10 @@ bonfire = {}
bonfire.formspec = bonfire.formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[0,2;1,1;default_furnace_fire_bg.png]".. "image[2,2;1,1;default_furnace_fire_bg.png]"..
"list[current_name;fuel;0,1;1,1;]".. "list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;src;2,1;1,1;]"..
"list[current_name;dst;2,3;2,1;]".. "list[current_name;dst;5,1;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;]" "list[current_player;main;0,5;8,4;]"
minetest.register_node("bonfire:self", { minetest.register_node("bonfire:self", {
@ -37,25 +32,19 @@ minetest.register_node("bonfire:self", {
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", bonfire.formspec) meta:set_string("formspec", bonfire.formspec)
meta:set_string("infotext", "Bonfire") meta:set_string("infotext", "Bonfire")
meta:set_int("active", 0)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("fuel", 1) inv:set_size("fuel", 1)
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 2) inv:set_size("dst", 2)
inv:set_size("add", 4)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("fuel") then if inv:is_empty("fuel") and inv:is_empty("src") and inv:is_empty("dst") then
return false return true
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
end end
return true return false
end, end,
}) })
@ -84,25 +73,19 @@ minetest.register_node("bonfire:self_active", {
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", bonfire.formspec) meta:set_string("formspec", bonfire.formspec)
meta:set_string("infotext", "Bonfire") meta:set_string("infotext", "Bonfire")
meta:set_int("active", 0)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("fuel", 1) inv:set_size("fuel", 1)
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 2) inv:set_size("dst", 2)
inv:set_size("add", 4)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("fuel") then if inv:is_empty("fuel") and inv:is_empty("src") and inv:is_empty("dst") then
return false return true
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
end end
return true return false
end, end,
}) })
@ -137,91 +120,80 @@ minetest.register_abm({
end end
end end
local inv = meta:get_inventory() if meta:get_int("active") == 1 then
local inv = meta:get_inventory()
local srclist = inv:get_list("src") local srclist = inv:get_list("src")
local cooked = nil local cooked = nil
if srclist then if srclist then
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) 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)
end end
end
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then local was_active = false
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 if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
local cooked = nil was_active = true
local fuellist = inv:get_list("fuel") meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
local srclist = inv:get_list("src") 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 srclist then if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) local percent = math.floor(meta:get_float("fuel_time") /
end meta:get_float("fuel_totaltime") * 100)
if fuellist then meta:set_string("infotext","Bonfire active: "..percent.."%")
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) hacky_swap_node(pos,"bonfire:self_active")
end 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 local fuel = nil
meta:set_string("infotext","Bonfire out of fuel") local cooked = nil
hacky_swap_node(pos,"bonfire:self") local fuellist = inv:get_list("fuel")
meta:set_string("formspec", bonfire.formspec) local srclist = inv:get_list("src")
return
end
if cooked.item:is_empty() then if srclist then
if was_active then cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
meta:set_string("infotext","Bonfire is empty") end
if fuellist then
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
end
if fuel.time <= 0 then
meta:set_string("infotext","Bonfire out of fuel")
hacky_swap_node(pos,"bonfire:self") hacky_swap_node(pos,"bonfire:self")
meta:set_string("formspec", bonfire.formspec) meta:set_string("formspec", bonfire.formspec)
meta:set_int("active", 0)
return
end end
return
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)
end end
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)
end, end,
}) })

View File

@ -4,7 +4,7 @@ minetest.register_tool("sticks:sticks", {
on_use = function(item, user, pointed_thing) on_use = function(item, user, pointed_thing)
local pos local pos
if pointed_thing.type == "node" then 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) local meta = minetest.env:get_meta(pointed_thing.under)
meta:set_int("active", 1) meta:set_int("active", 1)
item:add_wear(65535/10) 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_name;fuel;3.5,5;1,1;]"..
"list[current_player;main;0,6;8,4;]") "list[current_player;main;0,6;8,4;]")
if furnaceb > 9 then if furnaceb > 9 then
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:add_item("fuel", "default:coal_lump "..furnaceb-9) inv:add_item("fuel", "default:coal_lump "..furnaceb-9)
end end
@ -71,6 +70,18 @@ minetest.register_tool("sticks:sticks", {
end end
if bonfireb >= 10 and minetest.env:get_node(pos).name == "air" then if bonfireb >= 10 and minetest.env:get_node(pos).name == "air" then
minetest.env:set_node(pos, {name = "bonfire:self"}) 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
end end
item:add_wear(65535/10) item:add_wear(65535/10)