From dd0602ac00af87ed67b88201273f1f548f0bdf1e Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 13 Oct 2023 08:44:27 +0200 Subject: [PATCH] node allow-list --- README.md | 4 ++ handlers/mesecons.lua | 57 +++++++++++++++++++++++++--- init.lua | 1 - register_wand.lua | 33 ---------------- textures/mtui_register_mesecons.png | Bin 0 -> 5278 bytes textures/mtui_register_wand.png | Bin 587 -> 0 bytes 6 files changed, 56 insertions(+), 39 deletions(-) delete mode 100644 register_wand.lua create mode 100644 textures/mtui_register_mesecons.png delete mode 100644 textures/mtui_register_wand.png diff --git a/README.md b/README.md index 49276c9..db31149 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # mtui_mod +# License + +* Code: `MIT` +* Textures: `CC-BY-SA 3.0` \ No newline at end of file diff --git a/handlers/mesecons.lua b/handlers/mesecons.lua index 57b24ac..2003007 100644 --- a/handlers/mesecons.lua +++ b/handlers/mesecons.lua @@ -1,3 +1,7 @@ +local allowed_nodes = { + ["mesecons_switch:mesecon_switch_off"] = true, + ["mesecons_switch:mesecon_switch_on"] = true +} local switch_off_def = assert(minetest.registered_nodes["mesecons_switch:mesecon_switch_off"]) local switch_on_def = assert(minetest.registered_nodes["mesecons_switch:mesecon_switch_on"]) @@ -65,7 +69,12 @@ end local lightstone_colors = {"red", "green", "blue", "gray", "darkgray", "yellow", "orange", "white", "pink", "magenta", "cyan", "violet"} for _, color in ipairs(lightstone_colors) do - local def_on = assert(minetest.registered_nodes["mesecons_lightstone:lightstone_" .. color .. "_on"]) + local on_nodename = "mesecons_lightstone:lightstone_" .. color .. "_on" + local off_nodename = "mesecons_lightstone:lightstone_" .. color .. "_off" + allowed_nodes[on_nodename] = true + allowed_nodes[off_nodename] = true + + local def_on = assert(minetest.registered_nodes[on_nodename]) local old_action_off = assert(def_on.mesecons.effector.action_off) def_on.mesecons.effector.action_off = function(pos, node) mtui.send_command({ @@ -73,13 +82,13 @@ for _, color in ipairs(lightstone_colors) do data = { pos = pos, state = "off", - nodename = "mesecons_lightstone:lightstone_" .. color .. "_off" + nodename = off_nodename } }) return old_action_off(pos, node) end - local def_off = assert(minetest.registered_nodes["mesecons_lightstone:lightstone_" .. color .. "_off"]) + local def_off = assert(minetest.registered_nodes[off_nodename]) local old_action_on = assert(def_off.mesecons.effector.action_on) def_off.mesecons.effector.action_on = function(pos, node) mtui.send_command({ @@ -87,9 +96,47 @@ for _, color in ipairs(lightstone_colors) do data = { pos = pos, state = "on", - nodename = "mesecons_lightstone:lightstone_" .. color .. "_on" + nodename = on_nodename } }) return old_action_on(pos, node) end -end \ No newline at end of file +end + +minetest.register_tool("mtui:register_mesecons", { + description = "UI Register wand", + inventory_image = "mtui_register_mesecons.png", + stack_max = 1, + on_use = function(_, player, pointed_thing) + local pos = pointed_thing.under + if not pos then + return + end + local node = minetest.get_node_or_nil(pos) + local playername = player:get_player_name() + + if not allowed_nodes[node.name] then + minetest.chat_send_player(playername, "Node '" .. node.name .. + "' at position '" .. minetest.pos_to_string(pos) .. "' not supported!") + return + end + + if minetest.is_protected(pos, playername) then + minetest.chat_send_player(playername, "Node '" .. node.name .. + "' at position '" .. minetest.pos_to_string(pos) .. "' is protected!") + return + end + + mtui.send_command({ + type = "mesecons_register", + data = { + pos = pos, + playername = playername, + nodename = node.name + } + }) + + minetest.chat_send_player(playername, "Node '" .. node.name .. + "' at position '" .. minetest.pos_to_string(pos) .. "' has been registered") + end +}) \ No newline at end of file diff --git a/init.lua b/init.lua index a2a5a47..47be527 100644 --- a/init.lua +++ b/init.lua @@ -21,7 +21,6 @@ dofile(MP.."/stats.lua") dofile(MP.."/log.lua") dofile(MP.."/log_file.lua") dofile(MP.."/log_technic.lua") -dofile(MP.."/register_wand.lua") dofile(MP.."/control.lua") dofile(MP.."/controls/builtin.lua") diff --git a/register_wand.lua b/register_wand.lua deleted file mode 100644 index 2e12f8a..0000000 --- a/register_wand.lua +++ /dev/null @@ -1,33 +0,0 @@ --- TODO: common node-registration function - -minetest.register_tool("mtui:register_wand", { - description = "UI Register wand", - inventory_image = "mtui_register_wand.png", - stack_max = 1, - on_use = function(_, player, pointed_thing) - local pos = pointed_thing.under - if not pos then - return - end - local node = minetest.get_node_or_nil(pos) - local playername = player:get_player_name() - - if minetest.is_protected(pos, playername) then - minetest.chat_send_player(playername, "Node '" .. node.name .. - "' at position '" .. minetest.pos_to_string(pos) .. "' is protected!") - return - end - - mtui.send_command({ - type = "mesecons_register", - data = { - pos = pos, - playername = playername, - nodename = node.name - } - }) - - minetest.chat_send_player(playername, "Node '" .. node.name .. - "' at position '" .. minetest.pos_to_string(pos) .. "' has been registered") - end -}) \ No newline at end of file diff --git a/textures/mtui_register_mesecons.png b/textures/mtui_register_mesecons.png new file mode 100644 index 0000000000000000000000000000000000000000..f042785ce067aa271349852c07cf1c6fb031cf28 GIT binary patch literal 5278 zcmeHKd010d77vPmsZnqjQDe{%&?GO(OGr|}matWWk$qEmd3gzeY$PEG)YeuOg(5<+ zGIm69Unnl%j-XV)1uGS$XhlSHv@S&%nYw^7HvtvC=|6rm{m@t#s- zOK~{Uuk{hJ6^~rT^tHN4M+bHucN()Z$)G9rA~blWu{X?_7v35+X0mV6)$y6Xc=fYh z*{)q}s-OrqpL91VDuU=XmlaL)cEw{;)40lU`|j!&*$Hx&9c`KuTH~8fYkC5gJl%I{ zI@bfsYikl*3ayE2ES8Hp%eUlsr#(|VjDrY!76}Z!lnI54X>rQ(^$)HGFX?+3P3SDS zpU{0o?E7@|9hU~1x=KT7d7xu<+vK152Ua}UJ7Q6VTUl*v>ej1oLVsH7+5VXbcI-x0 z1zufydb((|o%i=Uw<+=ymNnd)=Ra;!9rD-UnBK7MH}S~u=4gE01&t(zyL z3(L9#R=CNIPXBdY&r|2(O(@4B{=7qjW*Yv)_Nv2O%3AipukJLgpD$CL%&*Z{3Fens_mHv#tDu$J=Ztba z9cT@!#=~;Iq}A&S`4Rs-{o@&>V;4Rk^n6(MUMP>YetFw(;q||ylWG4j)!~nAkDMo( zYV*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