-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanter.lua
More file actions
78 lines (69 loc) · 1.42 KB
/
planter.lua
File metadata and controls
78 lines (69 loc) · 1.42 KB
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
local settings = {
signalSide = "bottom",
chopColor = colors.red,
chargeColor = colors.green,
cyclePause = 1
}
local inFront = {
nothing = 0,
sapling = 1,
wood = 2,
unknown = 3
}
function mainLoop()
print("Planter started.")
init()
while true do
i = whatIsInFront()
if i == inFront.nothing then
print("Nothing in front, charging then planting...")
charge()
plant()
elseif i == inFront.sapling then
print("Sapling in front, waiting...")
elseif i == inFront.wood then
print("Log in front, chopping...")
chop()
else
print("Something unexpected in front of the turtle. Waiting...")
end
print("Waiting 3 seconds...")
os.sleep(3)
end
end
function init()
redstone.setOutput(settings.signalSide, false)
redstone.setBundledOutput(settings.signalSide, 0)
end
function whatIsInFront()
local foundSomething, data = turtle.inspect()
if foundSomething then
if data.name == "minecraft:log" then
return inFront.wood
elseif data.name == "minecraft:sapling" then
return inFront.sapling
else
return inFront.unknown
end
else
return inFront.nothing
end
end
function plant()
turtle.place()
end
function charge()
print("Charging axe.")
init()
redstone.setBundledOutput(settings.signalSide, settings.chargeColor)
os.sleep(1)
init()
end
function chop()
print("Chopping...")
init()
redstone.setBundledOutput(settings.signalSide, settings.chopColor)
os.sleep(1)
init()
end
mainLoop()