From ff5ccba41f67f790f1c7954674dc4cbea70f4601 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Mon, 28 Jun 2021 23:19:10 -0400 Subject: [PATCH] extend the generic streetlight code to place schematics add another type of lamp using that feature this one is good for parking lots or common areas, comes in 1-, 2-, and 4-lamp versions, with either a thin or thick base node. --- functions.lua | 165 +++++++++++++----- init.lua | 1 + modern.lua | 55 ++++++ schems/streetlight_parking_lot_1.mts | Bin 0 -> 112 bytes schems/streetlight_parking_lot_2.mts | Bin 0 -> 116 bytes schems/streetlight_parking_lot_4.mts | Bin 0 -> 119 bytes schems/streetlight_parking_lot_hd_fence_1.mts | Bin 0 -> 144 bytes schems/streetlight_parking_lot_hd_fence_2.mts | Bin 0 -> 149 bytes schems/streetlight_parking_lot_hd_fence_4.mts | Bin 0 -> 152 bytes .../simple_streetlights_inv_parking_lot_1.png | Bin 0 -> 656 bytes .../simple_streetlights_inv_parking_lot_2.png | Bin 0 -> 787 bytes .../simple_streetlights_inv_parking_lot_4.png | Bin 0 -> 1056 bytes ...treetlights_inv_parking_lot_hd_fence_1.png | Bin 0 -> 882 bytes ...treetlights_inv_parking_lot_hd_fence_2.png | Bin 0 -> 1006 bytes ...treetlights_inv_parking_lot_hd_fence_4.png | Bin 0 -> 1294 bytes 15 files changed, 173 insertions(+), 48 deletions(-) create mode 100644 schems/streetlight_parking_lot_1.mts create mode 100644 schems/streetlight_parking_lot_2.mts create mode 100644 schems/streetlight_parking_lot_4.mts create mode 100644 schems/streetlight_parking_lot_hd_fence_1.mts create mode 100644 schems/streetlight_parking_lot_hd_fence_2.mts create mode 100644 schems/streetlight_parking_lot_hd_fence_4.mts create mode 100644 textures/simple_streetlights_inv_parking_lot_1.png create mode 100644 textures/simple_streetlights_inv_parking_lot_2.png create mode 100644 textures/simple_streetlights_inv_parking_lot_4.png create mode 100644 textures/simple_streetlights_inv_parking_lot_hd_fence_1.png create mode 100644 textures/simple_streetlights_inv_parking_lot_hd_fence_2.png create mode 100644 textures/simple_streetlights_inv_parking_lot_hd_fence_4.png diff --git a/functions.lua b/functions.lua index f296394..30c3f03 100644 --- a/functions.lua +++ b/functions.lua @@ -11,6 +11,17 @@ local fdir_to_back = { { 0, 1 }, { 1, 0 } } + +-- rotate around Y in order by fdir(+1) +-- x+xo, x+zo, z+xo, z+zo, CW degrees + +local rot_y = { + { 1, 0, 0, 1, 0 }, -- N + { 0, 1, -1, 0, 90 }, -- E + { -1, 0, 0, -1, 180 }, -- S + { 0, -1, 1, 0, 270 }, -- W +} + --digilines compatibility local rules_alldir = { @@ -37,46 +48,93 @@ function streetlights.rightclick_pointed_thing(pos, placer, itemstack, pointed_t return def.on_rightclick(pos, node, placer, itemstack, pointed_thing) or itemstack end -local function can_build(target_pos, fdir, model_def, player_name, controls) - local main_node, node3, node4 - local main_def, def3, def4 - - local main_pos, pos3, pos4 - for i = 1, model_def.height do - main_pos = { x=target_pos.x, y = target_pos.y+i, z=target_pos.z } - main_node = minetest.get_node(main_pos) - main_def = minetest.registered_items[main_node.name] - if minetest.is_protected(main_pos, player_name) or not (main_def and main_def.buildable_to) then return end - end - - pos3 = { - x = target_pos.x+fdir_to_right[fdir+1][1], - y = target_pos.y+model_def.height, - z = target_pos.z+fdir_to_right[fdir+1][2] - } - node3 = minetest.get_node(pos3) - def3 = minetest.registered_items[node3.name] - if minetest.is_protected(pos3, player_name) or not (def3 and def3.buildable_to) then return end - - if def.topnodes ~= false then - pos4 = { - x = target_pos.x+fdir_to_right[fdir+1][1], - y = target_pos.y+model_def.height-1, - z = target_pos.z+fdir_to_right[fdir+1][2] - } - node4 = minetest.get_node(pos4) - def4 = minetest.registered_items[node4.name] - if minetest.is_protected(pos4, player_name) or not (def4 and def4.buildable_to) then return end - end - - local dist_pos = { x = target_pos.x, y = target_pos.y-1, z = target_pos.z } - - if controls.sneak and minetest.is_protected(target_pos, player_name) then return end - if model_def.distributor_node and minetest.is_protected(dist_pos, player_name) then return end - return true +local function rotate_offset_around_y(origin, offs, fdir) + local ox = offs.x + local oz = offs.z + local rx = rot_y[fdir+1][1] * ox + rot_y[fdir+1][2] * oz + local rz = rot_y[fdir+1][3] * ox + rot_y[fdir+1][4] * oz + return {x = origin.x + rx, y = origin.y, z = origin.z + rz} end -local function has_materials(model_def, inv, player_name, controls) + +local function can_build(target_pos, fdir, model_def, player_name, controls) + + if model_def.protection_box then + + local base_pos = {x=target_pos.x, y=target_pos.y+1, z=target_pos.z} + + local r1 = rotate_offset_around_y(base_pos, model_def.protection_box.omin, fdir) + local r2 = rotate_offset_around_y(base_pos, model_def.protection_box.omax, fdir) + + local minp = {x=r1.x, y=r1.y + model_def.protection_box.omin.y, z=r1.z} + local maxp = {x=r2.x, y=r2.y + model_def.protection_box.omax.y, z=r2.z} + + return not minetest.is_area_protected(minp, maxp, player_name, 1) + else + local main_node, node3, node4 + local main_def, def3, def4 + + local main_pos, pos3, pos4 + for i = 1, model_def.height do + main_pos = { x=target_pos.x, y = target_pos.y+i, z=target_pos.z } + main_node = minetest.get_node(main_pos) + main_def = minetest.registered_items[main_node.name] + if minetest.is_protected(main_pos, player_name) or not (main_def and main_def.buildable_to) then return end + end + + pos3 = { + x = target_pos.x+fdir_to_right[fdir+1][1], + y = target_pos.y+model_def.height, + z = target_pos.z+fdir_to_right[fdir+1][2] + } + node3 = minetest.get_node(pos3) + def3 = minetest.registered_items[node3.name] + if minetest.is_protected(pos3, player_name) or not (def3 and def3.buildable_to) then return end + + if model_def.topnodes ~= false then + pos4 = { + x = target_pos.x+fdir_to_right[fdir+1][1], + y = target_pos.y+model_def.height-1, + z = target_pos.z+fdir_to_right[fdir+1][2] + } + node4 = minetest.get_node(pos4) + def4 = minetest.registered_items[node4.name] + if minetest.is_protected(pos4, player_name) or not (def4 and def4.buildable_to) then return end + end + + local dist_pos = { x = target_pos.x, y = target_pos.y-1, z = target_pos.z } + + if controls.sneak and minetest.is_protected(target_pos, player_name) then return end + if model_def.distributor_node and minetest.is_protected(dist_pos, player_name) then return end + return true + end +end + +local function deduct_materials_schematic(model_def, inv, player_name, controls) + for _,mat in ipairs(model_def.materials) do + if not inv:contains_item("main", mat) then + local matname = string.sub(mat, 1, string.find(mat, " ")) + minetest.chat_send_player(player_name, "*** You don't have enough "..matname.." in your inventory!") + return + end + end + + if controls.sneak then + if not inv:contains_item("main", streetlights.concrete) then + minetest.chat_send_player(player_name, "*** You don't have any concrete in your inventory!") + return + else + inv:remove_item("main", streetlights.concrete) + end + end + + for _,mat in ipairs(model_def.materials) do + inv:remove_item("main", mat) + end + +end + +local function deduct_materials_non_schematic(model_def, inv, player_name, controls) -- if main_extends_base, then the base node is one of two pieces -- and the upper piece is not usually directly available to the player, -- as with streets:pole_[top|bottom] (the thin one) @@ -154,10 +212,10 @@ local function has_materials(model_def, inv, player_name, controls) inv:remove_item("main", streetlights.concrete) end end - return num_main -end -local function take_materials(model_def, inv, num_main, controls) + -- if we made it this far, then the player has everything needed + -- so deduct as appropriate + if model_def.poletop ~= model_def.pole and not model_def.main_extends_base then inv:remove_item("main", model_def.poletop) end @@ -187,7 +245,6 @@ local function take_materials(model_def, inv, num_main, controls) if controls.sneak then inv:remove_item("main", streetlights.concrete) end - end local function build_streetlight(target_pos, target_node, target_dir, fdir, model_def, controls) @@ -228,8 +285,6 @@ local function build_streetlight(target_pos, target_node, target_dir, fdir, mode local top_pos = {x=target_pos.x, y = target_pos.y+model_def.height, z=target_pos.z} minetest.set_node(top_pos, {name = model_def.poletop, param2 = target_fdir }) - - local pos2, pos3, pos4 pos3 = { @@ -307,14 +362,28 @@ function streetlights.check_and_place(itemstack, placer, pointed_thing, model_de if not creative.is_enabled_for(player_name) then local inv = placer:get_inventory() - if has_materials(model_def, inv, player_name, controls) then - take_materials(model_def, inv, num_main, controls) + if model_def.materials then + deduct_materials_schematic(model_def, inv, player_name, controls) else - return + deduct_materials_non_schematic(model_def, inv, player_name, controls) end end - build_streetlight(target_pos, target_node, target_dir, fdir, model_def, controls) + if model_def.schematic then + + local base_pos = {x=target_pos.x, y=target_pos.y+1, z=target_pos.z} + +-- local offs = { +-- x = model_def.placement_offsets.x, +-- z = model_def.placement_offsets.z +-- } + +-- local place_pos = rotate_offset_around_y(base_pos, offs, fdir) + + minetest.place_schematic(base_pos, model_def.schematic, rot_y[fdir+1][5], nil, false, {place_center_x=true, place_center_z=true}) + else + build_streetlight(target_pos, target_node, target_dir, fdir, model_def, controls) + end end diff --git a/init.lua b/init.lua index c887698..c4a2175 100644 --- a/init.lua +++ b/init.lua @@ -3,6 +3,7 @@ local modpath = minetest.get_modpath("simple_streetlights") streetlights = {} +streetlights.schematics = {} streetlights.basic_materials = minetest.get_modpath("basic_materials") streetlights.concrete = "basic_materials:concrete_block" streetlights.distributor = "streets:digiline_distributor" diff --git a/modern.lua b/modern.lua index 477c822..186531b 100644 --- a/modern.lua +++ b/modern.lua @@ -19,3 +19,58 @@ minetest.register_tool("simple_streetlights:spawner_modern_walllamp", { }) end }) + +local homedecor_modpath = minetest.get_modpath("homedecor_fences") + +for k,v in pairs({1, 2, 4}) do + streetlights.schematics[k] = + minetest.register_schematic(string.format("schems%sstreetlight_parking_lot_"..v..".mts",DIR_DELIM)) + + local s = (v == 1) and "" or "s" + + minetest.register_tool("simple_streetlights:spawner_modern_parking_lot_"..v, { + description = "Streetlight spawner (parking lot light with "..v.." lamp"..s..")", + inventory_image = "simple_streetlights_inv_parking_lot_"..v..".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, { + schematic = streetlights.schematics[k], + materials = { + "morelights_modern:streetpost_d 4", + "morelights_modern:barlight_c "..v + }, + protection_box = { + omin = {x =-1, y = 0, z =-1}, -- distances relative to the base node + omax = {x = 1, y = 3, z = 1}, + } + }) + end + }) + + streetlights.schematics[k+3] = + minetest.register_schematic(string.format("schems%sstreetlight_parking_lot_hd_fence_"..v..".mts",DIR_DELIM)) + + minetest.register_tool("simple_streetlights:spawner_modern_parking_lot_hd_fence_"..v, { + description = "Streetlight spawner (parking lot light with thicker base and "..v.." lamp"..s..")", + inventory_image = "simple_streetlights_inv_parking_lot_hd_fence_"..v..".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, { + schematic = streetlights.schematics[k+3], + materials = { + "morelights_modern:streetpost_d 3", + "homedecor:fence_wrought_iron", + "morelights_modern:barlight_c "..v + }, + protection_box = { + omin = {x =-1, y = 0, z =-1}, + omax = {x = 1, y = 3, z = 1}, + } + }) + end + }) + + +end diff --git a/schems/streetlight_parking_lot_1.mts b/schems/streetlight_parking_lot_1.mts new file mode 100644 index 0000000000000000000000000000000000000000..e82a36bd3951fb75fa2494d0d4e1bdf24355a233 GIT binary patch literal 112 zcmeYb3HD`RVPFQ~dLRI@m=iOL802#Ei&Aqk(=$qn<8$*q%@#RJNrRfq%@#RJNrRfx%nxnMR`_9iA7+6_+$o|jQrfx zl+@(>BCE92yyVpQ@}m4wpxXG%qWnAtIZVC9B}J*JB?bA#CGja0bCMGdFi9L#5uTCK eHo3=PlHly3kc(9;tJbe~7gT3rV7MmA!T|snl{KIM literal 0 HcmV?d00001 diff --git a/textures/simple_streetlights_inv_parking_lot_1.png b/textures/simple_streetlights_inv_parking_lot_1.png new file mode 100644 index 0000000000000000000000000000000000000000..d976b31da2fec7c4020fbd6e19a597ff57c991b2 GIT binary patch literal 656 zcmV;B0&o3^P)AqT(F**U?3<4MuOrWaDrgsUm#{Gf|-e+nJ9)vq6jX>B_bFo zC}Lo0V&V!Sf`Njt?#E0S?1A3K%4?^mqK>Bf6~%j1Ju}dtL4yVj;)VYo4%siVJ?-3` z*x5=y{g_s>zxnJW)l&7C5^R&x7V*-?bMclb7$9YKYKD@Sl=iNjfiS@UIFtW3vmVW^jB4JzyQ^xAW}Xcrtwt zd;{(Subp$_TFSi(4*>z+feqj^uuD=>OPMdD?brmSz!^(FVm4AL(E=*qBT&XhK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?#&l9w-0@TqmIH3!4T+(+rhE1fX#s61j;(;s(8PNJKD@Ma*6Lci1#EAhK@IKq4fy zFt9RME=3qXNf@H60R|Folv`oI%r`p02m_dpI)K>U6Dw$M6i7Appa{g~;VAGSFiRtX ai9Z3P@9z0=o6uPR0000l?peSi+w%B$R2}OJeK?FjGk`5>k-FDm2Y_r;GyOma3?Jqz` zNE9GwkkTMTK?xEdP{c=qWXB$lXU2!Z#!m7FZq_HKvfSKzo_pT&rGaBRwqrXs#peGX zF1eb9aU60r3B9yCkdJC!XQ^iFY8qZyNyEqIH+~u1xq1D;Y8r+!@A!O3FduMXA>`rt z)9d-xv&S;F{-tvp>$B|m+=+T{WOe~nsEYu@fniADIDAB^fYV0EOeJ8o4nyKv z0#5AbmGr{Nh3G?S5I_Rhj^L`A2&hWA<$0_nb7SQ`_^0g>aoI5~7} zZH-p5i482tbS>0S(+IVem+^d`EX&C9oSjYqjuxX%BA_fv8fnT>tA!0GGN`Kou>J8p z-KRup(S?C$Oo*XuN!3m9Yk&;5=L0PO;*vcS%@smc;RPG~k;5nq)67%=)g z#P0RL11lbBqv5H^0ps?Ub^*h7k1#J8G7QxKh=3gE{UA{cD9dkpA|Nqz0)Y;Y{rIzA zIa!N2p>6~7+WJU1UW~{nB3`K42`u`Yj^HWK1^!dF6gevP9h5UGQS!3k=>Px#07*qo IM6N<$f|Ku+{Qv*} literal 0 HcmV?d00001 diff --git a/textures/simple_streetlights_inv_parking_lot_hd_fence_2.png b/textures/simple_streetlights_inv_parking_lot_hd_fence_2.png new file mode 100644 index 0000000000000000000000000000000000000000..019266dd820f7b6f0a409df88b6377c2cc56eabe GIT binary patch literal 1006 zcmVTM}GBc5JqHgR)!IdZh3Dr_+sg&Y!R(^q)Rb2#kF6^enO5cE^EJNVk^SkGN?*AMH zj^j9v<2Wo1_y2IndaT1xb0N}B-0I0)Yi_5SQ+_?x=WDUPetQ1d-dnFVuGM3$GoN@- z;}t#5Ol!V8eR8h5a^t#;qI2%l{9Kk3pL!_oJzwQ3!0ak(EfuBbJ-pgd-^;kbv&AFG}e5J8|XYB_O5n2A~ z+90Rh&wyuKSWrU%?`JRhVxSk_URb_!>!-<%ep^JAHaFHPBM<(D9s;zH5W>$^}icK`~Sfi{wW+& zA07Zl!QmJKAmfkctOVeVs=)M8#u$JUL`JQ`RtfAWnfu9^3mDZS<0mnzULE-*Fptrj8J)I2FG=2x7)P4UACGD7+Q=Psem*| zDa0|=av5JA$RKYGfQ`Gq(rULT6iY;5j!;2h=qWS;;K9}w_cwlHAOk9uD!#9XTr+0K zNDsKTy-T~35=Iez7!pMh&DO4O!W$a_&`uJZE^Kda6Xx@jO4BH%+;L1e;(rR?tufoIK+j5V@(ej*&;|DP zNhCee^npDU5Gk6TKoe;1|FP3IvKBK!-S^b0?;?7%7?EK`d}q~8pyF~efNy{n@Tql6 ck)slS0Q_!qEZhy>WdHyG07*qoM6N<$f+Z`;Jpcdz literal 0 HcmV?d00001 diff --git a/textures/simple_streetlights_inv_parking_lot_hd_fence_4.png b/textures/simple_streetlights_inv_parking_lot_hd_fence_4.png new file mode 100644 index 0000000000000000000000000000000000000000..849bc184b4f4ea3514d9af63828e0d5c86620b5f GIT binary patch literal 1294 zcmV+p1@ZccP)=%g&#jM5K8cXZ$h&#JGGdq`mA7*xUTr48cv$Ln?(=hXL=6!zW zx%}UU7yh^Z?XFpyXPK#H&zQ-3H1F1fQ=ZjPR_X1K%FSNX{Uwtd4-SBoXDzl}_oF>; z?OSJt?G=}Q`?cS8!#|JZi@^x}uIJakn;z)Xgl*mY;;n?k3lYmQ{v%MgEoMH~7BiRB z1prB}NE%g*ZQrsn9f1uA@88#iWW=yjp0&Q+vrevDwq$(kOI;^Yo@Lbo08`Q?NrSZz zcJA1cPBl9l=C&pO5klM|91pXq+2Y%k%RBQur%z5iBDZ$Mvd(&m0z=YjNtbIO?Ag6D zop9*<8^;^kV&Ny^VZK`P26K4yfnJ5uIhoLg_6$Jdhz-351+l$+Js}QUb|x1 z=-Hm{r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