Add furnace

This commit is contained in:
rubenwardy 2018-01-26 16:43:48 +00:00
parent 112d4389ea
commit ed942984f5
10 changed files with 66 additions and 48 deletions

View file

@ -40,7 +40,6 @@ local default_path = minetest.get_modpath("default")
dofile(default_path.."/functions.lua") dofile(default_path.."/functions.lua")
dofile(default_path.."/trees.lua") dofile(default_path.."/trees.lua")
dofile(default_path.."/nodes.lua") dofile(default_path.."/nodes.lua")
dofile(default_path.."/furnace.lua")
dofile(default_path.."/torch.lua") dofile(default_path.."/torch.lua")
dofile(default_path.."/tools.lua") dofile(default_path.."/tools.lua")
dofile(default_path.."/item_entity.lua") dofile(default_path.."/item_entity.lua")

1
mods/furnace/depends.txt Normal file
View file

@ -0,0 +1 @@
default

View file

@ -3,50 +3,49 @@
-- Formspecs -- Formspecs
-- --
local function active_formspec(fuel_percent, item_percent) function default.get_furnace_active_formspec(fuel_percent, item_percent)
local formspec = return "size[8,8.5]"..
"size[8,8.5]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[current_name;src;2.75,0.5;1,1;]".. "list[context;src;2.75,0.5;1,1;]"..
"list[current_name;fuel;2.75,2.5;1,1;]".. "list[context;fuel;2.75,2.5;1,1;]"..
"image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:".. "image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
(100-fuel_percent)..":default_furnace_fire_fg.png]".. (100-fuel_percent)..":default_furnace_fire_fg.png]"..
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:".. "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
(item_percent)..":gui_furnace_arrow_fg.png^[transformR270]".. (item_percent)..":gui_furnace_arrow_fg.png^[transformR270]"..
"list[current_name;dst;4.75,0.96;2,2;]".. "list[context;dst;4.75,0.96;2,2;]"..
"list[current_player;main;0,4.25;8,1;]".. "list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]".. "list[current_player;main;0,5.5;8,3;8]"..
"listring[current_name;dst]".. "listring[context;dst]"..
"listring[current_player;main]".. "listring[current_player;main]"..
"listring[current_name;src]".. "listring[context;src]"..
"listring[current_player;main]".. "listring[current_player;main]"..
"listring[current_name;fuel]".. "listring[context;fuel]"..
"listring[current_player;main]".. "listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25) default.get_hotbar_bg(0, 4.25)
return formspec
end end
local inactive_formspec = function default.get_furnace_inactive_formspec()
"size[8,8.5]".. return "size[8,8.5]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[current_name;src;2.75,0.5;1,1;]".. "list[context;src;2.75,0.5;1,1;]"..
"list[current_name;fuel;2.75,2.5;1,1;]".. "list[context;fuel;2.75,2.5;1,1;]"..
"image[2.75,1.5;1,1;default_furnace_fire_bg.png]".. "image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]".. "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
"list[current_name;dst;4.75,0.96;2,2;]".. "list[context;dst;4.75,0.96;2,2;]"..
"list[current_player;main;0,4.25;8,1;]".. "list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]".. "list[current_player;main;0,5.5;8,3;8]"..
"listring[current_name;dst]".. "listring[context;dst]"..
"listring[current_player;main]".. "listring[current_player;main]"..
"listring[current_name;src]".. "listring[context;src]"..
"listring[current_player;main]".. "listring[current_player;main]"..
"listring[current_name;fuel]".. "listring[context;fuel]"..
"listring[current_player;main]".. "listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25) default.get_hotbar_bg(0, 4.25)
end
-- --
-- Node callback functions that are the same for active and inactive furnace -- Node callback functions that are the same for active and inactive furnace
@ -190,7 +189,7 @@ local function furnace_node_timer(pos, elapsed)
-- --
-- Update formspec, infotext and node -- Update formspec, infotext and node
-- --
local formspec = inactive_formspec local formspec
local item_state local item_state
local item_percent = 0 local item_percent = 0
if cookable then if cookable then
@ -209,27 +208,29 @@ local function furnace_node_timer(pos, elapsed)
end end
local fuel_state = "Empty" local fuel_state = "Empty"
local active = "inactive " local active = "inactive"
local result = false local result = false
if fuel_totaltime ~= 0 then if fuel_totaltime ~= 0 then
active = "active " active = "active"
local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100) local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
fuel_state = fuel_percent .. "%" fuel_state = fuel_percent .. "%"
formspec = active_formspec(fuel_percent, item_percent) formspec = default.get_furnace_active_formspec(fuel_percent, item_percent)
swap_node(pos, "default:furnace_active") swap_node(pos, "furnace:furnace_active")
-- make sure timer restarts automatically -- make sure timer restarts automatically
result = true result = true
else else
if not fuellist[1]:is_empty() then if not fuellist[1]:is_empty() then
fuel_state = "0%" fuel_state = "0%"
end end
swap_node(pos, "default:furnace") formspec = default.get_furnace_inactive_formspec()
swap_node(pos, "furnace:furnace")
-- stop timer on the inactive furnace -- stop timer on the inactive furnace
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
end end
local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")" local infotext = "Furnace " .. active .. "\n(Item: " .. item_state ..
"; Fuel: " .. fuel_state .. ")"
-- --
-- Set meta values -- Set meta values
@ -243,11 +244,20 @@ local function furnace_node_timer(pos, elapsed)
return result return result
end end
local function on_destruct(pos)
local inv = minetest.get_inventory({ type = "node", pos = pos })
for _, list in pairs(inv:get_lists()) do
for _, item in pairs(list) do
minetest.add_item(pos, item)
end
end
end
-- --
-- Node definitions -- Node definitions
-- --
minetest.register_node("default:furnace", { minetest.register_node("furnace:furnace", {
description = "Furnace", description = "Furnace",
tiles = { tiles = {
"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_top.png", "default_furnace_bottom.png",
@ -255,18 +265,16 @@ minetest.register_node("default:furnace", {
"default_furnace_side.png", "default_furnace_front.png" "default_furnace_side.png", "default_furnace_front.png"
}, },
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2}, groups = {cracky = 3},
legacy_facedir_simple = true, legacy_facedir_simple = true,
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
can_dig = can_dig,
on_timer = furnace_node_timer, on_timer = furnace_node_timer,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", inactive_formspec) meta:set_string("formspec", default.get_furnace_inactive_formspec())
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 1) inv:set_size('src', 1)
inv:set_size('fuel', 1) inv:set_size('fuel', 1)
@ -285,17 +293,18 @@ minetest.register_node("default:furnace", {
default.get_inventory_drops(pos, "src", drops) default.get_inventory_drops(pos, "src", drops)
default.get_inventory_drops(pos, "fuel", drops) default.get_inventory_drops(pos, "fuel", drops)
default.get_inventory_drops(pos, "dst", drops) default.get_inventory_drops(pos, "dst", drops)
drops[#drops+1] = "default:furnace" drops[#drops+1] = "furnace:furnace"
minetest.remove_node(pos) minetest.remove_node(pos)
return drops return drops
end, end,
on_destruct = on_destruct,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,
}) })
minetest.register_node("default:furnace_active", { minetest.register_node("furnace:furnace_active", {
description = "Furnace", description = "Furnace",
tiles = { tiles = {
"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_top.png", "default_furnace_bottom.png",
@ -314,17 +323,26 @@ minetest.register_node("default:furnace_active", {
}, },
paramtype2 = "facedir", paramtype2 = "facedir",
light_source = 8, light_source = 8,
drop = "default:furnace", drop = "furnace:furnace",
groups = {cracky=2, not_in_creative_inventory=1}, groups = {cracky=3, not_in_creative_inventory=1},
legacy_facedir_simple = true, legacy_facedir_simple = true,
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_timer = furnace_node_timer, on_timer = furnace_node_timer,
can_dig = can_dig, on_destruct = on_destruct,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,
}) })
minetest.register_alias("default:furnace", "furnace:furnace")
minetest.register_craft({
output = 'furnace:furnace',
recipe = {
{'group:stone', 'group:stone', 'group:stone'},
{'group:stone', '', 'group:stone'},
{'group:stone', 'group:stone', 'group:stone'},
}
})

View file

Before

Width:  |  Height:  |  Size: 274 B

After

Width:  |  Height:  |  Size: 274 B

View file

Before

Width:  |  Height:  |  Size: 129 B

After

Width:  |  Height:  |  Size: 129 B

View file

Before

Width:  |  Height:  |  Size: 558 B

After

Width:  |  Height:  |  Size: 558 B

View file

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

View file

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

View file

Before

Width:  |  Height:  |  Size: 296 B

After

Width:  |  Height:  |  Size: 296 B

View file

Before

Width:  |  Height:  |  Size: 274 B

After

Width:  |  Height:  |  Size: 274 B