auto-combine tabletops with legs

If the player places table legs, and then places a tabletop while
pointing at the legs (from any side), the table and legs will
automatically be combined into a single node that can then have
something placed on top like usual.

This also gets rid of those redundant "utility" table nodes, since
these have always basically just been a set of legs, and a copy
of the small square wood table.  Now they're merged into the above
feature, and aliased as appropriate.

Tecccccccccchhnically, wood legs should only have been allowed to
combine with wooden tabletops...  then I googled around a bit,
and found a number of glass tables with wooden legs that were
surprisingly similar to the in-game versions.
This commit is contained in:
Vanessa Dannenberg
2021-03-26 23:08:06 -04:00
parent 40cd59aa24
commit c70fb1a1ed
32 changed files with 1808 additions and 472 deletions

View File

@ -2,25 +2,58 @@
local S = minetest.get_translator("homedecor_tables")
local materials = {
-- Various kinds of table legs
local table_shapes = {"large_square", "small_square", "small_round"}
local tabletop_materials = {
{ "glass",
S("Small square glass table"),
S("Small round glass table"),
S("Large glass table piece"),
S("Small square glass tabletop"),
S("Small round glass tabletop"),
S("Large glass tabletop piece"),
},
{ "wood",
S("Small square wooden table"),
S("Small round wooden table"),
S("Large wooden table piece"),
S("Small square wooden tabletop"),
S("Small round wooden tabletop"),
S("Large wooden tabletop piece"),
}
}
leg_materials = {
{ "brass", S("brass") },
{ "wrought_iron", S("wrought iron") },
{ "wood", S("wood") }
}
for _, t in ipairs(leg_materials) do
local name, desc = unpack(t)
homedecor.register("table_legs_"..name, {
description = S("Table Legs (@1)", desc),
drawtype = "plantlike",
tiles = {"homedecor_table_legs_"..name..".png"},
inventory_image = "homedecor_table_legs_"..name..".png",
wield_image = "homedecor_table_legs_"..name..".png",
walkable = false,
groups = {snappy=3},
sounds = default.node_sound_wood_defaults(),
selection_box = {
type = "fixed",
fixed = { -0.37, -0.5, -0.37, 0.37, 0.5, 0.37 }
},
})
end
minetest.register_alias("homedecor:utility_table_legs", "homedecor:table_legs_wood")
minetest.register_alias("homedecor:utility_table_top", "homedecor:wood_table_small_square")
-- table tops and combined tables
local tables_cbox = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.4375, 0.5 },
}
for i, mat in ipairs(materials) do
for i, mat in ipairs(tabletop_materials) do
local m, small_s, small_r, large = unpack(mat)
local s
@ -30,138 +63,67 @@ for i, mat in ipairs(materials) do
s = default.node_sound_wood_defaults()
end
-- small square tables
for _, shape in ipairs(table_shapes) do
homedecor.register(m.."_table_small_square", {
description = small_s,
mesh = "homedecor_table_small_square.obj",
tiles = { 'homedecor_'..m..'_table_small_square.png' },
wield_image = 'homedecor_'..m..'_table_small_square_inv.png',
inventory_image = 'homedecor_'..m..'_table_small_square_inv.png',
groups = { snappy = 3 },
sounds = s,
selection_box = tables_cbox,
collision_box = tables_cbox,
on_place = minetest.rotate_node
})
homedecor.register(m.."_table_"..shape, {
description = shape.." "..m.." tabletop",
mesh = "homedecor_table_"..shape..".obj",
tiles = {
'homedecor_'..m..'_table_'..shape..'.png',
'homedecor_'..m..'_table_edges.png',
'homedecor_blanktile.png',
'homedecor_blanktile.png',
'homedecor_blanktile.png',
},
wield_image = 'homedecor_'..m..'_table_'..shape..'_inv.png',
groups = { snappy = 3 },
sounds = s,
selection_box = tables_cbox,
collision_box = tables_cbox,
on_place = function(itemstack, placer, pointed_thing)
local player_name = placer:get_player_name()
if minetest.is_protected(pointed_thing.under, player_name) then return end
local node = minetest.get_node(pointed_thing.under)
if string.find(node.name, "homedecor:table_legs") then
local newname = string.format("homedecor:%s_table_%s_with_%s_legs",
m, shape, string.sub(node.name, 22))
minetest.set_node(pointed_thing.under, {name = newname})
if not creative.is_enabled_for(player_name) then
itemstack:take_item()
return itemstack
end
else
return minetest.rotate_node(itemstack, placer, pointed_thing)
end
end
})
-- small round tables
for _, l in ipairs(leg_materials) do
local leg_mat, desc = unpack(l)
homedecor.register(m..'_table_small_round', {
description = small_r,
mesh = "homedecor_table_small_round.obj",
tiles = { "homedecor_"..m.."_table_small_round.png" },
wield_image = 'homedecor_'..m..'_table_small_round_inv.png',
inventory_image = 'homedecor_'..m..'_table_small_round_inv.png',
groups = { snappy = 3 },
sounds = s,
selection_box = tables_cbox,
collision_box = tables_cbox,
on_place = minetest.rotate_node
})
-- Large square table pieces
homedecor.register(m..'_table_large', {
description = large,
tiles = {
'homedecor_'..m..'_table_large_tb.png',
'homedecor_'..m..'_table_large_tb.png',
'homedecor_'..m..'_table_large_edges.png',
'homedecor_'..m..'_table_large_edges.png',
'homedecor_'..m..'_table_large_edges.png',
'homedecor_'..m..'_table_large_edges.png'
},
wield_image = 'homedecor_'..m..'_table_large_inv.png',
inventory_image = 'homedecor_'..m..'_table_large_inv.png',
groups = { snappy = 3 },
sounds = s,
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.4375, 0.5 },
},
selection_box = tables_cbox,
on_place = minetest.rotate_node
})
homedecor.register(string.format("%s_table_%s_with_%s_legs", m, shape, leg_mat), {
description = string.format("%s %s table with %s legs", shape, m, leg_mat),
mesh = "homedecor_table_"..shape..".obj",
tiles = {
'homedecor_blanktile.png',
'homedecor_blanktile.png',
'homedecor_'..m..'_table_'..shape..'.png',
'homedecor_'..m..'_table_edges.png',
"homedecor_table_legs_"..leg_mat..".png",
},
groups = { snappy = 3 },
sounds = s,
})
end
end
minetest.register_alias('homedecor:'..m..'_table_large_b', 'homedecor:'..m..'_table_large')
minetest.register_alias('homedecor:'..m..'_table_small_square_b', 'homedecor:'..m..'_table_small_square')
minetest.register_alias('homedecor:'..m..'_table_small_round_b', 'homedecor:'..m..'_table_small_round')
minetest.register_alias('homedecor:'..m..'_table_large', 'homedecor:'..m..'_table_large_square')
end
-- other tables
homedecor.register("utility_table_top", {
description = S("Utility Table"),
tiles = {
'homedecor_utility_table_tb.png',
'homedecor_utility_table_tb.png',
'homedecor_utility_table_edges.png',
'homedecor_utility_table_edges.png',
'homedecor_utility_table_edges.png',
'homedecor_utility_table_edges.png'
},
wield_image = 'homedecor_utility_table_tb.png',
inventory_image = 'homedecor_utility_table_tb.png',
groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(),
paramtype2 = "wallmounted",
node_box = {
type = "wallmounted",
wall_bottom = { -0.5, -0.5, -0.5, 0.5, -0.4375, 0.5 },
wall_top = { -0.5, 0.4375, -0.5, 0.5, 0.5, 0.5 },
wall_side = { -0.5, -0.5, -0.5, -0.4375, 0.5, 0.5 },
},
selection_box = {
type = "wallmounted",
wall_bottom = { -0.5, -0.5, -0.5, 0.5, -0.4375, 0.5 },
wall_top = { -0.5, 0.4375, -0.5, 0.5, 0.5, 0.5 },
wall_side = { -0.5, -0.5, -0.5, -0.4375, 0.5, 0.5 },
},
})
-- Various kinds of table legs
-- local above
materials = {
{ "brass", S("brass") },
{ "wrought_iron", S("wrought iron") },
}
for _, t in ipairs(materials) do
local name, desc = unpack(t)
homedecor.register("table_legs_"..name, {
description = S("Table Legs (@1)", desc),
drawtype = "plantlike",
tiles = {"homedecor_table_legs_"..name..".png"},
inventory_image = "homedecor_table_legs_"..name..".png",
wield_image = "homedecor_table_legs_"..name..".png",
walkable = false,
groups = {snappy=3},
sounds = default.node_sound_wood_defaults(),
selection_box = {
type = "fixed",
fixed = { -0.37, -0.5, -0.37, 0.37, 0.5, 0.37 }
},
})
end
homedecor.register("utility_table_legs", {
description = S("Legs for Utility Table"),
drawtype = "plantlike",
tiles = { 'homedecor_utility_table_legs.png' },
inventory_image = 'homedecor_utility_table_legs_inv.png',
wield_image = 'homedecor_utility_table_legs.png',
walkable = false,
groups = { snappy = 3 },
sounds = default.node_sound_wood_defaults(),
selection_box = {
type = "fixed",
fixed = { -0.37, -0.5, -0.37, 0.37, 0.5, 0.37 }
},
})
-- crafting
minetest.register_craft( {
@ -266,7 +228,20 @@ minetest.register_craft({
burntime = 30,
})
for _, shape in ipairs (table_shapes) do
for _, leg in ipairs(leg_materials) do
for _, mat in ipairs(tabletop_materials) do
minetest.register_craft({
output = "homedecor:"..mat[1].."_table_"..shape.."_with_"..leg[1].."_legs",
type = "shapeless",
recipe = {
"homedecor:"..mat[1].."_table_"..shape,
"homedecor:table_legs_"..leg[1]
},
})
end
end
end
-- recycling
@ -329,3 +304,4 @@ minetest.register_craft({
"homedecor:wood_table_large"
}
})