Skip to content

Commit

Permalink
node_detector now accepts a comma-seperated list of nodes like object…
Browse files Browse the repository at this point in the history
…_detector
  • Loading branch information
lolbinarycat authored Jan 13, 2024
1 parent 7418d5c commit 50a4bd6
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mesecons_detector/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ local side_texture = mesecon.texture.steel_block or "mesecons_detector_side.png"

local GET_COMMAND = "GET"


local function comma_list_to_table(comma_list)
local tbl = {}
for _, str in ipairs(string.split(comma_list:gsub("%s", ""), ",")) do
tbl[str] = true
end
return tbl
end


-- Object detector
-- Detects players in a certain radius
-- The radius can be specified in mesecons/settings.lua
Expand Down Expand Up @@ -35,10 +45,7 @@ local function object_detector_scan(pos)
if next(objs) == nil then return false end

local scanname = minetest.get_meta(pos):get_string("scanname")
local scan_for = {}
for _, str in pairs(string.split(scanname:gsub(" ", ""), ",")) do
scan_for[str] = true
end
local scan_for = comma_list_to_table(scanname)

local every_player = scanname == ""
for _, obj in pairs(objs) do
Expand Down Expand Up @@ -188,8 +195,9 @@ local function node_detector_scan(pos)
vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
).name
local scanname = meta:get_string("scanname")
local scan_for = comma_list_to_table(scanname)

return (frontname == scanname) or
return (scan_for[frontname]) or
(frontname ~= "air" and frontname ~= "ignore" and scanname == "")
end

Expand Down

0 comments on commit 50a4bd6

Please sign in to comment.