forked from nalc/homedecor_modpack
add a horizontal banister, rename the diagonals (+alias)
includes just enough code to try to auto-route them as they're placed. the "root" node is now the horizontal one - if you have diagonals and they don't place right, they should after you dig them and place again.
This commit is contained in:
parent
610f2e0bdc
commit
10b859ba59
@ -222,20 +222,74 @@ function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||
return
|
||||
end
|
||||
|
||||
local lxd = homedecor.fdir_to_left[fdir+1][1]
|
||||
local lzd = homedecor.fdir_to_left[fdir+1][2]
|
||||
|
||||
local rxd = homedecor.fdir_to_right[fdir+1][1]
|
||||
local rzd = homedecor.fdir_to_right[fdir+1][2]
|
||||
|
||||
local fxd = homedecor.fdir_to_fwd[fdir+1][1]
|
||||
local fzd = homedecor.fdir_to_fwd[fdir+1][2]
|
||||
|
||||
local fwd_pos = { x=pos.x+fxd, y=pos.y, z=pos.z+fzd }
|
||||
local left_pos = { x=pos.x+lxd, y=pos.y, z=pos.z+lzd }
|
||||
local right_pos = { x=pos.x+rxd, y=pos.y, z=pos.z+rzd }
|
||||
|
||||
local right_fwd_above_pos = { x=pos.x+rxd+fxd, y=pos.y+1, z=pos.z+rzd+fzd }
|
||||
local left_fwd_above_pos = { x=pos.x+lxd+fxd, y=pos.y+1, z=pos.z+lzd+fzd }
|
||||
|
||||
local fwd_node = minetest.get_node(fwd_pos)
|
||||
local left_node = minetest.get_node(left_pos)
|
||||
local right_node = minetest.get_node(right_pos)
|
||||
|
||||
local left_below_node = minetest.get_node({x=left_pos.x, y=left_pos.y-1, z=left_pos.z})
|
||||
local right_below_node = minetest.get_node({x=right_pos.x, y=right_pos.y-1, z=right_pos.z})
|
||||
|
||||
local right_fwd_above_node = minetest.get_node(right_fwd_above_pos)
|
||||
local left_fwd_above_node = minetest.get_node(left_fwd_above_pos)
|
||||
|
||||
local new_place_name = itemstack:get_name()
|
||||
local n = 0
|
||||
|
||||
if placer:get_player_control()["sneak"]
|
||||
or not is_buildable_to(placer_name, right_fwd_above_pos, nil, right_fwd_above_pos) then
|
||||
-- try to place a diagonal one on the side of blocks stacked like stairs
|
||||
if not is_buildable_to(placer_name, right_fwd_above_pos, nil, right_fwd_above_pos) then
|
||||
new_place_name = string.gsub(new_place_name, "_horizontal", "_diagonal_right")
|
||||
elseif not is_buildable_to(placer_name, left_fwd_above_pos, nil, left_fwd_above_pos) then
|
||||
new_place_name = string.gsub(new_place_name, "_horizontal", "_diagonal_left")
|
||||
|
||||
-- try to follow a diagonal with the corresponding horizontal
|
||||
-- from the top of a diagonal...
|
||||
elseif left_below_node and string.find(left_below_node.name, "homedecor:banister_.*_diagonal") then
|
||||
fdir = left_below_node.param2
|
||||
new_place_name = string.gsub(left_below_node.name, "_diagonal_.-$", "_horizontal")
|
||||
elseif right_below_node and string.find(right_below_node.name, "homedecor:banister_.*_diagonal") then
|
||||
fdir = right_below_node.param2
|
||||
new_place_name = string.gsub(right_below_node.name, "_diagonal_.-$", "_horizontal")
|
||||
|
||||
-- from the bottom of it
|
||||
elseif left_node and string.find(left_node.name, "homedecor:banister_.*_diagonal") then
|
||||
fdir = left_node.param2
|
||||
new_place_name = string.gsub(left_node.name, "_diagonal_.-$", "_horizontal")
|
||||
elseif right_node and string.find(right_node.name, "homedecor:banister_.*_diagonal") then
|
||||
fdir = right_node.param2
|
||||
new_place_name = string.gsub(right_node.name, "_diagonal_.-$", "_horizontal")
|
||||
|
||||
-- try to follow a horizontal with another of the same
|
||||
elseif left_node and string.find(left_node.name, "homedecor:banister_.*_horizontal") then
|
||||
fdir = left_node.param2
|
||||
new_place_name = left_node.name
|
||||
elseif right_node and string.find(right_node.name, "homedecor:banister_.*_horizontal") then
|
||||
fdir = right_node.param2
|
||||
new_place_name = right_node.name
|
||||
end
|
||||
|
||||
-- manually invert left-right orientation
|
||||
if placer:get_player_control()["sneak"] then
|
||||
if string.find(new_place_name, "banister_.*_diagonal") then
|
||||
new_place_name = string.gsub(new_place_name, "_left", "_right")
|
||||
else
|
||||
new_place_name = string.gsub(new_place_name, "_right", "_left")
|
||||
end
|
||||
end
|
||||
|
||||
minetest.set_node(pos, {name = new_place_name, param2 = fdir})
|
||||
|
@ -727,26 +727,31 @@ homedecor.banister_materials = {
|
||||
}
|
||||
}
|
||||
|
||||
for _, side in ipairs({"left", "right"}) do
|
||||
for _, side in ipairs({"diagonal_left", "diagonal_right", "horizontal"}) do
|
||||
|
||||
for i in ipairs(homedecor.banister_materials) do
|
||||
|
||||
local name = homedecor.banister_materials[i][1]
|
||||
local nodename = "banister_"..name.."_"..side
|
||||
|
||||
local groups = { snappy = 3, not_in_creative_inventory = 1 }
|
||||
local cbox = {
|
||||
type = "fixed",
|
||||
fixed = { -9/16, -3/16, 5/16, 9/16, 24/16, 8/16}
|
||||
fixed = { -9/16, -3/16, 5/16, 9/16, 24/16, 8/16 }
|
||||
}
|
||||
|
||||
local onplace = nil
|
||||
groups = { snappy = 3, not_in_creative_inventory = 1}
|
||||
|
||||
if side == "left" then
|
||||
onplace = homedecor.place_banister
|
||||
if side == "horizontal" then
|
||||
groups = { snappy = 3 }
|
||||
cbox = {
|
||||
type = "fixed",
|
||||
fixed = { -8/16, -8/16, 5/16, 8/16, 8/16, 8/16 }
|
||||
}
|
||||
else
|
||||
minetest.register_alias(string.gsub("homedecor:"..nodename, "diagonal_", ""), "homedecor:"..nodename)
|
||||
end
|
||||
|
||||
homedecor.register("banister_"..name.."_"..side, {
|
||||
description = S("Banister for Stairs ("..homedecor.banister_materials[i][2]..", "..side.." side)"),
|
||||
homedecor.register(nodename, {
|
||||
description = S("Banister for Stairs ("..homedecor.banister_materials[i][2]..", "..side..")"),
|
||||
mesh = "homedecor_banister_"..side..".obj",
|
||||
tiles = {
|
||||
homedecor.banister_materials[i][3],
|
||||
@ -756,8 +761,8 @@ for _, side in ipairs({"left", "right"}) do
|
||||
groups = groups,
|
||||
selection_box = cbox,
|
||||
collision_box = cbox,
|
||||
on_place = onplace,
|
||||
drop = "homedecor:banister_"..name.."_left",
|
||||
on_place = homedecor.place_banister,
|
||||
drop = "homedecor:banister_"..name.."_horizontal",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
87
homedecor/models/homedecor_banister_horizontal.obj
Normal file
87
homedecor/models/homedecor_banister_horizontal.obj
Normal file
@ -0,0 +1,87 @@
|
||||
# Blender v2.73 (sub 0) OBJ File: 'banister-horizontal_left.blend'
|
||||
# www.blender.org
|
||||
o Cylinder_Cylinder_verticals
|
||||
v -0.312500 0.437500 0.437500
|
||||
v -0.312500 0.437500 0.500000
|
||||
v -0.250000 0.437500 0.500000
|
||||
v -0.250000 0.437500 0.437500
|
||||
v -0.312500 -0.500000 0.437500
|
||||
v -0.312500 -0.500000 0.500000
|
||||
v -0.250000 -0.500000 0.500000
|
||||
v -0.250000 -0.500000 0.437500
|
||||
v 0.500000 0.437500 0.312500
|
||||
v 0.500000 0.437500 0.500000
|
||||
v -0.500000 0.437500 0.500000
|
||||
v -0.500000 0.437500 0.312500
|
||||
v 0.500000 0.500000 0.312500
|
||||
v 0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 0.312500
|
||||
v 0.312500 -0.500000 0.437500
|
||||
v 0.312500 -0.500000 0.500000
|
||||
v 0.250000 -0.500000 0.500000
|
||||
v 0.250000 -0.500000 0.437500
|
||||
v 0.312500 0.437500 0.437500
|
||||
v 0.312500 0.437500 0.500000
|
||||
v 0.250000 0.437500 0.500000
|
||||
v 0.250000 0.437500 0.437500
|
||||
vt 0.750000 0.062500
|
||||
vt 0.750000 0.000000
|
||||
vt 0.812500 0.000000
|
||||
vt 0.812500 0.062500
|
||||
vt 0.937500 0.000000
|
||||
vt 0.937500 0.062500
|
||||
vt 0.000000 0.062500
|
||||
vt 0.000000 -0.000000
|
||||
vt 0.937500 0.562500
|
||||
vt 0.937500 0.625000
|
||||
vt -0.000000 0.625000
|
||||
vt -0.000000 0.562500
|
||||
vt 0.937500 0.875000
|
||||
vt 0.937500 0.812500
|
||||
vt 0.000000 0.812500
|
||||
vt 0.000000 0.875000
|
||||
vt 0.937500 0.750000
|
||||
vt 0.937500 0.687500
|
||||
vt -0.000000 0.687500
|
||||
vt -0.000000 0.750000
|
||||
vt 0.187500 0.062500
|
||||
vt 0.187500 0.000000
|
||||
vt 0.250000 0.000000
|
||||
vt 0.250000 0.062500
|
||||
vt -0.062500 1.000000
|
||||
vt 0.125000 1.000000
|
||||
vt 0.125000 0.937500
|
||||
vt -0.062500 0.937500
|
||||
vt 0.000000 1.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 1.000000 0.937500
|
||||
vt -0.000000 0.937500
|
||||
vt 0.000000 0.187500
|
||||
vt 1.000000 0.187500
|
||||
vt 1.000000 0.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
g Cylinder_Cylinder_verticals_Cylinder_Cylinder_verticals_verticals
|
||||
s off
|
||||
f 8/1/1 7/2/1 6/3/1 5/4/1
|
||||
f 1/5/2 4/6/2 8/7/2 5/8/2
|
||||
f 2/9/3 1/10/3 5/11/3 6/12/3
|
||||
f 3/6/4 2/5/4 6/8/4 7/7/4
|
||||
f 21/13/5 22/14/5 18/15/5 17/16/5
|
||||
f 22/17/4 23/18/4 19/19/4 18/20/4
|
||||
f 23/9/3 24/10/3 20/11/3 19/12/3
|
||||
f 24/18/2 21/17/2 17/20/2 20/19/2
|
||||
f 17/21/1 18/22/1 19/23/1 20/24/1
|
||||
f 4/13/5 3/14/5 7/15/5 8/16/5
|
||||
g Cylinder_Cylinder_verticals_Cylinder_Cylinder_verticals_railing
|
||||
f 13/25/5 14/26/5 10/27/5 9/28/5
|
||||
f 14/29/4 15/30/4 11/31/4 10/32/4
|
||||
f 15/26/3 16/25/3 12/28/3 11/27/3
|
||||
f 16/30/2 13/29/2 9/32/2 12/31/2
|
||||
f 9/8/1 10/33/1 11/34/1 12/35/1
|
||||
f 16/35/6 15/34/6 14/33/6 13/8/6
|
Loading…
Reference in New Issue
Block a user