From ed942984f5debb9b0b3159832a993b8fcefbf6df Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 26 Jan 2018 16:43:48 +0000 Subject: [PATCH] Add furnace --- mods/default/init.lua | 1 - mods/furnace/depends.txt | 1 + .../{default/furnace.lua => furnace/init.lua} | 112 ++++++++++-------- .../textures/default_furnace_bottom.png | Bin .../textures/default_furnace_fire_bg.png | Bin .../textures/default_furnace_fire_fg.png | Bin .../textures/default_furnace_front.png | Bin .../textures/default_furnace_front_active.png | Bin .../textures/default_furnace_side.png | Bin .../textures/default_furnace_top.png | Bin 10 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 mods/furnace/depends.txt rename mods/{default/furnace.lua => furnace/init.lua} (76%) rename mods/{default => furnace}/textures/default_furnace_bottom.png (100%) rename mods/{default => furnace}/textures/default_furnace_fire_bg.png (100%) rename mods/{default => furnace}/textures/default_furnace_fire_fg.png (100%) rename mods/{default => furnace}/textures/default_furnace_front.png (100%) rename mods/{default => furnace}/textures/default_furnace_front_active.png (100%) rename mods/{default => furnace}/textures/default_furnace_side.png (100%) rename mods/{default => furnace}/textures/default_furnace_top.png (100%) diff --git a/mods/default/init.lua b/mods/default/init.lua index 7b5f62f..3cf467e 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -40,7 +40,6 @@ local default_path = minetest.get_modpath("default") dofile(default_path.."/functions.lua") dofile(default_path.."/trees.lua") dofile(default_path.."/nodes.lua") -dofile(default_path.."/furnace.lua") dofile(default_path.."/torch.lua") dofile(default_path.."/tools.lua") dofile(default_path.."/item_entity.lua") diff --git a/mods/furnace/depends.txt b/mods/furnace/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/mods/furnace/depends.txt @@ -0,0 +1 @@ +default diff --git a/mods/default/furnace.lua b/mods/furnace/init.lua similarity index 76% rename from mods/default/furnace.lua rename to mods/furnace/init.lua index 4b82205..197ab8c 100644 --- a/mods/default/furnace.lua +++ b/mods/furnace/init.lua @@ -3,50 +3,49 @@ -- Formspecs -- -local function active_formspec(fuel_percent, item_percent) - local formspec = - "size[8,8.5]".. +function default.get_furnace_active_formspec(fuel_percent, item_percent) + return "size[8,8.5]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "list[current_name;src;2.75,0.5;1,1;]".. - "list[current_name;fuel;2.75,2.5;1,1;]".. + "list[context;src;2.75,0.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:".. (100-fuel_percent)..":default_furnace_fire_fg.png]".. "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:".. (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,5.5;8,3;8]".. - "listring[current_name;dst]".. + "listring[context;dst]".. "listring[current_player;main]".. - "listring[current_name;src]".. + "listring[context;src]".. "listring[current_player;main]".. - "listring[current_name;fuel]".. + "listring[context;fuel]".. "listring[current_player;main]".. default.get_hotbar_bg(0, 4.25) - return formspec end -local inactive_formspec = - "size[8,8.5]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "list[current_name;src;2.75,0.5;1,1;]".. - "list[current_name;fuel;2.75,2.5;1,1;]".. - "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]".. - "list[current_name;dst;4.75,0.96;2,2;]".. - "list[current_player;main;0,4.25;8,1;]".. - "list[current_player;main;0,5.5;8,3;8]".. - "listring[current_name;dst]".. - "listring[current_player;main]".. - "listring[current_name;src]".. - "listring[current_player;main]".. - "listring[current_name;fuel]".. - "listring[current_player;main]".. - default.get_hotbar_bg(0, 4.25) +function default.get_furnace_inactive_formspec() + return "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "list[context;src;2.75,0.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[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]".. + "list[context;dst;4.75,0.96;2,2;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + "listring[context;dst]".. + "listring[current_player;main]".. + "listring[context;src]".. + "listring[current_player;main]".. + "listring[context;fuel]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 4.25) +end -- -- 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 -- - local formspec = inactive_formspec + local formspec local item_state local item_percent = 0 if cookable then @@ -209,27 +208,29 @@ local function furnace_node_timer(pos, elapsed) end local fuel_state = "Empty" - local active = "inactive " + local active = "inactive" local result = false if fuel_totaltime ~= 0 then - active = "active " + active = "active" local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100) fuel_state = fuel_percent .. "%" - formspec = active_formspec(fuel_percent, item_percent) - swap_node(pos, "default:furnace_active") + formspec = default.get_furnace_active_formspec(fuel_percent, item_percent) + swap_node(pos, "furnace:furnace_active") -- make sure timer restarts automatically result = true else if not fuellist[1]:is_empty() then fuel_state = "0%" end - swap_node(pos, "default:furnace") + formspec = default.get_furnace_inactive_formspec() + swap_node(pos, "furnace:furnace") -- stop timer on the inactive furnace minetest.get_node_timer(pos):stop() 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 @@ -243,11 +244,20 @@ local function furnace_node_timer(pos, elapsed) return result 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 -- -minetest.register_node("default:furnace", { +minetest.register_node("furnace:furnace", { description = "Furnace", tiles = { "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" }, paramtype2 = "facedir", - groups = {cracky=2}, + groups = {cracky = 3}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_stone_defaults(), - can_dig = can_dig, - on_timer = furnace_node_timer, on_construct = function(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() inv:set_size('src', 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, "fuel", drops) default.get_inventory_drops(pos, "dst", drops) - drops[#drops+1] = "default:furnace" + drops[#drops+1] = "furnace:furnace" minetest.remove_node(pos) return drops end, + on_destruct = on_destruct, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_take = allow_metadata_inventory_take, }) -minetest.register_node("default:furnace_active", { +minetest.register_node("furnace:furnace_active", { description = "Furnace", tiles = { "default_furnace_top.png", "default_furnace_bottom.png", @@ -314,17 +323,26 @@ minetest.register_node("default:furnace_active", { }, paramtype2 = "facedir", light_source = 8, - drop = "default:furnace", - groups = {cracky=2, not_in_creative_inventory=1}, + drop = "furnace:furnace", + groups = {cracky=3, not_in_creative_inventory=1}, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_stone_defaults(), on_timer = furnace_node_timer, - can_dig = can_dig, - + on_destruct = on_destruct, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_move = allow_metadata_inventory_move, 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'}, + } +}) diff --git a/mods/default/textures/default_furnace_bottom.png b/mods/furnace/textures/default_furnace_bottom.png similarity index 100% rename from mods/default/textures/default_furnace_bottom.png rename to mods/furnace/textures/default_furnace_bottom.png diff --git a/mods/default/textures/default_furnace_fire_bg.png b/mods/furnace/textures/default_furnace_fire_bg.png similarity index 100% rename from mods/default/textures/default_furnace_fire_bg.png rename to mods/furnace/textures/default_furnace_fire_bg.png diff --git a/mods/default/textures/default_furnace_fire_fg.png b/mods/furnace/textures/default_furnace_fire_fg.png similarity index 100% rename from mods/default/textures/default_furnace_fire_fg.png rename to mods/furnace/textures/default_furnace_fire_fg.png diff --git a/mods/default/textures/default_furnace_front.png b/mods/furnace/textures/default_furnace_front.png similarity index 100% rename from mods/default/textures/default_furnace_front.png rename to mods/furnace/textures/default_furnace_front.png diff --git a/mods/default/textures/default_furnace_front_active.png b/mods/furnace/textures/default_furnace_front_active.png similarity index 100% rename from mods/default/textures/default_furnace_front_active.png rename to mods/furnace/textures/default_furnace_front_active.png diff --git a/mods/default/textures/default_furnace_side.png b/mods/furnace/textures/default_furnace_side.png similarity index 100% rename from mods/default/textures/default_furnace_side.png rename to mods/furnace/textures/default_furnace_side.png diff --git a/mods/default/textures/default_furnace_top.png b/mods/furnace/textures/default_furnace_top.png similarity index 100% rename from mods/default/textures/default_furnace_top.png rename to mods/furnace/textures/default_furnace_top.png