-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplant controller.lua
88 lines (81 loc) · 2.34 KB
/
plant controller.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--Infinite tree farm: plant controller
--
--License: GNU AGPL
--Copyright Ghaydn ([email protected]), 2021
--
--Download full code: github.com/Ghaydn/minetest-tree-farm
--
local deployer = "a"
local mulch = "d"
local chainsaw = "b"
local blink_interval = 0.2
if event.type == "program" then
mem.var = {
state = "off"
}
port[deployer] = false
port[mulch] = false
port[chainsaw] = false
digiline_send("lcd", "Tree machine ready")
end
if event.type == "digiline" then
if event.channel == "switch" then
if event.msg == "on" then
mem.var.state = "ready"
port[deployer] = false
port[mulch] = false
port[chainsaw] = false
digiline_send("lcd", "Turning on...")
digiline_send("command", "recall")
elseif event.msg == "off" then
mem.var.state = "off"
port[deployer] = false
port[mulch] = false
port[chainsaw] = false
digiline_send("lcd", "Tree machine OFF")
end
elseif event.channel == "detector" then
if mem.var.state ~= "off" then
if event.msg == "tree" then
mem.var.state = "chainsaw"
port[deployer] = false
port[mulch] = false
port[chainsaw] = true
digiline_send("lcd", "Found tree, using chainsaw")
interrupt(blink_interval, "chainsaw")
elseif event.msg == "sapling" then
mem.var.state = "mulch"
port[deployer] = false
port[mulch] = true
port[chainsaw] = false
digiline_send("lcd", "Found sapling, using mulch")
interrupt(blink_interval, "mulch")
elseif event.msg == "air" then
mem.var.state = "deployer"
port[deployer] = true
port[mulch] = false
port[chainsaw] = false
digiline_send("lcd", "Found nothing, placing sapling")
interrupt(blink_interval, "deployer")
end
end
end
end
if event.type == "interrupt" then
if event.iid == "chainsaw" then
if mem.var.state == "chainsaw" then
port[chainsaw] = not port[chainsaw]
interrupt(blink_interval, "chainsaw")
end
elseif event.iid == "mulch" then
if mem.var.state == "mulch" then
port[mulch] = not port[mulch]
interrupt(blink_interval, "mulch")
end
elseif event.iid == "deployer" then
if mem.var.state == "deployer" then
port[deployer] = not port[deployer]
interrupt(blink_interval, "deployer")
end
end
end