abstract most inventory handling code into a homedecor registration function

drawtype and param related defaults are being handled as well
for now we still leave the locked-node generation to locked.lua, due to its furnace-like node support

example:
homedecor.register("penbox", {
	<common defs>
	infotext=S("Penbox"),
	inventory = {
		size=8,
		formspec=…
		lockable=true -- will be supported later
	},
})
This commit is contained in:
Tim 2015-01-21 19:19:14 +01:00 committed by Vanessa Ezekowitz
parent 2cdf6667dc
commit b4b281d9ea
8 changed files with 203 additions and 512 deletions

View File

@ -347,7 +347,7 @@ minetest.register_node("homedecor:wardrobe_top", {
}, },
}) })
minetest.register_node("homedecor:wardrobe_bottom", { homedecor.register("wardrobe_bottom", {
tiles = { tiles = {
"forniture_wood.png", "forniture_wood.png",
"forniture_wood.png^[transformR180", "forniture_wood.png^[transformR180",
@ -358,9 +358,6 @@ minetest.register_node("homedecor:wardrobe_bottom", {
}, },
inventory_image = "homedecor_wardrobe_inv.png", inventory_image = "homedecor_wardrobe_inv.png",
description = "Wardrobe", description = "Wardrobe",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3}, groups = {snappy=3},
node_box = { node_box = {
type = "fixed", type = "fixed",
@ -385,39 +382,13 @@ minetest.register_node("homedecor:wardrobe_bottom", {
minetest.remove_node(pos2) minetest.remove_node(pos2)
end end
end, end,
on_construct = function(pos) infotext=S("Wardrobe cabinet"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=24,
"size[8,8]".. formspec="size[8,8]"..
"list[current_name;main;0,0;8,3;]".. "list[context;main;0,0;8,3;]"..
"list[current_player;main;0,4;8,4;]") "list[current_player;main;0,4;8,4;]",
meta:set_string("infotext", S("Wardrobe cabinet")) },
local inv = meta:get_inventory()
inv:set_size("main", 24)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in wardrobe at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to wardrobe at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from wardrobe at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node("homedecor:simple_bench", { minetest.register_node("homedecor:simple_bench", {

View File

@ -222,8 +222,9 @@ function homedecor.find_ceiling(itemstack, placer, pointed_thing)
return isceiling, pos return isceiling, pos
end end
-- load various other components dofile(homedecor.modpath.."/registration_handler.lua")
-- load various other components
dofile(homedecor.modpath.."/misc-nodes.lua") -- the catch-all for all misc nodes dofile(homedecor.modpath.."/misc-nodes.lua") -- the catch-all for all misc nodes
dofile(homedecor.modpath.."/tables.lua") dofile(homedecor.modpath.."/tables.lua")
dofile(homedecor.modpath.."/electronics.lua") dofile(homedecor.modpath.."/electronics.lua")

View File

@ -14,7 +14,7 @@ for _, mat in ipairs(counter_materials) do
material = "_"..mat material = "_"..mat
end end
minetest.register_node('homedecor:kitchen_cabinet'..material, { homedecor.register("kitchen_cabinet"..material, {
description = desc, description = desc,
tiles = { 'homedecor_kitchen_cabinet_top'..material..'.png', tiles = { 'homedecor_kitchen_cabinet_top'..material..'.png',
'homedecor_kitchen_cabinet_bottom.png', 'homedecor_kitchen_cabinet_bottom.png',
@ -23,49 +23,20 @@ for _, mat in ipairs(counter_materials) do
'homedecor_kitchen_cabinet_sides.png', 'homedecor_kitchen_cabinet_sides.png',
'homedecor_kitchen_cabinet_front.png'}, 'homedecor_kitchen_cabinet_front.png'},
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) infotext=S("Kitchen Cabinet"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=24,
"size[8,8]".. formspec="size[8,8]"..
"list[current_name;main;0,0;8,3;]".. "list[context;main;0,0;8,3;]"..
"list[current_player;main;0,4;8,4;]") "list[current_player;main;0,4;8,4;]",
meta:set_string("infotext", S("Kitchen Cabinet")) },
local inv = meta:get_inventory()
inv:set_size("main", 24)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
end end
minetest.register_node('homedecor:kitchen_cabinet_half', { homedecor.register("kitchen_cabinet_half", {
drawtype="nodebox",
description = S('Half-height Kitchen Cabinet (on ceiling)'), description = S('Half-height Kitchen Cabinet (on ceiling)'),
tiles = { 'homedecor_kitchen_cabinet_sides.png', tiles = { 'homedecor_kitchen_cabinet_sides.png',
'homedecor_kitchen_cabinet_bottom.png', 'homedecor_kitchen_cabinet_bottom.png',
@ -74,8 +45,6 @@ minetest.register_node('homedecor:kitchen_cabinet_half', {
'homedecor_kitchen_cabinet_sides.png', 'homedecor_kitchen_cabinet_sides.png',
'homedecor_kitchen_cabinet_front_half.png'}, 'homedecor_kitchen_cabinet_front_half.png'},
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -87,84 +56,29 @@ minetest.register_node('homedecor:kitchen_cabinet_half', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) infotext=S("Kitchen Cabinet"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=12,
"size[8,7]".. formspec="size[8,7]"..
"list[current_name;main;1,0;6,2;]".. "list[context;main;1,0;6,2;]"..
"list[current_player;main;0,3;8,4;]") "list[current_player;main;0,3;8,4;]",
meta:set_string("infotext", S("Kitchen Cabinet")) },
local inv = meta:get_inventory()
inv:set_size("main", 12)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node('homedecor:kitchen_cabinet_with_sink', { homedecor.register("kitchen_cabinet_with_sink", {
description = S("Kitchen Cabinet with sink"), description = S("Kitchen Cabinet with sink"),
drawtype = "mesh",
mesh = "homedecor_kitchen_sink.obj", mesh = "homedecor_kitchen_sink.obj",
tiles = { "homedecor_kitchen_sink.png" }, tiles = { "homedecor_kitchen_sink.png" },
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) infotext=S("Under-sink cabinet"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=16,
"size[8,7]".. formspec="size[8,7]"..
"list[current_name;main;0,0;8,2;]".. "list[context;main;0,0;8,2;]"..
"list[current_player;main;0,3;8,4;]") "list[current_player;main;0,3;8,4;]",
meta:set_string("infotext", S("Under-sink cabinet")) },
local inv = meta:get_inventory()
inv:set_size("main", 16)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from kitchen cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })

View File

@ -31,9 +31,8 @@ for i in ipairs(bathroom_tile_colors) do
}) })
end end
minetest.register_node("homedecor:towel_rod", { homedecor.register("towel_rod", {
description = "Towel rod with towel", description = "Towel rod with towel",
drawtype = "nodebox",
tiles = { tiles = {
"homedecor_towel_rod_top.png", "homedecor_towel_rod_top.png",
"homedecor_towel_rod_bottom.png", "homedecor_towel_rod_bottom.png",
@ -42,8 +41,6 @@ minetest.register_node("homedecor:towel_rod", {
"homedecor_towel_rod_fb.png", "homedecor_towel_rod_fb.png",
"homedecor_towel_rod_fb.png" "homedecor_towel_rod_fb.png"
}, },
paramtype = "light",
paramtype2 = "facedir",
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
@ -62,7 +59,7 @@ minetest.register_node("homedecor:towel_rod", {
sounds = default.node_sound_defaults(), sounds = default.node_sound_defaults(),
}) })
minetest.register_node('homedecor:medicine_cabinet', { homedecor.register("medicine_cabinet", {
drawtype = "nodebox", drawtype = "nodebox",
description = S("Medicine Cabinet"), description = S("Medicine Cabinet"),
tiles = { tiles = {
@ -75,14 +72,12 @@ minetest.register_node('homedecor:medicine_cabinet', {
}, },
inventory_image = "homedecor_medicine_cabinet_inv.png", inventory_image = "homedecor_medicine_cabinet_inv.png",
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.3125, -0.1875, 0.3125, 0.3125, 0.5, 0.5} fixed = {-0.3125, -0.1875, 0.3125, 0.3125, 0.5, 0.5}
}, },
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = {-0.3125, -0.1875, 0.3125, 0.3125, 0.5, 0.5} fixed = {-0.3125, -0.1875, 0.3125, 0.3125, 0.5, 0.5}
}, },
@ -92,42 +87,16 @@ minetest.register_node('homedecor:medicine_cabinet', {
node.name = "homedecor:medicine_cabinet_open" node.name = "homedecor:medicine_cabinet_open"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end, end,
on_construct = function(pos) infotext=S("Medicine cabinet"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=16,
"size[8,7]".. formspec="size[8,7]"..
"list[current_name;main;1,0;6,1;]".. "list[context;main;1,0;6,1;]"..
"list[current_player;main;0,3;8,4;]") "list[current_player;main;0,3;8,4;]",
meta:set_string("infotext", S("Medicine cabinet")) },
local inv = meta:get_inventory()
inv:set_size("main", 16)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in medicine cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to medicine cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from medicine cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node("homedecor:medicine_cabinet_open", { homedecor.register("medicine_cabinet_open", {
tiles = { tiles = {
'homedecor_medicine_cabinet_tb.png', 'homedecor_medicine_cabinet_tb.png',
'homedecor_medicine_cabinet_tb.png', 'homedecor_medicine_cabinet_tb.png',
@ -136,9 +105,6 @@ minetest.register_node("homedecor:medicine_cabinet_open", {
'homedecor_medicine_cabinet_back.png', 'homedecor_medicine_cabinet_back.png',
"homedecor_medicine_cabinet_open_front.png" "homedecor_medicine_cabinet_open_front.png"
}, },
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
groups = { snappy = 3, not_in_creative_inventory=1 }, groups = { snappy = 3, not_in_creative_inventory=1 },
node_box = { node_box = {
type = "fixed", type = "fixed",
@ -154,14 +120,11 @@ minetest.register_node("homedecor:medicine_cabinet_open", {
end, end,
}) })
minetest.register_node("homedecor:toilet_paper", { homedecor.register("toilet_paper", {
description = S("Toilet paper"), description = S("Toilet paper"),
drawtype = "mesh",
mesh = "homedecor_toilet_paper.obj", mesh = "homedecor_toilet_paper.obj",
tiles = { "homedecor_toilet_paper.png" }, tiles = { "homedecor_toilet_paper.png" },
inventory_image = "homedecor_toilet_paper_inv.png", inventory_image = "homedecor_toilet_paper_inv.png",
paramtype = "light",
paramtype2 = "facedir",
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = { -0.1875, 0.125, 0.0625, 0.25, 0.4375, 0.5 } fixed = { -0.1875, 0.125, 0.0625, 0.25, 0.4375, 0.5 }

View File

@ -293,7 +293,7 @@ minetest.register_node("homedecor:fishtank_lighted", {
end end
}) })
minetest.register_node('homedecor:cardboard_box', { homedecor.register("cardboard_box", {
drawtype = "nodebox", drawtype = "nodebox",
description = S("Cardboard box"), description = S("Cardboard box"),
tiles = { tiles = {
@ -305,10 +305,10 @@ minetest.register_node('homedecor:cardboard_box', {
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
}, },
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
@ -325,40 +325,13 @@ minetest.register_node('homedecor:cardboard_box', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
infotext=S("Cardboard box"),
on_construct = function(pos) inventory = {
local meta = minetest.get_meta(pos) size=8,
meta:set_string("formspec", formspec="size[8,6]"..
"size[8,6]".. "list[current_name;main;2,0;4,1;]"..
"list[current_name;main;2,0;4,1;]".. "list[current_player;main;0,2;8,4;]",
"list[current_player;main;0,2;8,4;]") },
meta:set_string("infotext", S("Cardboard box"))
local inv = meta:get_inventory()
inv:set_size("main", 8)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in cardboard box at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to cardboard box at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from cardboard box at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node("homedecor:dvd_cd_cabinet", { minetest.register_node("homedecor:dvd_cd_cabinet", {
@ -395,8 +368,7 @@ minetest.register_node("homedecor:dvd_cd_cabinet", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_node('homedecor:filing_cabinet', { homedecor.register("filing_cabinet", {
drawtype = "nodebox",
description = S("Filing Cabinet"), description = S("Filing Cabinet"),
tiles = { tiles = {
'forniture_wood.png', 'forniture_wood.png',
@ -407,8 +379,6 @@ minetest.register_node('homedecor:filing_cabinet', {
'homedecor_filing_cabinet_front.png' 'homedecor_filing_cabinet_front.png'
}, },
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -423,39 +393,13 @@ minetest.register_node('homedecor:filing_cabinet', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) infotext=S("Filing cabinet"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=16,
"size[8,7]".. formspec="size[8,7]"..
"list[current_name;main;0,0;8,2;]".. "list[context;main;0,0;8,2;]"..
"list[current_player;main;0,3;8,4;]") "list[current_player;main;0,3;8,4;]",
meta:set_string("infotext", S("Filing cabinet")) },
local inv = meta:get_inventory()
inv:set_size("main", 16)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in filing cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to filing cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from filing cabinet at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node("homedecor:dishwasher", { minetest.register_node("homedecor:dishwasher", {

View File

@ -2,8 +2,7 @@
local S = homedecor.gettext local S = homedecor.gettext
minetest.register_node('homedecor:nightstand_oak_one_drawer', { homedecor.register("nightstand_oak_one_drawer", {
drawtype = "nodebox",
description = S("Oak Nightstand with One Drawer"), description = S("Oak Nightstand with One Drawer"),
tiles = { 'homedecor_nightstand_oak_top.png', tiles = { 'homedecor_nightstand_oak_top.png',
'homedecor_nightstand_oak_bottom.png', 'homedecor_nightstand_oak_bottom.png',
@ -12,8 +11,6 @@ minetest.register_node('homedecor:nightstand_oak_one_drawer', {
'homedecor_nightstand_oak_back.png', 'homedecor_nightstand_oak_back.png',
'homedecor_nightstand_oak_1_drawer_front.png'}, 'homedecor_nightstand_oak_1_drawer_front.png'},
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -32,43 +29,16 @@ minetest.register_node('homedecor:nightstand_oak_one_drawer', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
infotext=S("One-drawer Nightstand"),
on_construct = function(pos) inventory = {
local meta = minetest.get_meta(pos) size=8,
meta:set_string("formspec", formspec="size[8,6]"..
"size[8,6]".. "list[context;main;0,0;8,1;]"..
"list[current_name;main;0,0;8,1;]".. "list[current_player;main;0,2;8,4;]",
"list[current_player;main;0,2;8,4;]") },
meta:set_string("infotext", S("One-drawer Nightstand"))
local inv = meta:get_inventory()
inv:set_size("main", 8)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node('homedecor:nightstand_oak_two_drawers', { homedecor.register("nightstand_oak_two_drawers", {
drawtype = "nodebox", drawtype = "nodebox",
description = S("Oak Nightstand with Two Drawers"), description = S("Oak Nightstand with Two Drawers"),
tiles = { 'homedecor_nightstand_oak_top.png', tiles = { 'homedecor_nightstand_oak_top.png',
@ -96,43 +66,16 @@ minetest.register_node('homedecor:nightstand_oak_two_drawers', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) infotext=S("Two-drawer Nightstand"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=16,
"size[8,7]".. formspec="size[8,7]"..
"list[current_name;main;0,0;8,2;]".. "list[context;main;0,0;8,2;]"..
"list[current_player;main;0,3;8,4;]") "list[current_player;main;0,3;8,4;]",
meta:set_string("infotext", S("Two-drawer Nightstand")) },
local inv = meta:get_inventory()
inv:set_size("main", 16)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node('homedecor:nightstand_mahogany_one_drawer', { homedecor.register("nightstand_mahogany_one_drawer", {
drawtype = "nodebox",
description = S("Mahogany Nightstand with One Drawer"), description = S("Mahogany Nightstand with One Drawer"),
tiles = { 'homedecor_nightstand_mahogany_top.png', tiles = { 'homedecor_nightstand_mahogany_top.png',
'homedecor_nightstand_mahogany_bottom.png', 'homedecor_nightstand_mahogany_bottom.png',
@ -141,8 +84,6 @@ minetest.register_node('homedecor:nightstand_mahogany_one_drawer', {
'homedecor_nightstand_mahogany_back.png', 'homedecor_nightstand_mahogany_back.png',
'homedecor_nightstand_mahogany_1_drawer_front.png'}, 'homedecor_nightstand_mahogany_1_drawer_front.png'},
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -161,44 +102,16 @@ minetest.register_node('homedecor:nightstand_mahogany_one_drawer', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
infotext=S("One-drawer Nightstand"),
on_construct = function(pos) inventory = {
local meta = minetest.get_meta(pos) size=8,
meta:set_string("formspec", formspec="size[8,6]"..
"size[8,6]".. "list[context;main;0,0;8,1;]"..
"list[current_name;main;0,0;8,1;]".. "list[current_player;main;0,2;8,4;]",
"list[current_player;main;0,2;8,4;]") },
meta:set_string("infotext", S("One-drawer Nightstand"))
local inv = meta:get_inventory()
inv:set_size("main", 8)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node('homedecor:nightstand_mahogany_two_drawers', { homedecor.register("nightstand_mahogany_two_drawers", {
drawtype = "nodebox",
description = S("Mahogany Nightstand with Two Drawers"), description = S("Mahogany Nightstand with Two Drawers"),
tiles = { 'homedecor_nightstand_mahogany_top.png', tiles = { 'homedecor_nightstand_mahogany_top.png',
'homedecor_nightstand_mahogany_bottom.png', 'homedecor_nightstand_mahogany_bottom.png',
@ -207,8 +120,6 @@ minetest.register_node('homedecor:nightstand_mahogany_two_drawers', {
'homedecor_nightstand_mahogany_back.png', 'homedecor_nightstand_mahogany_back.png',
'homedecor_nightstand_mahogany_2_drawer_front.png'}, 'homedecor_nightstand_mahogany_2_drawer_front.png'},
sunlight_propagates = false, sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true, walkable = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -225,37 +136,11 @@ minetest.register_node('homedecor:nightstand_mahogany_two_drawers', {
}, },
groups = { snappy = 3 }, groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) infotext=S("Two-drawer Nightstand"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=16,
"size[8,7]".. formspec="size[8,7]"..
"list[current_name;main;0,0;8,2;]".. "list[context;main;0,0;8,2;]"..
"list[current_player;main;0,3;8,4;]") "list[current_player;main;0,3;8,4;]",
meta:set_string("infotext", S("Two-drawer Nightstand")) },
local inv = meta:get_inventory()
inv:set_size("main", 16)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from nightstand at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })

View File

@ -36,8 +36,7 @@ local fridge_model_top = {
} }
-- steel-textured fridge -- steel-textured fridge
homedecor.register("refrigerator_steel_bottom", {
minetest.register_node("homedecor:refrigerator_steel_bottom", {
tiles = { tiles = {
"default_steel_block.png", "default_steel_block.png",
"homedecor_refrigerator_steel_bottom.png", "homedecor_refrigerator_steel_bottom.png",
@ -47,11 +46,8 @@ minetest.register_node("homedecor:refrigerator_steel_bottom", {
"homedecor_refrigerator_steel_front2.png" "homedecor_refrigerator_steel_front2.png"
}, },
inventory_image = "homedecor_refrigerator_steel_inv.png", inventory_image = "homedecor_refrigerator_steel_inv.png",
description = S("Refrigerator (stainless steel)"), description = S("Refrigerator (stainless steel)"),
drawtype = "nodebox", groups = {snappy=3},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3},
node_box = fridge_model_bottom, node_box = fridge_model_bottom,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -98,42 +94,16 @@ minetest.register_node("homedecor:refrigerator_steel_bottom", {
minetest.remove_node(pos2) minetest.remove_node(pos2)
end end
end, end,
on_construct = function(pos) infotext=S("Refrigerator"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=50,
"size[10,10]".. formspec="size[10,10]"..
"list[current_name;main;0,0;10,5;]".. "list[context;main;0,0;10,5;]"..
"list[current_player;main;1,6;8,4;]") "list[current_player;main;1,6;8,4;]",
meta:set_string("infotext", S("Refrigerator")) },
local inv = meta:get_inventory()
inv:set_size("main",50)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in refrigerator at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to refrigerator at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from refrigerator at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node("homedecor:refrigerator_steel_top", { homedecor.register("refrigerator_steel_top", {
tiles = { tiles = {
"homedecor_refrigerator_steel_top.png", "homedecor_refrigerator_steel_top.png",
"default_steel_block.png", "default_steel_block.png",
@ -142,10 +112,7 @@ minetest.register_node("homedecor:refrigerator_steel_top", {
"homedecor_refrigerator_steel_back1.png", "homedecor_refrigerator_steel_back1.png",
"homedecor_refrigerator_steel_front1.png" "homedecor_refrigerator_steel_front1.png"
}, },
drawtype = "nodebox", groups = {snappy=3},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3},
node_box = fridge_model_top, node_box = fridge_model_top,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -155,7 +122,7 @@ minetest.register_node("homedecor:refrigerator_steel_top", {
-- white, enameled fridge -- white, enameled fridge
minetest.register_node("homedecor:refrigerator_white_bottom", { homedecor.register("refrigerator_white_bottom", {
tiles = { tiles = {
"default_steel_block.png", "default_steel_block.png",
"homedecor_refrigerator_white_bottom.png", "homedecor_refrigerator_white_bottom.png",
@ -165,11 +132,8 @@ minetest.register_node("homedecor:refrigerator_white_bottom", {
"homedecor_refrigerator_white_front2.png" "homedecor_refrigerator_white_front2.png"
}, },
inventory_image = "homedecor_refrigerator_white_inv.png", inventory_image = "homedecor_refrigerator_white_inv.png",
description = S("Refrigerator"), description = S("Refrigerator"),
drawtype = "nodebox", groups = {snappy=3},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3},
node_box = fridge_model_bottom, node_box = fridge_model_bottom,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -216,42 +180,16 @@ minetest.register_node("homedecor:refrigerator_white_bottom", {
minetest.remove_node(pos2) minetest.remove_node(pos2)
end end
end, end,
on_construct = function(pos) infotext=S("Refrigerator"),
local meta = minetest.get_meta(pos) inventory = {
meta:set_string("formspec", size=50,
"size[10,10]".. formspec="size[10,10]"..
"list[current_name;main;0,0;10,5;]".. "list[context;main;0,0;10,5;]"..
"list[current_player;main;1,6;8,4;]") "list[current_player;main;1,6;8,4;]",
meta:set_string("infotext", S("Refrigerator")) },
local inv = meta:get_inventory()
inv:set_size("main",50)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in refrigerator at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to refrigerator at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from refrigerator at %s"):format(
player:get_player_name(),
minetest.pos_to_string(pos)
))
end,
}) })
minetest.register_node("homedecor:refrigerator_white_top", { homedecor.register("refrigerator_white_top", {
tiles = { tiles = {
"homedecor_refrigerator_white_top.png", "homedecor_refrigerator_white_top.png",
"default_steel_block.png", "default_steel_block.png",
@ -260,10 +198,7 @@ minetest.register_node("homedecor:refrigerator_white_top", {
"homedecor_refrigerator_white_back1.png", "homedecor_refrigerator_white_back1.png",
"homedecor_refrigerator_white_front1.png" "homedecor_refrigerator_white_front1.png"
}, },
drawtype = "nodebox", groups = {snappy=3},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3},
node_box = fridge_model_top, node_box = fridge_model_top,
selection_box = { selection_box = {
type = "fixed", type = "fixed",

View File

@ -0,0 +1,78 @@
homedecor = homedecor or {}
local S = homedecor.gettext
local default_can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
return meta:get_inventory():is_empty("main")
end
local default_inventory_size = 32
local default_inventory_formspec = "size[8,9]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;main;0,0.3;8,4;]"..
"list[current_player;main;0,4.85;8,1;]"..
"list[current_player;main;0,6.08;8,3;8]"..
default.get_hotbar_bg(0,4.85)
--wrapper around minetest.register_node that sets sane defaults and interprets some specialized settings
function homedecor.register(name, def)
def.paramtype = def.paramtype or "light"
def.paramtype2 = def.paramtype2 or "facedir"
def.drawtype = def.drawtype
or (def.mesh and "mesh")
or (def.node_box and "nodebox")
local infotext = def.infotext
def.infotext = nil -- no need to register this into the global node table
-- handle inventory setting
-- inventory = {
-- size = 16
-- formspec = …
-- }
local inventory = def.inventory
def.inventory = nil
if inventory then
assert((inventory.formspec == nil) == (inventory.size == nil),
"inventory.formspec and inventory.size either have both to be set or both be left nil" )
def.on_construct = def.on_construct or function(pos)
local meta = minetest.get_meta(pos)
if infotext then
meta:set_string("infotext", infotext)
end
meta:set_string("formspec", inventory.formspec or default_inventory_formspec)
meta:get_inventory():set_size("main", inventory.size or default_inventory_size)
end
def.can_dig = def.can_dig or default_can_dig
def.on_metadata_inventory_move = def.on_metadata_inventory_move or function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", S("%s moves stuff in %s at %s"):format(
player:get_player_name(), name, minetest.pos_to_string(pos)
))
end
def.on_metadata_inventory_put = def.on_metadata_inventory_put or function(pos, listname, index, stack, player)
minetest.log("action", S("%s moves stuff to %s at %s"):format(
player:get_player_name(), name, minetest.pos_to_string(pos)
))
end
def.on_metadata_inventory_take = def.on_metadata_inventory_take or function(pos, listname, index, stack, player)
minetest.log("action", S("%s takes stuff from %s at %s"):format(
player:get_player_name(), name, minetest.pos_to_string(pos)
))
end
elseif infotext and not def.on_construct then
def.on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", infotext)
end
end
-- register the actual minetest node
minetest.register_node("homedecor:" .. name, def)
end