-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigiline.lua
68 lines (58 loc) · 2.01 KB
/
digiline.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local function msg_to_table(str)
if str == "get" or str == "GET" then
return {command = "get"}
elseif str == "activate" or str == "enable" or str == "on" then
return {command = "set", active = true}
elseif str == "deactivate" or str == "disable" or str == "off" then
return {command = "set", active = false}
elseif mcl_beacon.effects[str] or str == "none" then
return {command = "set", effect = str}
elseif tonumber(str) then
return {command = "set", range = tonumber(str)}
end
return {}
end
function mcl_beacon.digiline_effector(pos, _, channel, msg)
local meta = minetest.get_meta(pos)
local set_channel = meta:get_string("channel")
if channel ~= set_channel then
return
end
if type(msg) ~= "table" then
if type(msg) == "string" then
msg = msg_to_table(msg)
else
return
end
end
if msg.command == "get" then
digilines.receptor_send(pos, digilines.rules.default, set_channel, {
radius = meta:get_int("range"),
effect = meta:get_string("effect"),
active = meta:get_string("active") == "true" and true or false,
})
elseif msg.command == "get_effects" then
digilines.receptor_send(pos, digilines.rules.default, set_channel, mcl_beacon.sorted_effect_ids)
elseif msg.command == "set" then
local level = mcl_beacon.get_level(pos)
if type(msg.effect) == "string" then
if mcl_beacon.effects[msg.effect] and mcl_beacon.effects[msg.effect].min_level <= level then
meta:set_string("effect", msg.effect)
elseif msg.effect == "none" then
meta:set_string("effect", "none")
end
end
if type(msg.range) == "number" then
meta:set_int("range", mcl_beacon.limit_range(msg.range, level))
elseif type(msg.radius) == "number" then
meta:set_int("range", mcl_beacon.limit_range(msg.radius, level))
end
if type(msg.active) == "boolean" then
if msg.active and meta:get_string("active") == "false" then
mcl_beacon.activate(pos, meta:get_string("owner"))
elseif not msg.active and meta:get_string("active") == "true" then
mcl_beacon.deactivate(pos)
end
end
end
end