Allow speciying custom top and overhang nodes

Can be true, false, or a table with two entries (topnode, overhang).

If false, the main pole extends all the way up to the specified height,
and the light is simply placed next to it.

if true, the main pole extends all the way up, and then steps right by
1m, with the light hanging from it.  This is the default.

if a table, the main pole stops 1m short of the top, and the two
specified nodes are placed above it, with the overhang to the right, and
the light hanging under it.

also fixed the custom base node not getting _digilines extension when
called-for
master
Vanessa Dannenberg 2021-06-27 20:23:51 -04:00
parent 92eb5b9e8d
commit fac56f263c
2 changed files with 19 additions and 11 deletions

View File

@ -38,9 +38,10 @@ function streetlights.check_and_place(itemstack, placer, pointed_thing, def)
local light = def.light local light = def.light
local param2 = def.param2 local param2 = def.param2
local height = def.height or 5 local height = def.height or 5
local has_top = (def.has_top ~= false)
local needs_digiline_wire = def.needs_digiline_wire local needs_digiline_wire = def.needs_digiline_wire
local distributor_node = def.distributor_node local distributor_node = def.distributor_node
local poletop = (def.topnodes and (type(def.topnodes) == "table") and def.topnodes.poletop) or pole
local overhang = (def.topnodes and (type(def.topnodes) == "table") and def.topnodes.overhang) or pole
local controls = placer:get_player_control() local controls = placer:get_player_control()
if not placer then return end if not placer then return end
@ -85,7 +86,7 @@ function streetlights.check_and_place(itemstack, placer, pointed_thing, def)
def3 = minetest.registered_items[node3.name] def3 = minetest.registered_items[node3.name]
if minetest.is_protected(pos3, player_name) or not (def3 and def3.buildable_to) then return end if minetest.is_protected(pos3, player_name) or not (def3 and def3.buildable_to) then return end
if has_top then if def.topnodes ~= false then
pos4 = { x = pos1.x+fdir_to_right[fdir+1][1], y = pos1.y+height-1, z = pos1.z+fdir_to_right[fdir+1][2] } pos4 = { x = pos1.x+fdir_to_right[fdir+1][1], y = pos1.y+height-1, z = pos1.z+fdir_to_right[fdir+1][2] }
node4 = minetest.get_node(pos4) node4 = minetest.get_node(pos4)
def4 = minetest.registered_items[node4.name] def4 = minetest.registered_items[node4.name]
@ -146,20 +147,27 @@ function streetlights.check_and_place(itemstack, placer, pointed_thing, def)
end end
local pole2 = pole local pole2 = pole
if needs_digiline_wire then if needs_digiline_wire then
base = base.."_digilines"
pole2 = pole.."_digilines" pole2 = pole.."_digilines"
poletop = poletop.."_digilines"
overhang = overhang.."_digilines"
end end
local pos2b = {x=pos1.x, y = pos1.y+1, z=pos1.z} local pos2b = {x=pos1.x, y = pos1.y+1, z=pos1.z}
minetest.set_node(pos2b, {name = base }) minetest.set_node(pos2b, {name = base })
for i = 2, height do for i = 2, height-1 do
pos2 = {x=pos1.x, y = pos1.y+i, z=pos1.z} pos2 = {x=pos1.x, y = pos1.y+i, z=pos1.z}
minetest.set_node(pos2, {name = pole2 }) minetest.set_node(pos2, {name = pole2 })
end end
if has_top then local pos2t = {x=pos1.x, y = pos1.y+height, z=pos1.z}
minetest.set_node(pos3, { name = pole2 }) minetest.set_node(pos2t, {name = poletop })
if def.topnodes ~= false then
minetest.set_node(pos3, { name = overhang })
minetest.set_node(pos4, { name = light, param2 = param2 }) minetest.set_node(pos4, { name = light, param2 = param2 })
else else
minetest.set_node(pos3, { name = light, param2 = param2 }) minetest.set_node(pos3, { name = light, param2 = param2 })

View File

@ -30,7 +30,7 @@ end
local digiline_wire_node = "digilines:wire_std_00000000" local digiline_wire_node = "digilines:wire_std_00000000"
local poles_tab = { local poles_tab = {
-- material name, mod name, node name, optional base, optional height, has top section -- material name, mod name, node name, optional base, optional height, top section
{ "wood", "default", "default:fence_wood" }, { "wood", "default", "default:fence_wood" },
{ "junglewood", "default", "default:fence_junglewood" }, { "junglewood", "default", "default:fence_junglewood" },
{ "brass", "homedecor_fences", "homedecor:fence_brass"}, { "brass", "homedecor_fences", "homedecor:fence_brass"},
@ -51,7 +51,7 @@ for _, pole in ipairs(poles_tab) do
local matnode = pole[3] local matnode = pole[3]
local basenode = pole[4] local basenode = pole[4]
local height = pole[5] local height = pole[5]
local has_top = pole[6] local topnodes = pole[6]
if minetest.get_modpath(matmod) then if minetest.get_modpath(matmod) then
@ -122,7 +122,7 @@ for _, pole in ipairs(poles_tab) do
pole=matnode, pole=matnode,
light=lightnode, light=lightnode,
param2=lightparam2, param2=lightparam2,
has_top = has_top, topnodes = topnodes,
height = height height = height
}) })
end end
@ -157,7 +157,7 @@ for _, pole in ipairs(poles_tab) do
pole=matnode, pole=matnode,
light=lightnode, light=lightnode,
param2=lightparam2, param2=lightparam2,
has_top = has_top, topnodes = topnodes,
height = height, height = height,
needs_digiline_wire=true needs_digiline_wire=true
}) })
@ -215,7 +215,7 @@ for _, pole in ipairs(poles_tab) do
pole=matnode, pole=matnode,
light=lightnode, light=lightnode,
param2=lightparam2, param2=lightparam2,
has_top = has_top, topnodes = topnodes,
height = height, height = height,
needs_digiline_wire=true, needs_digiline_wire=true,
distributor_node=distributor distributor_node=distributor