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 0000000..a2f8508 Binary files /dev/null and b/textures/mtui_register_wand.png differ