1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2025-07-22 07:10:21 +02:00

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:
Vanessa Ezekowitz
2015-05-11 18:03:21 -04:00
parent 610f2e0bdc
commit 10b859ba59
5 changed files with 160 additions and 14 deletions

View File

@ -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
new_place_name = string.gsub(new_place_name, "_left", "_right")
-- 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})