forked from Mirrorlandia_minetest/mesecons
Add digiline commands for operating node detector (#472)
This commit is contained in:
parent
8baa789eb1
commit
1a9704f184
@ -1,8 +1,11 @@
|
|||||||
The node detector is a receptor. It changes its state when either any node
|
The node detector is a receptor. It changes its state when either any node
|
||||||
or a specific node is detected. Right-click it to set a nodename to scan for.
|
or a specific node is detected. Right-click it to set a nodename to scan for.
|
||||||
It can also receive digiline signals. You can either send "GET" and it will
|
It can also receive digiline signals. For example, you can send
|
||||||
respond with the detected nodename or you can send any other string and it will
|
<code>{distance=4, scanname="default:dirt"}</code>
|
||||||
set this string as the node to scan for.
|
to set distance to 4 and scan for dirt. You can omit either parameter.
|
||||||
|
There is also a command parameter: <code>{command="get"}</code> will respond
|
||||||
|
with the detected nodename and <code>{command="scan"}</code> will respond with
|
||||||
|
a boolean using the distance and nodename of the detector.
|
||||||
Nodenames must include the mod they reside in, so for instance default:dirt, not just dirt.
|
Nodenames must include the mod they reside in, so for instance default:dirt, not just dirt.
|
||||||
The distance parameter specifies how many blocks are between the node detector and the node to detect.
|
The distance parameter specifies how many blocks are between the node detector and the node to detect.
|
||||||
Automatic scanning with Mesecons output only works when the detector is in an active block, but Digilines queries always work.
|
Automatic scanning with Mesecons output only works when the detector is in an active block, but Digilines queries always work.
|
||||||
|
@ -189,29 +189,50 @@ local function node_detector_scan(pos)
|
|||||||
(frontname ~= "air" and frontname ~= "ignore" and scanname == "")
|
(frontname ~= "air" and frontname ~= "ignore" and scanname == "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function node_detector_send_node_name(pos, node, channel, meta)
|
||||||
|
local distance = meta:get_int("distance")
|
||||||
|
local distance_max = mesecon.setting("node_detector_distance_max", 10)
|
||||||
|
if distance < 0 then distance = 0 end
|
||||||
|
if distance > distance_max then distance = distance_max end
|
||||||
|
local nodename = minetest.get_node(
|
||||||
|
vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
|
||||||
|
).name
|
||||||
|
|
||||||
|
digiline:receptor_send(pos, digiline.rules.default, channel, nodename)
|
||||||
|
end
|
||||||
|
|
||||||
-- set player name when receiving a digiline signal on a specific channel
|
-- set player name when receiving a digiline signal on a specific channel
|
||||||
local node_detector_digiline = {
|
local node_detector_digiline = {
|
||||||
effector = {
|
effector = {
|
||||||
action = function(pos, node, channel, msg)
|
action = function(pos, node, channel, msg)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
local distance = meta:get_int("distance")
|
|
||||||
local distance_max = mesecon.setting("node_detector_distance_max", 10)
|
|
||||||
if distance < 0 then distance = 0 end
|
|
||||||
if distance > distance_max then distance = distance_max end
|
|
||||||
|
|
||||||
if channel ~= meta:get_string("digiline_channel") then return end
|
if channel ~= meta:get_string("digiline_channel") then return end
|
||||||
|
|
||||||
|
if type(msg) == "table" then
|
||||||
|
if msg.distance or msg.scanname then
|
||||||
|
if msg.distance then
|
||||||
|
meta:set_string("distance", msg.distance)
|
||||||
|
end
|
||||||
|
if msg.scanname then
|
||||||
|
meta:set_string("scanname", msg.scanname)
|
||||||
|
end
|
||||||
|
node_detector_make_formspec(pos)
|
||||||
|
end
|
||||||
|
if msg.command == "get" then
|
||||||
|
node_detector_send_node_name(pos, node, channel, meta)
|
||||||
|
elseif msg.command == "scan" then
|
||||||
|
local result = node_detector_scan(pos)
|
||||||
|
digiline:receptor_send(pos, digiline.rules.default, channel, result)
|
||||||
|
end
|
||||||
|
else
|
||||||
if msg == GET_COMMAND then
|
if msg == GET_COMMAND then
|
||||||
local nodename = minetest.get_node(
|
node_detector_send_node_name(pos, node, channel, meta)
|
||||||
vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
|
|
||||||
).name
|
|
||||||
|
|
||||||
digiline:receptor_send(pos, digiline.rules.default, channel, nodename)
|
|
||||||
else
|
else
|
||||||
meta:set_string("scanname", msg)
|
meta:set_string("scanname", msg)
|
||||||
node_detector_make_formspec(pos)
|
node_detector_make_formspec(pos)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
receptor = {}
|
receptor = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user