Skip to content

Commit

Permalink
wand
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 12, 2023
1 parent dbb938b commit 808eeed
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
19 changes: 5 additions & 14 deletions handlers/mesecons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,7 +81,6 @@ for _, color in ipairs(lightstone_colors) do
data = {
pos = pos,
state = "on",
color = color,
nodename = node.name
}
})
Expand All @@ -105,7 +97,6 @@ for _, color in ipairs(lightstone_colors) do
data = {
pos = pos,
state = "off",
color = color,
nodename = node.name
}
})
Expand Down
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
29 changes: 29 additions & 0 deletions register_wand.lua
Original file line number Diff line number Diff line change
@@ -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
})
Binary file added textures/mtui_register_wand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 808eeed

Please sign in to comment.