From b4b281d9ea700349c7dc4ef6f5336c8f04d021de Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 21 Jan 2015 19:19:14 +0100 Subject: [PATCH] abstract most inventory handling code into a homedecor registration function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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", { infotext=S("Penbox"), inventory = { size=8, formspec=… lockable=true -- will be supported later }, }) --- homedecor/furniture.lua | 45 ++------ homedecor/init.lua | 3 +- homedecor/kitchen_cabinet.lua | 134 ++++----------------- homedecor/misc-bathroom.lua | 67 +++-------- homedecor/misc-nodes.lua | 96 ++++------------ homedecor/nightstands.lua | 179 ++++++----------------------- homedecor/refrigerator.lua | 113 ++++-------------- homedecor/registration_handler.lua | 78 +++++++++++++ 8 files changed, 203 insertions(+), 512 deletions(-) create mode 100644 homedecor/registration_handler.lua diff --git a/homedecor/furniture.lua b/homedecor/furniture.lua index be960e2f..723b22b4 100644 --- a/homedecor/furniture.lua +++ b/homedecor/furniture.lua @@ -347,7 +347,7 @@ minetest.register_node("homedecor:wardrobe_top", { }, }) -minetest.register_node("homedecor:wardrobe_bottom", { +homedecor.register("wardrobe_bottom", { tiles = { "forniture_wood.png", "forniture_wood.png^[transformR180", @@ -358,9 +358,6 @@ minetest.register_node("homedecor:wardrobe_bottom", { }, inventory_image = "homedecor_wardrobe_inv.png", description = "Wardrobe", - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", groups = {snappy=3}, node_box = { type = "fixed", @@ -385,39 +382,13 @@ minetest.register_node("homedecor:wardrobe_bottom", { minetest.remove_node(pos2) end end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,8]".. - "list[current_name;main;0,0;8,3;]".. - "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, + infotext=S("Wardrobe cabinet"), + inventory = { + size=24, + formspec="size[8,8]".. + "list[context;main;0,0;8,3;]".. + "list[current_player;main;0,4;8,4;]", + }, }) minetest.register_node("homedecor:simple_bench", { diff --git a/homedecor/init.lua b/homedecor/init.lua index 4b68539d..98d5399c 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -222,8 +222,9 @@ function homedecor.find_ceiling(itemstack, placer, pointed_thing) return isceiling, pos 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.."/tables.lua") dofile(homedecor.modpath.."/electronics.lua") diff --git a/homedecor/kitchen_cabinet.lua b/homedecor/kitchen_cabinet.lua index 52f5056d..8aa90881 100644 --- a/homedecor/kitchen_cabinet.lua +++ b/homedecor/kitchen_cabinet.lua @@ -14,7 +14,7 @@ for _, mat in ipairs(counter_materials) do material = "_"..mat end - minetest.register_node('homedecor:kitchen_cabinet'..material, { + homedecor.register("kitchen_cabinet"..material, { description = desc, tiles = { 'homedecor_kitchen_cabinet_top'..material..'.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_front.png'}, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,8]".. - "list[current_name;main;0,0;8,3;]".. - "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, + infotext=S("Kitchen Cabinet"), + inventory = { + size=24, + formspec="size[8,8]".. + "list[context;main;0,0;8,3;]".. + "list[current_player;main;0,4;8,4;]", + }, }) end -minetest.register_node('homedecor:kitchen_cabinet_half', { - drawtype="nodebox", +homedecor.register("kitchen_cabinet_half", { description = S('Half-height Kitchen Cabinet (on ceiling)'), tiles = { 'homedecor_kitchen_cabinet_sides.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_front_half.png'}, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, selection_box = { type = "fixed", @@ -87,84 +56,29 @@ minetest.register_node('homedecor:kitchen_cabinet_half', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,7]".. - "list[current_name;main;1,0;6,2;]".. - "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, + infotext=S("Kitchen Cabinet"), + inventory = { + size=12, + formspec="size[8,7]".. + "list[context;main;1,0;6,2;]".. + "list[current_player;main;0,3;8,4;]", + }, }) -minetest.register_node('homedecor:kitchen_cabinet_with_sink', { +homedecor.register("kitchen_cabinet_with_sink", { description = S("Kitchen Cabinet with sink"), - drawtype = "mesh", mesh = "homedecor_kitchen_sink.obj", tiles = { "homedecor_kitchen_sink.png" }, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,7]".. - "list[current_name;main;0,0;8,2;]".. - "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, + infotext=S("Under-sink cabinet"), + inventory = { + size=16, + formspec="size[8,7]".. + "list[context;main;0,0;8,2;]".. + "list[current_player;main;0,3;8,4;]", + }, }) diff --git a/homedecor/misc-bathroom.lua b/homedecor/misc-bathroom.lua index 6da386f2..71a4bd46 100644 --- a/homedecor/misc-bathroom.lua +++ b/homedecor/misc-bathroom.lua @@ -31,9 +31,8 @@ for i in ipairs(bathroom_tile_colors) do }) end -minetest.register_node("homedecor:towel_rod", { +homedecor.register("towel_rod", { description = "Towel rod with towel", - drawtype = "nodebox", tiles = { "homedecor_towel_rod_top.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" }, - paramtype = "light", - paramtype2 = "facedir", node_box = { type = "fixed", fixed = { @@ -62,7 +59,7 @@ minetest.register_node("homedecor:towel_rod", { sounds = default.node_sound_defaults(), }) -minetest.register_node('homedecor:medicine_cabinet', { +homedecor.register("medicine_cabinet", { drawtype = "nodebox", description = S("Medicine Cabinet"), tiles = { @@ -75,14 +72,12 @@ minetest.register_node('homedecor:medicine_cabinet', { }, inventory_image = "homedecor_medicine_cabinet_inv.png", sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, - selection_box = { - type = "fixed", + selection_box = { + type = "fixed", fixed = {-0.3125, -0.1875, 0.3125, 0.3125, 0.5, 0.5} - }, - node_box = { + }, + node_box = { type = "fixed", 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" minetest.swap_node(pos, node) end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,7]".. - "list[current_name;main;1,0;6,1;]".. - "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, + infotext=S("Medicine cabinet"), + inventory = { + size=16, + formspec="size[8,7]".. + "list[context;main;1,0;6,1;]".. + "list[current_player;main;0,3;8,4;]", + }, }) -minetest.register_node("homedecor:medicine_cabinet_open", { +homedecor.register("medicine_cabinet_open", { tiles = { '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_open_front.png" }, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", groups = { snappy = 3, not_in_creative_inventory=1 }, node_box = { type = "fixed", @@ -154,14 +120,11 @@ minetest.register_node("homedecor:medicine_cabinet_open", { end, }) -minetest.register_node("homedecor:toilet_paper", { +homedecor.register("toilet_paper", { description = S("Toilet paper"), - drawtype = "mesh", mesh = "homedecor_toilet_paper.obj", tiles = { "homedecor_toilet_paper.png" }, inventory_image = "homedecor_toilet_paper_inv.png", - paramtype = "light", - paramtype2 = "facedir", selection_box = { type = "fixed", fixed = { -0.1875, 0.125, 0.0625, 0.25, 0.4375, 0.5 } diff --git a/homedecor/misc-nodes.lua b/homedecor/misc-nodes.lua index 11a0ae33..1c6d4bb6 100644 --- a/homedecor/misc-nodes.lua +++ b/homedecor/misc-nodes.lua @@ -293,7 +293,7 @@ minetest.register_node("homedecor:fishtank_lighted", { end }) -minetest.register_node('homedecor:cardboard_box', { +homedecor.register("cardboard_box", { drawtype = "nodebox", description = S("Cardboard box"), tiles = { @@ -305,10 +305,10 @@ minetest.register_node('homedecor:cardboard_box', { paramtype = "light", paramtype2 = "facedir", walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } - }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, node_box = { type = "fixed", fixed = { @@ -325,40 +325,13 @@ minetest.register_node('homedecor:cardboard_box', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,6]".. - "list[current_name;main;2,0;4,1;]".. - "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, + infotext=S("Cardboard box"), + inventory = { + size=8, + formspec="size[8,6]".. + "list[current_name;main;2,0;4,1;]".. + "list[current_player;main;0,2;8,4;]", + }, }) minetest.register_node("homedecor:dvd_cd_cabinet", { @@ -395,8 +368,7 @@ minetest.register_node("homedecor:dvd_cd_cabinet", { sounds = default.node_sound_wood_defaults(), }) -minetest.register_node('homedecor:filing_cabinet', { - drawtype = "nodebox", +homedecor.register("filing_cabinet", { description = S("Filing Cabinet"), tiles = { 'forniture_wood.png', @@ -407,8 +379,6 @@ minetest.register_node('homedecor:filing_cabinet', { 'homedecor_filing_cabinet_front.png' }, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, selection_box = { type = "fixed", @@ -423,39 +393,13 @@ minetest.register_node('homedecor:filing_cabinet', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,7]".. - "list[current_name;main;0,0;8,2;]".. - "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, + infotext=S("Filing cabinet"), + inventory = { + size=16, + formspec="size[8,7]".. + "list[context;main;0,0;8,2;]".. + "list[current_player;main;0,3;8,4;]", + }, }) minetest.register_node("homedecor:dishwasher", { diff --git a/homedecor/nightstands.lua b/homedecor/nightstands.lua index 96fba084..853886c7 100644 --- a/homedecor/nightstands.lua +++ b/homedecor/nightstands.lua @@ -2,8 +2,7 @@ local S = homedecor.gettext -minetest.register_node('homedecor:nightstand_oak_one_drawer', { - drawtype = "nodebox", +homedecor.register("nightstand_oak_one_drawer", { description = S("Oak Nightstand with One Drawer"), tiles = { 'homedecor_nightstand_oak_top.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_1_drawer_front.png'}, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, selection_box = { type = "fixed", @@ -32,43 +29,16 @@ minetest.register_node('homedecor:nightstand_oak_one_drawer', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,6]".. - "list[current_name;main;0,0;8,1;]".. - "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, + infotext=S("One-drawer Nightstand"), + inventory = { + size=8, + formspec="size[8,6]".. + "list[context;main;0,0;8,1;]".. + "list[current_player;main;0,2;8,4;]", + }, }) -minetest.register_node('homedecor:nightstand_oak_two_drawers', { +homedecor.register("nightstand_oak_two_drawers", { drawtype = "nodebox", description = S("Oak Nightstand with Two Drawers"), tiles = { 'homedecor_nightstand_oak_top.png', @@ -96,43 +66,16 @@ minetest.register_node('homedecor:nightstand_oak_two_drawers', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,7]".. - "list[current_name;main;0,0;8,2;]".. - "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, + infotext=S("Two-drawer Nightstand"), + inventory = { + size=16, + formspec="size[8,7]".. + "list[context;main;0,0;8,2;]".. + "list[current_player;main;0,3;8,4;]", + }, }) -minetest.register_node('homedecor:nightstand_mahogany_one_drawer', { - drawtype = "nodebox", +homedecor.register("nightstand_mahogany_one_drawer", { description = S("Mahogany Nightstand with One Drawer"), tiles = { 'homedecor_nightstand_mahogany_top.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_1_drawer_front.png'}, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, selection_box = { type = "fixed", @@ -161,44 +102,16 @@ minetest.register_node('homedecor:nightstand_mahogany_one_drawer', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,6]".. - "list[current_name;main;0,0;8,1;]".. - "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, + infotext=S("One-drawer Nightstand"), + inventory = { + size=8, + formspec="size[8,6]".. + "list[context;main;0,0;8,1;]".. + "list[current_player;main;0,2;8,4;]", + }, }) -minetest.register_node('homedecor:nightstand_mahogany_two_drawers', { - drawtype = "nodebox", +homedecor.register("nightstand_mahogany_two_drawers", { description = S("Mahogany Nightstand with Two Drawers"), tiles = { 'homedecor_nightstand_mahogany_top.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_2_drawer_front.png'}, sunlight_propagates = false, - paramtype = "light", - paramtype2 = "facedir", walkable = true, selection_box = { type = "fixed", @@ -225,37 +136,11 @@ minetest.register_node('homedecor:nightstand_mahogany_two_drawers', { }, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,7]".. - "list[current_name;main;0,0;8,2;]".. - "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, + infotext=S("Two-drawer Nightstand"), + inventory = { + size=16, + formspec="size[8,7]".. + "list[context;main;0,0;8,2;]".. + "list[current_player;main;0,3;8,4;]", + }, }) diff --git a/homedecor/refrigerator.lua b/homedecor/refrigerator.lua index 34f7f048..db9d6244 100644 --- a/homedecor/refrigerator.lua +++ b/homedecor/refrigerator.lua @@ -36,8 +36,7 @@ local fridge_model_top = { } -- steel-textured fridge - -minetest.register_node("homedecor:refrigerator_steel_bottom", { +homedecor.register("refrigerator_steel_bottom", { tiles = { "default_steel_block.png", "homedecor_refrigerator_steel_bottom.png", @@ -47,11 +46,8 @@ minetest.register_node("homedecor:refrigerator_steel_bottom", { "homedecor_refrigerator_steel_front2.png" }, inventory_image = "homedecor_refrigerator_steel_inv.png", - description = S("Refrigerator (stainless steel)"), - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", - groups = {snappy=3}, + description = S("Refrigerator (stainless steel)"), + groups = {snappy=3}, node_box = fridge_model_bottom, selection_box = { type = "fixed", @@ -98,42 +94,16 @@ minetest.register_node("homedecor:refrigerator_steel_bottom", { minetest.remove_node(pos2) end end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[10,10]".. - "list[current_name;main;0,0;10,5;]".. - "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, + infotext=S("Refrigerator"), + inventory = { + size=50, + formspec="size[10,10]".. + "list[context;main;0,0;10,5;]".. + "list[current_player;main;1,6;8,4;]", + }, }) -minetest.register_node("homedecor:refrigerator_steel_top", { +homedecor.register("refrigerator_steel_top", { tiles = { "homedecor_refrigerator_steel_top.png", "default_steel_block.png", @@ -142,10 +112,7 @@ minetest.register_node("homedecor:refrigerator_steel_top", { "homedecor_refrigerator_steel_back1.png", "homedecor_refrigerator_steel_front1.png" }, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", - groups = {snappy=3}, + groups = {snappy=3}, node_box = fridge_model_top, selection_box = { type = "fixed", @@ -155,7 +122,7 @@ minetest.register_node("homedecor:refrigerator_steel_top", { -- white, enameled fridge -minetest.register_node("homedecor:refrigerator_white_bottom", { +homedecor.register("refrigerator_white_bottom", { tiles = { "default_steel_block.png", "homedecor_refrigerator_white_bottom.png", @@ -165,11 +132,8 @@ minetest.register_node("homedecor:refrigerator_white_bottom", { "homedecor_refrigerator_white_front2.png" }, inventory_image = "homedecor_refrigerator_white_inv.png", - description = S("Refrigerator"), - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", - groups = {snappy=3}, + description = S("Refrigerator"), + groups = {snappy=3}, node_box = fridge_model_bottom, selection_box = { type = "fixed", @@ -216,42 +180,16 @@ minetest.register_node("homedecor:refrigerator_white_bottom", { minetest.remove_node(pos2) end end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[10,10]".. - "list[current_name;main;0,0;10,5;]".. - "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, + infotext=S("Refrigerator"), + inventory = { + size=50, + formspec="size[10,10]".. + "list[context;main;0,0;10,5;]".. + "list[current_player;main;1,6;8,4;]", + }, }) -minetest.register_node("homedecor:refrigerator_white_top", { +homedecor.register("refrigerator_white_top", { tiles = { "homedecor_refrigerator_white_top.png", "default_steel_block.png", @@ -260,10 +198,7 @@ minetest.register_node("homedecor:refrigerator_white_top", { "homedecor_refrigerator_white_back1.png", "homedecor_refrigerator_white_front1.png" }, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", - groups = {snappy=3}, + groups = {snappy=3}, node_box = fridge_model_top, selection_box = { type = "fixed", diff --git a/homedecor/registration_handler.lua b/homedecor/registration_handler.lua new file mode 100644 index 00000000..2749636e --- /dev/null +++ b/homedecor/registration_handler.lua @@ -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