From 4da69dd2067f9f1aa47a022fa00827731b0f73cd Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Thu, 30 May 2019 01:30:30 -0400 Subject: [PATCH] If digilines is enabled, create digiline conducting copies of all registered pole nodes, with simple texture overlays to make it evident. Also, create suitable spawners for these, but only if the light source to be spawned is also digilines compatible. When using a digiline-compat spawner, you can set the channel for the light source (and thus all future lights you place) by shift-punching while wielding the spawner. This setting persists until the next restart, or until you change it with another shift-punch. --- depends.txt | 1 + simple.lua | 136 +++++++++++++++++- ...streetlights_inv_pole_digiline_overlay.png | Bin 0 -> 651 bytes ...streetlights_pole_digiline_overlay_cnb.png | Bin 0 -> 144 bytes ..._streetlights_pole_digiline_overlay_fl.png | Bin 0 -> 146 bytes 5 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 textures/simple_streetlights_inv_pole_digiline_overlay.png create mode 100644 textures/simple_streetlights_pole_digiline_overlay_cnb.png create mode 100644 textures/simple_streetlights_pole_digiline_overlay_fl.png diff --git a/depends.txt b/depends.txt index 26a770c..8ef9489 100644 --- a/depends.txt +++ b/depends.txt @@ -6,3 +6,4 @@ gloopblocks? homedecor_fences? homedecor_lighting? streetspoles? +digilines? diff --git a/simple.lua b/simple.lua index 41808a3..eadfa21 100644 --- a/simple.lua +++ b/simple.lua @@ -1,4 +1,3 @@ - local fdir_to_right = { { 1, 0 }, { 0, -1 }, @@ -6,16 +5,72 @@ local fdir_to_right = { { 0, 1 } } +--digilines compatibility + +local rules_alldir = { + {x = 0, y = 0, z = -1}, -- borrowed from lightstones + {x = 1, y = 0, z = 0}, + {x = -1, y = 0, z = 0}, + {x = 0, y = 0, z = 1}, + {x = 1, y = 1, z = 0}, + {x = 1, y = -1, z = 0}, + {x = -1, y = 1, z = 0}, + {x = -1, y = -1, z = 0}, + {x = 0, y = 1, z = 1}, + {x = 0, y = -1, z = 1}, + {x = 0, y = 1, z = -1}, + {x = 0, y = -1, z = -1}, + {x = 0, y = -1, z = 0}, +} + +local enable_digilines = minetest.get_modpath("digilines") + +ilights.player_channels = {} -- last light source channel name that was set by a given player + +if enable_digilines then + + minetest.register_on_player_receive_fields(function(player, formname, fields) + if not player then return end + if fields.channel and fields.channel ~= "" and formname == "simple_streetlights:set_channel" then + local playername = player:get_player_name() + minetest.chat_send_player(playername, "*** The light source on all streetlights placed from now on will have the channel set to \""..fields.channel.."\"") + ilights.player_channels[playername] = fields.channel + end + end) + + function ilights.digiline_on_use(itemstack, user, pointed_thing) + if user and user:get_player_control().sneak then + local name = user:get_player_name() + local form = "field[channel;Set a channel for future streetlights;]" + minetest.show_formspec(name, "simple_streetlights:set_channel", form) + end + end +end + +local digiline_wire_node = "digilines:wire_std_00000000" + +-- clone node + +local function clone_node(name) + local node2 = {} + local node = minetest.registered_nodes[name] + for k,v in pairs(node) do + node2[k]=v + end + return node2 +end + minetest.register_privilege("streetlight", { description = "Allows using streetlight spawners", give_to_singleplayer = true }) -local function check_and_place(itemstack, placer, pointed_thing, pole, light, param2) +local function check_and_place(itemstack, placer, pointed_thing, pole, light, param2, needs_digiline_wire) local sneak = placer:get_player_control().sneak if not placer then return end + local playername = placer:get_player_name() if not minetest.check_player_privs(placer, "streetlight") then - minetest.chat_send_player(placer:get_player_name(), "*** You don't have permission to use a streetlight spawner.") + minetest.chat_send_player(playername, "*** You don't have permission to use a streetlight spawner.") return end local player_name = placer:get_player_name() @@ -63,18 +118,23 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa if not creative.is_enabled_for(player_name) then local inv = placer:get_inventory() if not inv:contains_item("main", pole.." 6") then - minetest.chat_send_player(placer:get_player_name(), "*** You don't have enough "..pole.." in your inventory!") + minetest.chat_send_player(playername, "*** You don't have enough "..pole.." in your inventory!") return end if not inv:contains_item("main", light) then - minetest.chat_send_player(placer:get_player_name(), "*** You don't have any "..light.." in your inventory!") + minetest.chat_send_player(playername, "*** You don't have any "..light.." in your inventory!") + return + end + + if needs_digiline_wire and not inv:contains_item("main", digiline_wire_node) then + minetest.chat_send_player(playername, "*** You don't have any digiline wires in your inventory!") return end if sneak then if not inv:contains_item("main", streetlights.concrete) then - minetest.chat_send_player(placer:get_player_name(), "*** You don't have any concrete in your inventory!") + minetest.chat_send_player(playername, "*** You don't have any concrete in your inventory!") return else inv:remove_item("main", streetlights.concrete) @@ -83,6 +143,7 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa inv:remove_item("main", pole.." 6") inv:remove_item("main", light) + inv:remove_item("main", digiline_wire_node) end @@ -96,6 +157,10 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa end minetest.set_node(pos3, { name = pole }) minetest.set_node(pos4, { name = light, param2 = param2 }) + + if needs_digiline_wire and ilights.player_channels[playername] then + minetest.get_meta(pos4):set_string("channel", ilights.player_channels[playername]) + end end local poles_tab = { @@ -127,6 +192,36 @@ for _, pole in ipairs(poles_tab) do local lightnode = light[3] local lightparam2 = light[4] or 0 + if enable_digilines then + local def = clone_node(matnode) + local dl_overlay + + if def.drawtype == "fencelike" then + dl_overlay = "simple_streetlights_pole_digiline_overlay_fl.png" + else + dl_overlay = "simple_streetlights_pole_digiline_overlay_cnb.png" + end + + for i,t in ipairs(def.tiles) do + def.tiles[i] = t.."^"..dl_overlay + end + def.description = def.description.." (digilines conducting)" + def.digiline = { + wire = { + rules = { + {x= 0, y= 0, z=-1}, + {x= 0, y= 0, z= 1}, + {x= 1, y= 0, z= 0}, + {x=-1, y= 0, z= 0}, + {x= 0, y=-1, z= 0}, + {x= 0, y= 1, z= 0}, + {x= 0, y=-2, z= 0} + } + } + } + minetest.register_node(":"..matnode.."_digilines", def) + end + if minetest.get_modpath(lightmod) then minetest.register_tool("simple_streetlights:spawner_"..matname.."_"..lightname, { @@ -154,6 +249,35 @@ for _, pole in ipairs(poles_tab) do } }) + if enable_digilines and minetest.registered_nodes[lightnode].digiline then + minetest.register_tool("simple_streetlights:spawner_"..matname.."_"..lightname.."_digilines", { + description = "Streetlight spawner ("..matname.." pole, with "..lightname..", digilines conducting pole)", + inventory_image = "simple_streetlights_inv_pole_"..matname..".png".. + "^simple_streetlights_inv_pole_digiline_overlay.png".. + "^simple_streetlights_inv_light_source_"..lightname..".png", + use_texture_alpha = true, + tool_capabilities = { full_punch_interval=0.1 }, + on_place = function(itemstack, placer, pointed_thing) + check_and_place(itemstack, placer, pointed_thing, matnode.."_digilines", lightnode, lightparam2, true) + end, + on_use = ilights.digiline_on_use + }) + + minetest.register_craft({ + output = "simple_streetlights:spawner_"..matname.."_"..lightname.."_digilines", + type = "shapeless", + recipe = { + matnode, + matnode, + matnode, + matnode, + matnode, + matnode, + lightnode, + digiline_wire_node, + } + }) + end end end end diff --git a/textures/simple_streetlights_inv_pole_digiline_overlay.png b/textures/simple_streetlights_inv_pole_digiline_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..b1ce8a8dea541b65f707ced6e0b6f7a67a1fcd66 GIT binary patch literal 651 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lNlJ896Vhd zLn>~)ov}afa)3yCeZqCWEbBytJaailIffP{9gnxi*o0z#ad>bXi7HK6cjVGSV;#vE zCj?eLVw{kWu%teAlEvOap*J2p2ewALZnW9))8ti7%<^UZ!RJU8$a8CuU#FzTi1ug2|Lh zk-ma2x%`P24&Sgpa>U+AghzmtnWMg;`LSJHiTb8GDUPpW*jc-u_YPA* zdfH#-$CbjD>p!>%S~;jNe7SII@AWz1|G!+#eemJE#hhQS-Zwn)Zdv^K%CA+)$IpLb z{>oSpJ27+F*DRg~ZI!;Y3}08NeLiU*+c1scfmzPi@`l?54bApHJD(@lKWEe`0W~Q?n1p3&2{QKHnvn|Q`6|;e^_p`h64qSUa_uHOd)BX26TT>VycHmOc zAJMg4ZP#}HTz+77dVYFe^CoMBpF*p9zf9vhJn;&xBcvSM*O3-(1hF*xe8B}^+|nIyhI zqwvVobas|UP5c^(>@i;$moiVd$}Ym^5GEgB!4O&N@Q`6gC-;TU=hOKQq{;_aF-)&@ sc*&6Rm9Z79E}#7Z1<*j^zhxbBNv`0Er{2kbfT@eY)78&qol`;+0EpiwG5`Po literal 0 HcmV?d00001 diff --git a/textures/simple_streetlights_pole_digiline_overlay_cnb.png b/textures/simple_streetlights_pole_digiline_overlay_cnb.png new file mode 100644 index 0000000000000000000000000000000000000000..a1b72ec5accc9669ee95c5d1fe7959bb35c8771d GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_cTPZ!6K zh{MS#3c^2BWS*raBp9?6ozII*_&rmmc!mUFVdQ&MBb@08Mo(T>t<8 literal 0 HcmV?d00001 diff --git a/textures/simple_streetlights_pole_digiline_overlay_fl.png b/textures/simple_streetlights_pole_digiline_overlay_fl.png new file mode 100644 index 0000000000000000000000000000000000000000..75bd8801f217af369076ee4a8845e1a654a3340f GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_czPZ!6K zh{JEMIPx+m@UR?g{ou-LCeRpuufpk=?XJ}eJoTBcX8*o3(