From 7f5eaac5c35d4c26d566b39a45e93c4582712b90 Mon Sep 17 00:00:00 2001 From: cheapie Date: Thu, 30 Apr 2020 00:44:04 -0500 Subject: [PATCH] Add channel copier --- camera.lua | 1 + cardreader.lua | 1 + channelcopier.lua | 90 +++++++++++++++++++++++++++ depends.txt | 1 + detector.lua | 1 + init.lua | 1 + ioexpander.lua | 1 + light.lua | 1 + nic.lua | 1 + noteblock.lua | 1 + panel.lua | 5 ++ piezo.lua | 1 + piston.lua | 2 + switches.lua | 7 +++ textures/digistuff_channelcopier.png | Bin 0 -> 2428 bytes timer.lua | 1 + touchscreen.lua | 5 ++ 17 files changed, 120 insertions(+) create mode 100644 channelcopier.lua create mode 100644 textures/digistuff_channelcopier.png diff --git a/camera.lua b/camera.lua index 3a2a129..e228790 100644 --- a/camera.lua +++ b/camera.lua @@ -11,6 +11,7 @@ minetest.register_node("digistuff:camera", { { receptor = {} }, + _digistuff_channelcopier_fieldname = "channel", groups = {cracky=2}, paramtype = "light", paramtype2 = "facedir", diff --git a/cardreader.lua b/cardreader.lua index 3279e90..2592d6d 100644 --- a/cardreader.lua +++ b/cardreader.lua @@ -58,6 +58,7 @@ minetest.register_node("digistuff:card_reader",{ local meta = minetest.get_meta(pos) if fields.channel then meta:set_string("channel",fields.channel) end end, + _digistuff_channelcopier_fieldname = "channel", paramtype = "light", paramtype2 = "facedir", tiles = { diff --git a/channelcopier.lua b/channelcopier.lua new file mode 100644 index 0000000..7a86514 --- /dev/null +++ b/channelcopier.lua @@ -0,0 +1,90 @@ +minetest.register_tool("digistuff:channelcopier",{ + description = "Digilines Channel Copier (shift-click to copy, click to paste)", + inventory_image = "digistuff_channelcopier.png", + on_use = function(itemstack,player,pointed) + if not (pointed and pointed.under) then return itemstack end + if not (player and player:get_player_name()) then return end + local pos = pointed.under + local name = player:get_player_name() + local node = minetest.get_node(pos) + if not node then return itemstack end + if minetest.registered_nodes[node.name]._digistuff_channelcopier_fieldname then + if player:get_player_control().sneak then + local channel = minetest.get_meta(pointed.under):get_string(minetest.registered_nodes[node.name]._digistuff_channelcopier_fieldname) + if type(channel) == "string" and channel ~= "" then + local stackmeta = itemstack:get_meta() + stackmeta:set_string("channel",channel) + stackmeta:set_string("description","Digilines Channel Copier, set to: "..channel) + if player and player:get_player_name() then minetest.chat_send_player(player:get_player_name(),"Digilines channel copier set to "..minetest.colorize("#00FFFF",channel)..". Click another node to paste this channel there.") end + end + else + if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then + minetest.record_protection_violation(pos,name) + return itemstack + end + if minetest.registered_nodes[node.name]._digistuff_channelcopier_fieldname then + local channel = itemstack:get_meta():get_string("channel") + if type(channel) ~= "string" or channel == "" then + minetest.chat_send_player(name,minetest.colorize("#FF5555","Error:").." No channel has been set yet. Shift-click to copy one.") + return itemstack + end + local oldchannel = minetest.get_meta(pos):get_string(minetest.registered_nodes[node.name]._digistuff_channelcopier_fieldname) + minetest.get_meta(pos):set_string(minetest.registered_nodes[node.name]._digistuff_channelcopier_fieldname,channel) + if type(oldchannel) == "string" and oldchannel ~= "" then + if channel == oldchannel then + minetest.chat_send_player(name,"Channel of target node is already "..minetest.colorize("#00FFFF",oldchannel)..".") + else + minetest.chat_send_player(name,string.format("Channel of target node changed from %s to %s.",minetest.colorize("#00FFFF",oldchannel),minetest.colorize("#00FFFF",channel))) + end + else + minetest.chat_send_player(name,"Channel of target node set to "..minetest.colorize("#00FFFF",channel)..".") + end + if type(minetest.registered_nodes[node.name]._digistuff_channelcopier_onset) == "function" then + minetest.registered_nodes[node.name]._digistuff_channelcopier_onset(pos,node,player,channel,oldchannel) + end + end + end + end + return itemstack + end, +}) + +minetest.register_craft({ + output = "digistuff:channelcopier", + recipe = { + {"mesecons_fpga:programmer"}, + {"digilines:wire_std_00000000"} + } +}) + + +--NOTE: Asking to have your own mod added to here is not the right way to add compatibility with the channel copier. +--Instead, include a _digistuff_channelcopier_fieldname field in your nodedef set to the name of the metadata field that contains the channel. +--If you need an action to occur after the channel is set, place a function in _digistuff_channelcopier_onset. +--Function signature is _digistuff_channelcopier_onset(pos,node,player,new_channel,old_channel) + +local additionalnodes = { + ["digilines:chest"] = "channel", + ["digilines:lcd"] = "channel", + ["digilines:lightsensor"] = "channel", + ["digilines:rtc"] = "channel", + ["pipeworks:digiline_detector_tube_1"] = "channel", + ["pipeworks:digiline_detector_tube_2"] = "channel", + ["pipeworks:digiline_detector_tube_3"] = "channel", + ["pipeworks:digiline_detector_tube_4"] = "channel", + ["pipeworks:digiline_detector_tube_5"] = "channel", + ["pipeworks:digiline_detector_tube_6"] = "channel", + ["pipeworks:digiline_detector_tube_7"] = "channel", + ["pipeworks:digiline_detector_tube_8"] = "channel", + ["pipeworks:digiline_detector_tube_9"] = "channel", + ["pipeworks:digiline_detector_tube_10"] = "channel", + ["pipeworks:digiline_filter"] = "channel", +} + +for name,field in pairs(additionalnodes) do + if minetest.registered_nodes[name] and not minetest.registered_nodes[name]._digistuff_channelcopier_fieldname then + minetest.override_item(name,{_digistuff_channelcopier_fieldname = field}) + end +end + + diff --git a/depends.txt b/depends.txt index a3bfdda..5a8efa0 100644 --- a/depends.txt +++ b/depends.txt @@ -3,3 +3,4 @@ digilines mesecons? mesecons_mvps? screwdriver? +pipeworks? diff --git a/detector.lua b/detector.lua index f6542da..8cb4170 100644 --- a/detector.lua +++ b/detector.lua @@ -12,6 +12,7 @@ minetest.register_node("digistuff:detector", { local meta = minetest.get_meta(pos) meta:set_string("formspec","size[8,4;]field[1,1;6,2;channel;Channel;${channel}]field[1,2;6,2;radius;Radius;${radius}]button_exit[2.25,3;3,1;submit;Save]") end, + _digistuff_channelcopier_fieldname = "channel", on_receive_fields = function(pos, formname, fields, sender) local name = sender:get_player_name() if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then diff --git a/init.lua b/init.lua index bcc7b40..765ed74 100644 --- a/init.lua +++ b/init.lua @@ -14,6 +14,7 @@ local components = { "piston", "timer", "cardreader", + "channelcopier", } if minetest.get_modpath("mesecons_luacontroller") then table.insert(components,"ioexpander") end diff --git a/ioexpander.lua b/ioexpander.lua index 1acfde7..59da390 100644 --- a/ioexpander.lua +++ b/ioexpander.lua @@ -118,6 +118,7 @@ for i=0,15,1 do meta:set_int("don",0) meta:set_int("outstate",i) end, + _digistuff_channelcopier_fieldname = "channel", tiles = gettiles(i), inventory_image = "digistuff_ioexp_top.png", drawtype = "nodebox", diff --git a/light.lua b/light.lua index aeca08d..ec9b6df 100644 --- a/light.lua +++ b/light.lua @@ -13,6 +13,7 @@ for i=0,14,1 do {-0.25,0.4,-0.25,0.25,0.5,0.25}, } }, + _digistuff_channelcopier_fieldname = "channel", groups = i > 0 and {cracky = 1, not_in_creative_inventory = 1} or {cracky = 1}, is_ground_content = false, light_source = i, diff --git a/nic.lua b/nic.lua index 50bf105..03019fe 100644 --- a/nic.lua +++ b/nic.lua @@ -21,6 +21,7 @@ minetest.register_node("digistuff:nic", { type = "fixed", fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 }, }, + _digistuff_channelcopier_fieldname = "channel", node_box = { --From Luacontroller type = "fixed", diff --git a/noteblock.lua b/noteblock.lua index 5bd0883..80c4936 100644 --- a/noteblock.lua +++ b/noteblock.lua @@ -21,6 +21,7 @@ minetest.register_node("digistuff:noteblock", { tiles = { "mesecons_noteblock.png" }, + _digistuff_channelcopier_fieldname = "channel", on_receive_fields = function(pos, formname, fields, sender) local name = sender:get_player_name() if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then diff --git a/panel.lua b/panel.lua index d543af1..7ecc633 100644 --- a/panel.lua +++ b/panel.lua @@ -123,6 +123,11 @@ minetest.register_node("digistuff:panel", { "digistuff_panel_back.png", "digistuff_panel_front.png" }, + _digistuff_channelcopier_fieldname = "channel", + _digistuff_channelcopier_onset = function(pos) + local helpmsg = "Channel has been set. Waiting for data..." + digistuff.update_panel_formspec(pos,helpmsg) + end, paramtype = "light", paramtype2 = "facedir", node_box = { diff --git a/piezo.lua b/piezo.lua index 39fce0d..3f040c8 100644 --- a/piezo.lua +++ b/piezo.lua @@ -14,6 +14,7 @@ minetest.register_node("digistuff:piezo", { digistuff.sounds_playing[pos_hash] = nil end end, + _digistuff_channelcopier_fieldname = "channel", tiles = { "digistuff_piezo_top.png", "digistuff_piezo_sides.png", diff --git a/piston.lua b/piston.lua index 070da43..bd8860b 100644 --- a/piston.lua +++ b/piston.lua @@ -66,6 +66,7 @@ minetest.register_node("digistuff:piston", { local meta = minetest.get_meta(pos) if fields.channel then meta:set_string("channel",fields.channel) end end, + _digistuff_channelcopier_fieldname = "channel", digiline = { wire = { rules = { @@ -124,6 +125,7 @@ minetest.register_node("digistuff:piston_ext", { {-0.5,-0.5,-1.5,0.5,0.5,0.5}, } }, + _digistuff_channelcopier_fieldname = "channel", on_rotate = function() return false end, on_receive_fields = function(pos, formname, fields, sender) local name = sender:get_player_name() diff --git a/switches.lua b/switches.lua index 87d7a87..6f18432 100644 --- a/switches.lua +++ b/switches.lua @@ -95,6 +95,7 @@ minetest.register_node("digistuff:button", { rules = digistuff.button_get_rules, }, }, + _digistuff_channelcopier_fieldname = "channel", groups = {dig_immediate = 2,digiline_receiver = 1,}, description = "Digilines Button", on_construct = function(pos) @@ -160,6 +161,7 @@ minetest.register_node("digistuff:button_off", { action = digistuff.button_handle_digilines, }, }, + _digistuff_channelcopier_fieldname = "channel", groups = {dig_immediate = 2,not_in_creative_inventory = 1,digiline_receiver = 1,}, drop = "digistuff:button", after_destruct = digistuff.remove_receiver, @@ -204,6 +206,7 @@ minetest.register_node("digistuff:button_off_pushed", { action = digistuff.button_handle_digilines, }, }, + _digistuff_channelcopier_fieldname = "channel", on_timer = digistuff.button_turnoff, groups = {dig_immediate = 2,not_in_creative_inventory = 1,digiline_receiver = 1,}, drop = "digistuff:button", @@ -240,6 +243,7 @@ minetest.register_node("digistuff:button_on", { { -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself } }, + _digistuff_channelcopier_fieldname = "channel", digiline = { receptor = {}, @@ -279,6 +283,7 @@ minetest.register_node("digistuff:button_on_pushed", { type = "fixed", fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 } }, + _digistuff_channelcopier_fieldname = "channel", node_box = { type = "fixed", fixed = { @@ -338,6 +343,7 @@ minetest.register_node("digistuff:wall_knob", { {-0.4,-0.4,0,0.4,0.4,0.5}, }, }, + _digistuff_channelcopier_fieldname = "channel", groups = {dig_immediate = 2,digiline_receiver = 1,}, description = "Digilines Wall Knob", on_construct = function(pos) @@ -397,6 +403,7 @@ minetest.register_node("digistuff:wall_knob_configured", { {-0.4,-0.4,0,0.4,0.4,0.5}, }, }, + _digistuff_channelcopier_fieldname = "channel", groups = {dig_immediate = 2,digiline_receiver = 1,not_in_creative_inventory = 1,}, description = "Digilines Wall Knob (configured state - you hacker you!)", drop = "digistuff:wall_knob", diff --git a/textures/digistuff_channelcopier.png b/textures/digistuff_channelcopier.png new file mode 100644 index 0000000000000000000000000000000000000000..deb07e4481882e7fc62008167d0abee424b26c29 GIT binary patch literal 2428 zcmV-?34`{DP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O1Yuvg9ZX{O1&N1SG_E9KaAUH|XO}vf5Sk-gLi+ zE=SpzMM#+`VO4+q+tfe!Fuk6f{L|IU^I6u!;mZ0O zKTIDZ{armf!~> zx70iOr}YLtr`2!XuyhL}G`<`l`!)Cj;>X73c*Ji5qWwoW>)+ZHTB|d^Szd`{!UxcYlFh*GN?WO*2@F$mQt#pV; zhl3UT;;vk{(V6Ra%mN|Q7H@U{yst&Se&`2M1%r0L91vjAd78+UZf%*tv%x%z=gbOH z{#phA5%#ulh71_c4uU5~+B171;21zqg6C|6GZ-Li`GS)y#yD1<1NXhL#?zR~mL2zQ z)Fu#NjWZtHM3X?4h=qQ<1ZXH(W5rtQthYhgXp=KeoORB5*Na^8#*4S!dGCXdJ_Qpb z*x-T>A;gd(M}rz@ql-R<7-LGT5;jV(l`ub{Cv!Ggvdu309CFO5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