From b5188493cc193dfee761955b24d634e61257a325 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 23 Jan 2015 17:40:57 +0100 Subject: [PATCH] abstract common nodebox forms, fixing some ignored ones in the process --- homedecor/climate-control.lua | 15 +++---- homedecor/cobweb.lua | 10 +---- homedecor/doors_and_gates.lua | 10 +---- homedecor/fences.lua | 10 +---- homedecor/furniture.lua | 30 +++---------- homedecor/init.lua | 3 ++ homedecor/kitchen_cabinet.lua | 11 ++--- homedecor/laundry.lua | 10 +---- homedecor/lighting.lua | 75 +++++++++----------------------- homedecor/misc-nodes.lua | 81 +++++++---------------------------- homedecor/nightstands.lua | 20 ++------- homedecor/nodeboxes.lua | 36 ++++++++++++++++ homedecor/refrigerator.lua | 20 ++------- homedecor/shingles.lua | 25 +++-------- homedecor/slopes.lua | 5 +-- homedecor/tables.lua | 5 +-- lrfurn/armchairs.lua | 7 +-- 17 files changed, 114 insertions(+), 259 deletions(-) create mode 100644 homedecor/nodeboxes.lua diff --git a/homedecor/climate-control.lua b/homedecor/climate-control.lua index 6ffaa070..ff80eae6 100644 --- a/homedecor/climate-control.lua +++ b/homedecor/climate-control.lua @@ -24,16 +24,16 @@ minetest.register_node('homedecor:air_conditioner', { {-0.5, 0.125, -0.5, 0.5, 0.5, 0.5 }, } }, - selection_box = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } + selection_box = { type="regular" }, }) -- fans minetest.register_entity("homedecor:mesh_desk_fan", { - collisionbox = { 0, 0, 0, 0, 0, 0 }, - visual = "mesh", + collisionbox = homedecor.nodebox.null, + visual = "mesh", mesh = "homedecor_desk_fan.b3d", - textures = {"homedecor_desk_fan_uv.png"}, + textures = {"homedecor_desk_fan_uv.png"}, visual_size = {x=10, y=10}, }) @@ -53,12 +53,7 @@ minetest.register_node("homedecor:desk_fan", { tiles = {"homedecor_desk_fan_body.png"}, inventory_image = "homedecor_desk_fan_inv.png", wield_image = "homedecor_desk_fan_inv.png", - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - } - }, + selection_box = { type = "regular" }, on_construct = function(pos) local entity_remove = minetest.get_objects_inside_radius(pos, 0.1) local meta = minetest.get_meta(pos) diff --git a/homedecor/cobweb.lua b/homedecor/cobweb.lua index d0440520..4d928c4b 100644 --- a/homedecor/cobweb.lua +++ b/homedecor/cobweb.lua @@ -14,10 +14,7 @@ minetest.register_node("homedecor:cobweb_corner", { liquid_renewable = false, liquid_range = 0, walkable = false, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} - }, + selection_box = { type = "regular" }, visual_scale = 1.4, groups = { snappy = 3, liquid=3 }, after_place_node = function(pos, placer, itemstack, pointed_thing) @@ -94,10 +91,7 @@ minetest.register_node("homedecor:cobweb_plantlike", { liquid_renewable = false, liquid_range = 0, walkable = false, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} - }, + selection_box = { type = "regular" }, visual_scale = 1.189, groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 }, drop = "homedecor:cobweb_corner" diff --git a/homedecor/doors_and_gates.lua b/homedecor/doors_and_gates.lua index b812acc6..5d986900 100644 --- a/homedecor/doors_and_gates.lua +++ b/homedecor/doors_and_gates.lua @@ -688,10 +688,7 @@ minetest.register_node("homedecor:jpn_door_top", { {0.1565, -0.5, 0, 0.2185, 0.5, 0.0625}, -- NodeBox9 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 }, - }, + selection_box = homedecor.nodebox.null, }) minetest.register_node("homedecor:jpn_door_bottom_open", { @@ -764,10 +761,7 @@ minetest.register_node("homedecor:jpn_door_top_open", { {-0.84375, -0.5, -0.0625, -0.7815, 0.5, 0}, -- NodeBox9 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 }, - }, + selection_box = homedecor.nodebox.null, }) diff --git a/homedecor/fences.lua b/homedecor/fences.lua index 2df12d34..0fd7bcd0 100644 --- a/homedecor/fences.lua +++ b/homedecor/fences.lua @@ -22,10 +22,7 @@ minetest.register_node("homedecor:fence_brass", { tiles = {"homedecor_tile_brass.png"}, inventory_image = "homedecor_fence_brass.png", paramtype = "light", - selection_box = { - type = "fixed", - fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, - }, + selection_box = homedecor.nodebox.bar_y(1/7), groups = {snappy=3}, sounds = default.node_sound_wood_defaults(), walkable = true, @@ -37,10 +34,7 @@ minetest.register_node("homedecor:fence_wrought_iron", { tiles = {"homedecor_tile_wrought_iron.png"}, inventory_image = "homedecor_fence_wrought_iron.png", paramtype = "light", - selection_box = { - type = "fixed", - fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, - }, + selection_box = homedecor.nodebox.bar_y(1/7), groups = {snappy=3}, sounds = default.node_sound_wood_defaults(), walkable = true, diff --git a/homedecor/furniture.lua b/homedecor/furniture.lua index 61667ed6..42829d8e 100644 --- a/homedecor/furniture.lua +++ b/homedecor/furniture.lua @@ -221,10 +221,7 @@ for _, color in ipairs(bedcolors) do {-0.3125, -0.125, 0.0625, 0.3125, 0.0625, 0.4375}, -- NodeBox8 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - } + selection_box = homedecor.nodebox.null }) homedecor.register("bed_"..color.."_foot", { @@ -313,10 +310,7 @@ homedecor.register("wardrobe_top", { {-0.4375, -0.4375, -0.5, -0.0625, 0.4375, -0.4375}, -- NodeBox3 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) homedecor.register("wardrobe_bottom", { @@ -425,10 +419,7 @@ homedecor.register("bench_large_1_right", { {0.25, -0.5, -0.0625, 0.3125, -0.25, 0}, -- NodeBox7 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) @@ -503,10 +494,7 @@ homedecor.register("bench_large_2_right", { {-0.5, -0.25, -0.0290173, 0.5, -0.125, 0.0125346}, -- NodeBox16 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) homedecor.register("deckchair_head", { @@ -538,10 +526,7 @@ homedecor.register("deckchair_head", { {-0.375, -0.5, 0, -0.3125, -0.25, 0.0625}, -- NodeBox14 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - } + selection_box = homedecor.nodebox.null }) homedecor.register("deckchair_foot", { @@ -642,10 +627,7 @@ homedecor.register("grandfather_clock_top", { {-0.3125, -0.5, -0.3125, 0.3125, 0.5, 0.4}, -- NodeBox4 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) -- Aliases for 3dforniture mod. diff --git a/homedecor/init.lua b/homedecor/init.lua index c7c5fe5a..f4bbd0d6 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -105,6 +105,9 @@ function homedecor.find_ceiling(itemstack, placer, pointed_thing) return isceiling, pos end +-- nodebox arithmetics and helpers +-- (please keep non-generic nodeboxes with their node definition) +dofile(homedecor.modpath.."/nodeboxes.lua") -- expand and unexpand decor dofile(homedecor.modpath.."/expansion.lua") -- glue it all together into a registration function diff --git a/homedecor/kitchen_cabinet.lua b/homedecor/kitchen_cabinet.lua index b2afaee8..5b1b7c88 100644 --- a/homedecor/kitchen_cabinet.lua +++ b/homedecor/kitchen_cabinet.lua @@ -33,6 +33,7 @@ for _, mat in ipairs(counter_materials) do }) end +local kitchen_cabinet_half_box = homedecor.nodebox.slab_y(0.5, 0.5) homedecor.register("kitchen_cabinet_half", { description = S('Half-height Kitchen Cabinet (on ceiling)'), tiles = { 'homedecor_kitchen_cabinet_sides.png', @@ -43,14 +44,8 @@ homedecor.register("kitchen_cabinet_half", { 'homedecor_kitchen_cabinet_front_half.png'}, sunlight_propagates = false, walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, 0, -0.5, 0.5, 0.5, 0.5 } - }, - node_box = { - type = "fixed", - fixed = { -0.5, 0, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = kitchen_cabinet_half_box, + node_box = kitchen_cabinet_half_box, groups = { snappy = 3 }, sounds = default.node_sound_wood_defaults(), infotext=S("Kitchen Cabinet"), diff --git a/homedecor/laundry.lua b/homedecor/laundry.lua index f26de99b..45bad348 100644 --- a/homedecor/laundry.lua +++ b/homedecor/laundry.lua @@ -20,10 +20,7 @@ minetest.register_node("homedecor:washing_machine", { {-0.5, -0.5, 0.3125, 0.5, 0.5, 0.5}, } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, groups = { snappy = 3 }, }) @@ -47,10 +44,7 @@ minetest.register_node("homedecor:dryer", { {-0.5, -0.5, 0.3125, 0.5, 0.5, 0.5}, } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, groups = { snappy = 3 }, }) diff --git a/homedecor/lighting.lua b/homedecor/lighting.lua index 16995945..38cb0770 100644 --- a/homedecor/lighting.lua +++ b/homedecor/lighting.lua @@ -61,6 +61,15 @@ for i in ipairs(colors) do }) end +local glowlight_nodebox = { + half = homedecor.nodebox.slab_y(1/2), + quarter = homedecor.nodebox.slab_y(1/4), + small_cube = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, +} + -- Yellow minetest.register_node('homedecor:glowlight_half_yellow', { @@ -74,15 +83,8 @@ minetest.register_node('homedecor:glowlight_half_yellow', { 'homedecor_glowlight_thick_yellow_sides.png', 'homedecor_glowlight_thick_yellow_sides.png' }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } - }, - node_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } - }, - + selection_box = glowlight_nodebox.half, + node_box = glowlight_nodebox.half, sunlight_propagates = false, paramtype = "light", paramtype2 = "facedir", @@ -104,15 +106,8 @@ minetest.register_node('homedecor:glowlight_quarter_yellow', { 'homedecor_glowlight_thin_yellow_sides.png', 'homedecor_glowlight_thin_yellow_sides.png' }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } - }, - node_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } - }, - + selection_box = glowlight_nodebox.quarter, + node_box = glowlight_nodebox.quarter, sunlight_propagates = false, paramtype = "light", paramtype2 = "facedir", @@ -136,15 +131,8 @@ minetest.register_node('homedecor:glowlight_half_white', { 'homedecor_glowlight_thick_white_sides.png', 'homedecor_glowlight_thick_white_sides.png' }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } - }, - node_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } - }, - + selection_box = glowlight_nodebox.half, + node_box = glowlight_nodebox.half, sunlight_propagates = false, paramtype = "light", paramtype2 = "facedir", @@ -166,15 +154,8 @@ minetest.register_node('homedecor:glowlight_quarter_white', { 'homedecor_glowlight_thin_white_sides.png', 'homedecor_glowlight_thin_white_sides.png' }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } - }, - node_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } - }, - + selection_box = glowlight_nodebox.quarter, + node_box = glowlight_nodebox.quarter, sunlight_propagates = false, paramtype = "light", paramtype2 = "facedir", @@ -198,15 +179,8 @@ minetest.register_node('homedecor:glowlight_small_cube_yellow', { 'homedecor_glowlight_cube_yellow_sides.png', 'homedecor_glowlight_cube_yellow_sides.png' }, - selection_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } - }, - node_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } - }, - + selection_box = glowlight_nodebox.small_cube, + node_box = glowlight_nodebox.small_cube, sunlight_propagates = false, paramtype = "light", paramtype2 = "facedir", @@ -228,15 +202,8 @@ minetest.register_node('homedecor:glowlight_small_cube_white', { 'homedecor_glowlight_cube_white_sides.png', 'homedecor_glowlight_cube_white_sides.png' }, - selection_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } - }, - node_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } - }, - + selection_box = glowlight_nodebox.small_cube, + node_box = glowlight_nodebox.small_cube, sunlight_propagates = false, paramtype = "light", paramtype2 = "facedir", diff --git a/homedecor/misc-nodes.lua b/homedecor/misc-nodes.lua index 4a58b390..c0099717 100644 --- a/homedecor/misc-nodes.lua +++ b/homedecor/misc-nodes.lua @@ -208,10 +208,7 @@ minetest.register_node("homedecor:chimney", { {0.1875, -0.5, -0.25, 0.25, 0.5, 0.25}, } }, - selection_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25, 0.5, 0.25 } - }, + selection_box = homedecor.nodebox.bar_y(0.25), groups = {cracky=3}, sounds = default.node_sound_stone_defaults() }) @@ -305,10 +302,7 @@ homedecor.register("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 = homedecor.nodebox.slab_y(0.5), node_box = { type = "fixed", fixed = { @@ -357,10 +351,7 @@ minetest.register_node("homedecor:dvd_cd_cabinet", { {0.125, -0.5, 0.01217, 0.375, 0.5, 0.5}, } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, 0, 0.5, 0.5, 0.5 } - }, + selection_box = homedecor.nodebox.slab_z(0.5), groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3}, sounds = default.node_sound_wood_defaults(), }) @@ -377,10 +368,7 @@ homedecor.register("filing_cabinet", { }, sunlight_propagates = false, walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, node_box = { type = "fixed", fixed = { @@ -418,10 +406,7 @@ minetest.register_node("homedecor:dishwasher", { {-0.4375, -0.5, -0.5, 0.4375, 0.4375, 0.4375}, } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, groups = { snappy = 3 }, }) @@ -512,10 +497,7 @@ homedecor.register("doghouse_base", { {-0.4375, -0.3125, 0.375, 0.4375, 0.5, 0.4375}, -- NodeBox11 } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 1.0, 0.5 } - }, + selection_box = homedecor.nodebox.slab_y(1.5), groups = {snappy=3}, expand = { top="homedecor:doghouse_roof" }, }) @@ -556,10 +538,7 @@ homedecor.register("doghouse_roof", { {0.0625, -0.125, -0.375, -0.0625, -0.0625, 0.4375}, -- NodeBox38 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, groups = {snappy=3, not_in_creative_inventory=1}, }) @@ -648,10 +627,7 @@ homedecor.register("pool_table_2", { {0.375, 0.25, -0.4375, 0.4375, 0.3125, 0.3125}, -- NodeBox25 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) minetest.register_node("homedecor:trash_can", { @@ -719,10 +695,7 @@ homedecor.register("well_base", { {-0.3125, -0.5, -0.3125, 0.3125, 0, 0.3125}, -- NodeBox17 } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } - }, + selection_box = homedecor.nodebox.slab_y(2), expand = { top="homedecor:well_top" }, }) @@ -784,10 +757,7 @@ homedecor.register("well_top", { {-0.0165975, -0.51, -0.125, 0.0165974, -0.46, -0.112033}, -- NodeBox43 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) minetest.register_node("homedecor:coatrack_wallmount", { @@ -1173,10 +1143,7 @@ homedecor.register("piano_right", { } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - } + selection_box = homedecor.nodebox.null }) minetest.register_node("homedecor:toaster", { @@ -1488,10 +1455,7 @@ homedecor.register("barbecue_meat", { {0.125, -0.5, -0.125, 0.3125, -0.4375, 0.125}, -- NodeBox2 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - } + selection_box = homedecor.nodebox.null }) minetest.register_node("homedecor:beer_tap", { @@ -1599,10 +1563,7 @@ homedecor.register("tool_cabinet_bottom", { {-0.5, -0.375, -0.5, 0.5, 0.5, 0.5}, -- NodeBox5 } }, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } - }, + selection_box = homedecor.nodebox.slab_y(2), expand = { top="homedecor:tool_cabinet_top" }, }) @@ -1636,10 +1597,7 @@ homedecor.register("tool_cabinet_top", { {0.375, -0.155, 0.42, 0.405, -0.093, 0.4375}, -- NodeBox15 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - } + selection_box = homedecor.nodebox.null }) minetest.register_node("homedecor:swing", { @@ -1732,10 +1690,7 @@ minetest.register_node("homedecor:swing_rope", { {0.3, -0.5, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox2 } }, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - } + selection_box = homedecor.nodebox.null }) local bookcolors = { @@ -1930,11 +1885,7 @@ minetest.register_node("homedecor:desk_globe", { sounds = default.node_sound_defaults(), }) -local wine_cbox = { - type = "fixed", - fixed = { -0.5, -0.5, -0.25, 0.5, 0.5, 0.5 } -} - +local wine_cbox = homedecor.nodebox.slab_z(0.25) minetest.register_node("homedecor:wine_rack", { description = "Wine Rack", drawtype = "mesh", diff --git a/homedecor/nightstands.lua b/homedecor/nightstands.lua index 863056df..4d41bbab 100644 --- a/homedecor/nightstands.lua +++ b/homedecor/nightstands.lua @@ -12,10 +12,7 @@ homedecor.register("nightstand_oak_one_drawer", { 'homedecor_nightstand_oak_1_drawer_front.png'}, sunlight_propagates = false, walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, node_box = { type = "fixed", fixed = { @@ -48,10 +45,7 @@ homedecor.register("nightstand_oak_two_drawers", { paramtype = "light", paramtype2 = "facedir", walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, node_box = { type = "fixed", fixed = { @@ -79,10 +73,7 @@ homedecor.register("nightstand_mahogany_one_drawer", { 'homedecor_nightstand_mahogany_1_drawer_front.png'}, sunlight_propagates = false, walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, node_box = { type = "fixed", fixed = { @@ -112,10 +103,7 @@ homedecor.register("nightstand_mahogany_two_drawers", { 'homedecor_nightstand_mahogany_2_drawer_front.png'}, sunlight_propagates = false, walkable = true, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } - }, + selection_box = { type = "regular" }, node_box = { type = "fixed", fixed = { diff --git a/homedecor/nodeboxes.lua b/homedecor/nodeboxes.lua new file mode 100644 index 00000000..4c94f6d8 --- /dev/null +++ b/homedecor/nodeboxes.lua @@ -0,0 +1,36 @@ +-- please keep any non-generic nodeboxe with its node definition +-- this file should not accumulate any left over nodeboxes +-- but is meant to host any abstractions or calculations based on nodeboxes + +-- a box is defined as {x1, y1, z1, x2, y2, z2} +homedecor.box = { + slab_y = function(height, shift) return { -0.5, -0.5+(shift or 0), -0.5, 0.5, -0.5+height+(shift or 0), 0.5 } end, + slab_z = function(depth) return { -0.5, -0.5, -0.5+depth, 0.5, 0.5, 0.5 } end, + bar_y = function(radius) return {-radius, -0.5, -radius, radius, 0.5, radius} end, + cuboid = function(radius_x, radius_y, radius_z) return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end, +} + +homedecor.nodebox = { + -- { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }, + -- can be used in-place as: + -- { type="regular" }, + regular = { type="regular" }, + null = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } }, +} + +local mt = {} +mt.__index = function(table, key) + local ref = homedecor.box[key] + if type(ref) == "function" then + return function(...) + return { type = "fixed", fixed = ref(unpack(arg)) } + end + elseif type(ref) == "table" then + return { type = "fixed", fixed = ref } + end + error("unexpected datatype " .. tostring(type(ref))) +end +setmetatable(homedecor.nodebox, mt) + + + diff --git a/homedecor/refrigerator.lua b/homedecor/refrigerator.lua index c0e8789c..745c9f80 100644 --- a/homedecor/refrigerator.lua +++ b/homedecor/refrigerator.lua @@ -49,10 +49,7 @@ homedecor.register("refrigerator_steel_bottom", { description = S("Refrigerator (stainless steel)"), groups = {snappy=3}, node_box = fridge_model_bottom, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } - }, + selection_box = homedecor.nodebox.slab_y(2), expand = { top="homedecor:refrigerator_steel_top" }, @@ -74,10 +71,7 @@ homedecor.register("refrigerator_steel_top", { }, groups = {snappy=3}, node_box = fridge_model_top, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) -- white, enameled fridge @@ -95,10 +89,7 @@ homedecor.register("refrigerator_white_bottom", { description = S("Refrigerator"), groups = {snappy=3}, node_box = fridge_model_bottom, - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } - }, + selection_box = homedecor.nodebox.slab_y(2), expand = { top="homedecor:refrigerator_white_top" }, @@ -120,10 +111,7 @@ homedecor.register("refrigerator_white_top", { }, groups = {snappy=3}, node_box = fridge_model_top, - selection_box = { - type = "fixed", - fixed = { 0, 0, 0, 0, 0, 0 } - }, + selection_box = homedecor.nodebox.null, }) -- convert the old single-node fridges to the new two-node models diff --git a/homedecor/shingles.lua b/homedecor/shingles.lua index db0c6df1..dce279f9 100644 --- a/homedecor/shingles.lua +++ b/homedecor/shingles.lua @@ -13,10 +13,7 @@ minetest.register_node("homedecor:skylight", { walkable = true, groups = { snappy = 3 }, sounds = default.node_sound_leaves_defaults(), - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.4, 0.5 } - } + selection_box = homedecor.nodebox.slab_y(0.1), }) minetest.register_node("homedecor:skylight_frosted", { @@ -31,10 +28,7 @@ minetest.register_node("homedecor:skylight_frosted", { walkable = true, groups = { snappy = 3 }, sounds = default.node_sound_leaves_defaults(), - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.4, 0.5 } - } + selection_box = homedecor.nodebox.slab_y(0.1), }) minetest.register_node("homedecor:shingles_wood", { @@ -48,10 +42,7 @@ minetest.register_node("homedecor:shingles_wood", { walkable = false, groups = { snappy = 3 }, sounds = default.node_sound_leaves_defaults(), - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.4, 0.5 } - } + selection_box = homedecor.nodebox.slab_y(0.1), }) minetest.register_node("homedecor:shingles_asphalt", { @@ -65,10 +56,7 @@ minetest.register_node("homedecor:shingles_asphalt", { walkable = false, groups = { snappy = 3 }, sounds = default.node_sound_leaves_defaults(), - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.4, 0.5 } - } + selection_box = homedecor.nodebox.slab_y(0.1), }) minetest.register_node("homedecor:shingles_terracotta", { @@ -82,9 +70,6 @@ minetest.register_node("homedecor:shingles_terracotta", { walkable = false, groups = { snappy = 3 }, sounds = default.node_sound_leaves_defaults(), - selection_box = { - type = "fixed", - fixed = { -0.5, -0.5, -0.5, 0.5, -0.4, 0.5 } - } + selection_box = homedecor.nodebox.slab_y(0.1), }) diff --git a/homedecor/slopes.lua b/homedecor/slopes.lua index c8086b54..fdb62659 100644 --- a/homedecor/slopes.lua +++ b/homedecor/slopes.lua @@ -60,10 +60,7 @@ homedecor.register_inner_corner = function(modname, subname, groups, slope_image paramtype = "light", paramtype2 = "facedir", walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} - }, + selection_box = { type = "regular" }, collision_box = icorner_cbox, groups = groups, on_place = minetest.rotate_node diff --git a/homedecor/tables.lua b/homedecor/tables.lua index 870491c6..cb4297b4 100644 --- a/homedecor/tables.lua +++ b/homedecor/tables.lua @@ -274,10 +274,7 @@ homedecor.register("desk_r", { {-0.5, -0.375, 0.4375, 0.4375, 0.25, 0.5}, } }, - selection_box = { - type = "fixed", - fixed = { 0,0,0,0,0,0 } - }, + selection_box = homedecor.nodebox.null, groups = { snappy = 3, not_in_creative_inventory=1 } }) diff --git a/lrfurn/armchairs.lua b/lrfurn/armchairs.lua index 20c76346..1e85cef3 100644 --- a/lrfurn/armchairs.lua +++ b/lrfurn/armchairs.lua @@ -43,12 +43,7 @@ for i in ipairs(armchairs_list) do {0.3125, 0, -0.5, 0.5, 0.25, 0.3125}, } }, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - } - }, + selection_box = { type = "regular" }, on_rightclick = function(pos, node, clicker) if not clicker:is_player() then