Skip to content

Commit 4865098

Browse files
BlockMenPilzAdam
authored andcommittedJun 12, 2013
Separate formspecs of active furnace and chests
Makes its possible to override formspecs by mods
1 parent c3c5f8a commit 4865098

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed
 

‎mods/default/nodes.lua

+34-17
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,21 @@ minetest.register_node("default:sign_wall", {
598598
end,
599599
})
600600

601+
default.chest_formspec =
602+
"size[8,9]"..
603+
"list[current_name;main;0,0;8,4;]"..
604+
"list[current_player;main;0,5;8,4;]"
605+
606+
function default.get_locked_chest_formspec(pos)
607+
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
608+
local formspec =
609+
"size[8,9]"..
610+
"list[nodemeta:".. spos .. ";main;0,0;8,4;]"..
611+
"list[current_player;main;0,5;8,4;]"
612+
return formspec
613+
end
614+
615+
601616
minetest.register_node("default:chest", {
602617
description = "Chest",
603618
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
@@ -608,10 +623,7 @@ minetest.register_node("default:chest", {
608623
sounds = default.node_sound_wood_defaults(),
609624
on_construct = function(pos)
610625
local meta = minetest.get_meta(pos)
611-
meta:set_string("formspec",
612-
"size[8,9]"..
613-
"list[current_name;main;0,0;8,4;]"..
614-
"list[current_player;main;0,5;8,4;]")
626+
meta:set_string("formspec",default.chest_formspec)
615627
meta:set_string("infotext", "Chest")
616628
local inv = meta:get_inventory()
617629
inv:set_size("main", 8*4)
@@ -716,15 +728,27 @@ minetest.register_node("default:chest_locked", {
716728
on_rightclick = function(pos, node, clicker)
717729
local meta = minetest.get_meta(pos)
718730
if has_locked_chest_privilege(meta, clicker) then
719-
local pos = pos.x .. "," .. pos.y .. "," ..pos.z
720-
minetest.show_formspec(clicker:get_player_name(), "default:chest_locked",
721-
"size[8,9]"..
722-
"list[nodemeta:".. pos .. ";main;0,0;8,4;]"..
723-
"list[current_player;main;0,5;8,4;]")
731+
minetest.show_formspec(
732+
clicker:get_player_name(),
733+
"default:chest_locked",
734+
default.get_locked_chest_formspec(pos)
735+
)
724736
end
725737
end,
726738
})
727739

740+
function default.get_furnace_active_formspec(pos, percent)
741+
local formspec =
742+
"size[8,9]"..
743+
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
744+
(100-percent)..":default_furnace_fire_fg.png]"..
745+
"list[current_name;fuel;2,3;1,1;]"..
746+
"list[current_name;src;2,1;1,1;]"..
747+
"list[current_name;dst;5,1;2,2;]"..
748+
"list[current_player;main;0,5;8,4;]"
749+
return formspec
750+
end
751+
728752
default.furnace_inactive_formspec =
729753
"size[8,9]"..
730754
"image[2,2;1,1;default_furnace_fire_bg.png]"..
@@ -937,14 +961,7 @@ minetest.register_abm({
937961
meta:get_float("fuel_totaltime") * 100)
938962
meta:set_string("infotext","Furnace active: "..percent.."%")
939963
hacky_swap_node(pos,"default:furnace_active")
940-
meta:set_string("formspec",
941-
"size[8,9]"..
942-
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
943-
(100-percent)..":default_furnace_fire_fg.png]"..
944-
"list[current_name;fuel;2,3;1,1;]"..
945-
"list[current_name;src;2,1;1,1;]"..
946-
"list[current_name;dst;5,1;2,2;]"..
947-
"list[current_player;main;0,5;8,4;]")
964+
meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent))
948965
return
949966
end
950967

0 commit comments

Comments
 (0)
Please sign in to comment.