From 64d992eec12684b25aa0ec17d557f70d62f94fd4 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Sun, 27 Jun 2021 22:32:50 -0400 Subject: [PATCH] add a "modern"-style light morelights_modern wall lamp on streets thin post plus some rotation helper options to make it work (should be generic enough to work for other designs as well) --- functions.lua | 38 ++++++++++++++---- init.lua | 9 ++++- modern.lua | 20 +++++++++ ..._streetlights_inv_pole_modern_walllamp.png | Bin 0 -> 1108 bytes 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 modern.lua create mode 100644 textures/simple_streetlights_inv_pole_modern_walllamp.png diff --git a/functions.lua b/functions.lua index 8a2176a..2531fdd 100644 --- a/functions.lua +++ b/functions.lua @@ -5,6 +5,12 @@ local fdir_to_right = { { 0, 1 } } +local fdir_to_back = { + { 0, -1 }, + { -1, 0 }, + { 0, 1 }, + { 1, 0 } +} --digilines compatibility local rules_alldir = { @@ -36,19 +42,23 @@ function streetlights.check_and_place(itemstack, placer, pointed_thing, def) local pole = def.pole local base = def.base or def.pole local light = def.light - local param2 = def.param2 local height = def.height or 5 local needs_digiline_wire = def.needs_digiline_wire 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 copy_pole_fdir = def.copy_pole_fdir + local light_fdir = def.light_fdir local controls = placer:get_player_control() if not placer then return end local playername = placer:get_player_name() local player_name = placer:get_player_name() - local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + + local placer_pos = placer:get_pos() -- this bit borrowed from builtin/game/item.lua + local target_dir = vector.subtract(pointed_thing.above, placer_pos) + local fdir = minetest.dir_to_facedir(target_dir) local pos1 = minetest.get_pointed_thing_position(pointed_thing) local node1 = minetest.get_node(pos1) @@ -155,22 +165,36 @@ function streetlights.check_and_place(itemstack, placer, pointed_thing, def) overhang = overhang.."_digilines" end + local target_fdir + + if copy_pole_fdir == true then + if def.node_rotation then + target_fdir = minetest.dir_to_facedir(vector.rotate(target_dir, {x=0, y=def.node_rotation, z=0})) + else + target_fdir = fdir + end + + if def.light_fdir == "auto" then -- the light should use the same fdir as the pole + light_fdir = target_fdir + end + end + local pos2b = {x=pos1.x, y = pos1.y+1, z=pos1.z} - minetest.set_node(pos2b, {name = base }) + minetest.set_node(pos2b, {name = base, param2 = target_fdir }) for i = 2, height-1 do pos2 = {x=pos1.x, y = pos1.y+i, z=pos1.z} - minetest.set_node(pos2, {name = pole2 }) + minetest.set_node(pos2, {name = pole2, param2 = target_fdir }) end local pos2t = {x=pos1.x, y = pos1.y+height, z=pos1.z} - minetest.set_node(pos2t, {name = poletop }) + minetest.set_node(pos2t, {name = poletop, param2 = target_fdir }) 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 = light_fdir }) else - minetest.set_node(pos3, { name = light, param2 = param2 }) + minetest.set_node(pos3, { name = light, param2 = light_fdir }) end if needs_digiline_wire and ilights.player_channels[playername] then diff --git a/init.lua b/init.lua index b6c462c..c887698 100644 --- a/init.lua +++ b/init.lua @@ -11,6 +11,11 @@ streetlights.vert_digiline = "digistuff:vertical_bottom" dofile(modpath.."/functions.lua") dofile(modpath.."/simple.lua") -if minetest.get_modpath("homedecor_lighting") and minetest.get_modpath("streetspoles") then - dofile(modpath.."/minedot.lua") +if minetest.get_modpath("streetspoles") then + if minetest.get_modpath("homedecor_lighting") then + dofile(modpath.."/minedot.lua") + end + if minetest.get_modpath("morelights_modern") then + dofile(modpath.."/modern.lua") + end end diff --git a/modern.lua b/modern.lua new file mode 100644 index 0000000..de7afe8 --- /dev/null +++ b/modern.lua @@ -0,0 +1,20 @@ +-- streets:pole_* with morelights_modern:walllamp + +minetest.register_tool("simple_streetlights:spawner_modern_walllamp", { + description = "Streetlight spawner (streets thin pole with modern wall lamp)", + inventory_image = "simple_streetlights_inv_pole_modern_walllamp.png", + use_texture_alpha = true, + tool_capabilities = { full_punch_interval=0.1 }, + on_place = function(itemstack, placer, pointed_thing) + streetlights.check_and_place(itemstack, placer, pointed_thing, { + base = "streets:pole_bottom", + pole = "streets:pole_top", + light = "morelights_modern:walllamp", + topnodes = false, + height = 4, + copy_pole_fdir = true, + node_rotation = math.pi/2, -- 90° CCW + light_fdir = "auto", + }) + end +}) diff --git a/textures/simple_streetlights_inv_pole_modern_walllamp.png b/textures/simple_streetlights_inv_pole_modern_walllamp.png new file mode 100644 index 0000000000000000000000000000000000000000..847cbf667e08d1a0b507006b529c426c73a1f681 GIT binary patch literal 1108 zcmV-a1grarP)^+*B?9s&Kl*W3N<(xuB!jX(T>7~?Cz2QkLQX)b2! zh^wl4AKKpQ;^D*9*%;#~UiR7802__0&Kd%%<9%@E)$ zaBOBvz!*Uly!WV51M!weT7a2l4nQ@q^5qwNbLDai&;!b{oLK;Ry&k<@m({OV_-bYO z31I#J0H(%GHUS4T#@Oc2{5-0@o%&c#K!VPTh!=$2&hG6tr8T=8ARq$H3cKCy+pWpX zEC5zUuWVHL{>Pu#_~Tk2?(p`x*CG770jvUl%`68@FmE|W1Rj3qv2bMZUVhuy`Q7`$ z8yDXHbhRjodS-ipt*y?Ht*y?_ORp})u?DySyaqg)>R6s?Y;JZIwzs?2*4D1Xr%#{m z10PRQ_$23mvUI2h78dU3t#jwUJ$d59c_3s1fGUVM%CbdOwd02uKk25-$OPSBGwBKu zNni2_l%R{CI{A22O$tDYcDMoQt18~B8xHFts|@f6g5sRTT4`H5XR-pI9`q6U-vj9P z>%2GsRaBvA6z`S6pr022V;vAhKt!b7u99*<0v!;%Dt!<{q-wQFmsJK>>!PX#=Pcg) zq`RNS4?s{2G>yL_giwMKP{81v1t>zu41l^GA~GUFpk>VT9N;?w0BfD9(y!|VRU`zJ ztN;*^2sESm*W@0EO~V0#hyeuWGUI^JD;3p%2xZe~nNqFMRg9{d3^_oCqx#p$ zahQ`1AOZssi-;wJ%nXrEr^8^-N7W-Dwyx`aDR6!Lqhe+OsHzf?(TIFFtPdQ8_xAe7 zfB5dgR4z#*@C42H*HKj^t=9e}Y;JCP_TL+r6&(Oz8WHeb4>U!ed-2^rXSM{69z7JT zmEO1$6q3v*lM11c8m#LP35KBU3;_UZEvkx1DuWVsB30EM8zPb)03vA9cvL;vwZr4s zRrRQ1jgh$w0g&LFop^#ph5#rbjHbicd4l7P5Mw6CzZO{nFzN@?7$f)ONP^vwDIzqD z&+il%42B*QYZDuSDW&jeI^5(5fVF~%V6Br@tISacn46iPs%3Tnh)CZ#i3zU0JgUF3RS8Qv