From 808eeed572a85b16b350a3d53678ac284507ce2a Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Thu, 12 Oct 2023 14:03:42 +0200 Subject: [PATCH] wand --- handlers/mesecons.lua | 19 +++++-------------- init.lua | 1 + register_wand.lua | 29 +++++++++++++++++++++++++++++ textures/mtui_register_wand.png | Bin 0 -> 587 bytes 4 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 register_wand.lua create mode 100644 textures/mtui_register_wand.png diff --git a/handlers/mesecons.lua b/handlers/mesecons.lua index 2d2dcb6..a752193 100644 --- a/handlers/mesecons.lua +++ b/handlers/mesecons.lua @@ -10,37 +10,30 @@ mtui.register_on_command("mesecons_set", function(data) local node = minetest.get_node_or_nil(data.pos) if node == nil then -- not loaded - return - end - - if node.name ~= data.nodename then - -- wrong nodename - return { - success = false, - nodename_mismatch = true - } + return { success = false } end if data.state == "on" then if node.name == "mesecons_switch:mesecon_switch_off" then -- switch in off-state, turn on switch_off_def.on_rightclick(data.pos, node) + return { success = true } elseif node.name == "mesecons_button:button_off" then -- button in off-state, turn on for 1 second button_off_def.on_rightclick(data.pos, node) -- call turnoff async, in case the node-timer does not fire (unloaded area) minetest.after(1, mesecon.button_turnoff, data.pos) + return { success = true } end elseif data.state == "off" then if node.name == "mesecons_switch:mesecon_switch_on" then -- switch in on-state, turn off switch_on_def.on_rightclick(data.pos, node) + return { success = true } end end - return { - success = true - } + return { success = false } end) -- game -> ui @@ -88,7 +81,6 @@ for _, color in ipairs(lightstone_colors) do data = { pos = pos, state = "on", - color = color, nodename = node.name } }) @@ -105,7 +97,6 @@ for _, color in ipairs(lightstone_colors) do data = { pos = pos, state = "off", - color = color, nodename = node.name } }) diff --git a/init.lua b/init.lua index 1435abe..a328f89 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,7 @@ 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 new file mode 100644 index 0000000..5806a83 --- /dev/null +++ b/register_wand.lua @@ -0,0 +1,29 @@ +minetest.register_tool("mtui:register_wand", { + description = "UI Register wand", + inventory_image = "mtui_register_wand.png", + stack_max = 1, + range = 0, + on_use = function(_, player, pointed_thing) + local pos = pointed_thing.under + 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_wand.png b/textures/mtui_register_wand.png new file mode 100644 index 0000000000000000000000000000000000000000..a2f8508526a85319433e589d8eff5ad0e05650ba GIT binary patch literal 587 zcmV-R0<`^!P)EX>4Tx04R}tkv&MmKpe$iQ$?v2hjtKg$WWc^q9Ts93Pq?8YK2xEOfLO`CJjl7 zi=*ILaPVWX>fqw6tAnc`2!4RLx;QDiNQwVT3N2zhIPS;0dyl(!fY7Wm&FV=2nr@q! zR8q|4SH-?pgb>C6L_}m}8FP}9hVS^gM}V()ah~OW?$0r(7Ayt?MB)T9Oq+OvcxKZ! zIPVijSy@(z&xt2Yx*+i**ARA; Z0RShU1_AL(O#}b{002ovPDHLkV1nst`33+0 literal 0 HcmV?d00001