Skip to content

Commit

Permalink
node allow-list
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 13, 2023
1 parent a1b7dbe commit dd0602a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 39 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# mtui_mod

# License

* Code: `MIT`
* Textures: `CC-BY-SA 3.0`
57 changes: 52 additions & 5 deletions handlers/mesecons.lua
Original file line number Diff line number Diff line change
@@ -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"])
Expand Down Expand Up @@ -65,31 +69,74 @@ 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({
type = "mesecons_event",
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({
type = "mesecons_event",
data = {
pos = pos,
state = "on",
nodename = "mesecons_lightstone:lightstone_" .. color .. "_on"
nodename = on_nodename
}
})
return old_action_on(pos, node)
end
end
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
})
1 change: 0 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 0 additions & 33 deletions register_wand.lua

This file was deleted.

Binary file added textures/mtui_register_mesecons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed textures/mtui_register_wand.png
Binary file not shown.

0 comments on commit dd0602a

Please sign in to comment.