From 99cb021f15358e03c797b79fdcf58a7a364a5ed0 Mon Sep 17 00:00:00 2001 From: Novatux Date: Sun, 8 Jun 2014 08:29:17 +0200 Subject: [PATCH] Add node detector, which works like the player detector but detects a specific nodename (or any node except air) in front of it. --- mesecons_detector/init.lua | 147 ++++++++++++++++++ .../textures/jeija_node_detector_off.png | Bin 0 -> 717 bytes .../textures/jeija_node_detector_on.png | Bin 0 -> 727 bytes 3 files changed, 147 insertions(+) create mode 100644 mesecons_detector/textures/jeija_node_detector_off.png create mode 100644 mesecons_detector/textures/jeija_node_detector_on.png diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua index 88614b5..b4ea3f1 100644 --- a/mesecons_detector/init.lua +++ b/mesecons_detector/init.lua @@ -108,3 +108,150 @@ minetest.register_abm( end end, }) + +-- Node detector +-- Detects the node in front of it + +local node_detector_make_formspec = function (pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", "size[9,2.5]" .. + "field[0.3, 0;9,2;scanname;Name of node to scan for (empty for any):;${scanname}]".. + "field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]".. + "button_exit[7,0.75;2,3;;Save]") +end + +local node_detector_on_receive_fields = function(pos, formname, fields) + if not fields.scanname or not fields.digiline_channel then return end; + + local meta = minetest.get_meta(pos) + meta:set_string("scanname", fields.scanname) + meta:set_string("digiline_channel", fields.digiline_channel) + node_detector_make_formspec(pos) +end + +-- returns true if player was found, false if not +local node_detector_scan = function (pos) + local node = minetest.get_node(pos) + local frontpos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) + local frontnode = minetest.get_node(frontpos) + local meta = minetest.get_meta(pos) + return (frontnode.name == meta:get_string("scanname")) or + (frontnode.name ~= "air" and frontnode.name ~= "ignore" and meta:get_string("scanname") == "") +end + +-- set player name when receiving a digiline signal on a specific channel +node_detector_digiline = { + effector = { + action = function (pos, node, channel, msg) + local meta = minetest.get_meta(pos) + local active_channel = meta:get_string("digiline_channel") + if channel == active_channel then + meta:set_string("scanname", msg) + node_detector_make_formspec(pos) + end + end, + } +} + +minetest.register_node("mesecons_detector:node_detector_off", { + tiles = {"default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "jeija_node_detector_off.png"}, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + groups = {cracky=3}, + description="Node Detector", + mesecons = {receptor = { + state = mesecon.state.off + }}, + on_construct = node_detector_make_formspec, + on_receive_fields = node_detector_on_receive_fields, + after_place_node = function (pos, placer) + local placer_pos = placer:getpos() + + --correct for the player's height + if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end + + --correct for 6d facedir + if placer_pos then + local dir = { + x = pos.x - placer_pos.x, + y = pos.y - placer_pos.y, + z = pos.z - placer_pos.z + } + local node = minetest.get_node(pos) + node.param2 = minetest.dir_to_facedir(dir, true) + minetest.set_node(pos, node) + minetest.log("action", "real (6d) facedir: " .. node.param2) + end + end, + sounds = default.node_sound_stone_defaults(), + digiline = node_detector_digiline +}) + +minetest.register_node("mesecons_detector:node_detector_on", { + tiles = {"default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "jeija_node_detector_on.png"}, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + groups = {cracky=3,not_in_creative_inventory=1}, + drop = 'mesecons_detector:node_detector_off', + mesecons = {receptor = { + state = mesecon.state.on + }}, + on_construct = node_detector_make_formspec, + on_receive_fields = node_detector_on_receive_fields, + after_place_node = function (pos, placer) + local placer_pos = placer:getpos() + + --correct for the player's height + if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end + + --correct for 6d facedir + if placer_pos then + local dir = { + x = pos.x - placer_pos.x, + y = pos.y - placer_pos.y, + z = pos.z - placer_pos.z + } + local node = minetest.get_node(pos) + node.param2 = minetest.dir_to_facedir(dir, true) + minetest.set_node(pos, node) + minetest.log("action", "real (6d) facedir: " .. node.param2) + end + end, + sounds = default.node_sound_stone_defaults(), + digiline = node_detector_digiline +}) + +minetest.register_craft({ + output = 'mesecons_detector:node_detector_off', + recipe = { + {"default:steel_ingot", "group:mesecon_conductor_craftable", "default:steel_ingot"}, + {"default:steel_ingot", "mesecons_luacontroller:luacontroller0000", "default:steel_ingot"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + } +}) + +minetest.register_abm( + {nodenames = {"mesecons_detector:node_detector_off"}, + interval = 1.0, + chance = 1, + action = function(pos, node) + if node_detector_scan(pos) then + minetest.swap_node(pos, {name = "mesecons_detector:node_detector_on", param2 = node.param2}) + mesecon:receptor_on(pos) + end + end, +}) + +minetest.register_abm( + {nodenames = {"mesecons_detector:node_detector_on"}, + interval = 1.0, + chance = 1, + action = function(pos, node) + if not node_detector_scan(pos) then + minetest.swap_node(pos, {name = "mesecons_detector:node_detector_off", param2 = node.param2}) + mesecon:receptor_off(pos) + end + end, +}) diff --git a/mesecons_detector/textures/jeija_node_detector_off.png b/mesecons_detector/textures/jeija_node_detector_off.png new file mode 100644 index 0000000000000000000000000000000000000000..6d130ad60d3f9e10a1494560e5146b580bc5a745 GIT binary patch literal 717 zcmV;;0y6!HP)9%F}_sO#E$Z;WZ0=HL0bKvY8b zm~>@do)#R@bnNR7AD*9|8Drz|7_7D4djJ@p|9MZ8B@+@%QAXlqtC*Yw`1AYst9S1@ zola2{u(Pv+h)OBq%yVvj{zA!KlvXjPluE7X&kd zLLpqp1i)CpxQwBrH2^53{tkz*xw)yeR!S+YGv~laVvLOGQaUPCNJUlQ)3esv7_+st zC90~DQW|4INI*!EXC&a9C(mLgA@a*&l?V~L-L9C;W;tihx!{b9amYBMEXyZC3fX5u z0Wk!vb*IyrOeV0sy*-^ywbq#!EJOMElg@mpqztGy#-$6K1Ax}LEX)1w05jBj-#+N~sv*3U$s2AvouY#iA&R<#O3HjXXFwkWyY=URrC1!{P1i zZBG}2n1oSggzUd@5Ontz}%00000NkvXXu0mjfg;!1v literal 0 HcmV?d00001 diff --git a/mesecons_detector/textures/jeija_node_detector_on.png b/mesecons_detector/textures/jeija_node_detector_on.png new file mode 100644 index 0000000000000000000000000000000000000000..926a9d1d0ba5e3979975150196327d2a68fb30de GIT binary patch literal 727 zcmV;|0x127P)6hN!$)}yPt z7e=-hLKtIVf|;xgfti62h&LfHA29nsc7goNK)%6{FR)Euz<3x3L$tEBFcubGv@ERd zSW;J2-+O1F{W+U+4ZPJQxffA0Gjr-|vsd zW4&B1r_-qrB81R1jWMQanwOWCwrvqHgpg9I>so8ww(WdA*D=PF(r`G8F_vY?%!s(P zwS|a62qI$U?d@%5cFx`1-RZ-_!~6StDW!9ch=@pQO+)~&p*N-w!diQDbfl}Q3L$v! z>$?8;{wpg216_>H6zkP1E6TI-{dYgUzP<_}CXfVWj(kpGf6Nw8h zS1DznKVSdz!~WZ%D4cWp;NXCWj4{lTg7}i1btLT4N`qbOY-WGrU)pu>-U}hVfAdC7 zCX=>pz4t*xmupPYqazg+ve053QfQ;gt=8HY^WSKscXxNKwZ<5$tw1RZN0nqJjLmS3 z+IEF5BL8o#_1^F8?WwXX0l<4tDG{(_$;cAqN(L!Wky>@DO(G)d^?GVPpCh7_Qb_4U z#;st<76BU~iX2cg#2Br$MNv$rQ@y{xKby_0wTz4qe)hkbOo%lIgPq}&f{IFOZLQ6+ z?D+UtUSD4?7K`Cl70*8&*>f`i{a{N8mP0GyqjX=e7`8)FdhkB@(L zUAOtY8LX6IW+GBb<#`SOvZ|`8s&;mE5RsXUF)5`D+P1AyN=mt0E}e7h^}4QWI5{~1 zfSa3}JkLj?(Zj<-S(fML=S|Zr7K_WvO8~gKx*Cti*4m4Ui*GLdfWRAp%Rc}B002ov JPDHLkV1lK2R`37- literal 0 HcmV?d00001