-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanabeans
executable file
·197 lines (176 loc) · 4.21 KB
/
manabeans
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
----- Turtle which can plant and harvest mana beans into tall tower of 4 wood columns
-- Syntax: manabeans cycleCount dump/resupply turnDirection(left,right,around,none) [continousDrop]
local columnHeight = 100
local currentSlot = 1
local currentDirection = "up"
local cycleCount = 1
local stockHandle = nil
local turnDirection = "right"
local dropMode = nil
function loopSlot()
local nextSlot = nil
if currentSlot<16 then
nextSlot = currentSlot+1
else
nextSlot = 1
end
selectSlot(nextSlot)
end
function place()
local limit=16
while turtle.getItemCount(currentSlot) == 0 and limit>0 do
loopSlot()
limit = limit - 1
end
if limit == 0 then
print("Place limit reached - inventory empty")
end
print ("Items in current slot: ", turtle.getItemCount(currentSlot))
print ("Current slot: ", currentSlot)
return turtle.place()
end
function dig()
if turnDirection == "none" and currentDirection == "down" then
--do nothing
else
turtle.dig()
end
end
function turtleUp()
local limit = 5
for i = 1,5 do
if turtle.up() then
return true
else
sleep(0.3)
end
end
return false
end
function turtleDown()
local limit = 5
for i = 1,5 do
if turtle.down() then
return true
else
sleep(0.3)
end
end
return false
end
function move()
if currentDirection == "up" then
return turtleUp()
elseif currentDirection == "down" then
return turtleDown()
else
print("Unknown direction: ", currentDirection)
exit()
end
end
function revertDirection()
if currentDirection == "up" then
currentDirection = "down"
elseif currentDirection == "down" then
currentDirection = "up"
else
print("Unknown current direction: ", currentDirection)
exit()
end
end
function selectSlot(slotNumber)
turtle.select(slotNumber)
currentSlot = slotNumber
end
function oneDirection()
selectSlot(1)
local movesInOneDir = 0
while movesInOneDir < columnHeight do
dig()
if not place() and currentDirection == "up" then
print("Cannot place, breaking")
break
end
if not move() then
print("Can't go current direction, reverting")
break
end
movesInOneDir = movesInOneDir + 1
if dropMode == "continousDrop" then
selectSlot(2)
turtle.dropDown()
selectSlot(1)
turtle.dropDown()
end
end
end
function turn()
if turnDirection == "right" then
turtle.turnRight()
elseif turnDirection == "left" then
turtle.turnLeft()
elseif turnDirection == "around" then
turtle.turnLeft()
turtle.turnLeft()
elseif turnDirection == "none" then
print("Turn direction = 'none', not turning")
else
print("Incorrect turn direction, turning right")
turtle.turnRight()
end
end
function goUpAndDown()
if turtle.getFuelLevel() < 300 then
print("Error - low on fuel ", turtle.getFuelLevel())
exit()
end
resupplyBeans()
oneDirection()
revertDirection()
turn()
oneDirection()
revertDirection()
turn()
end
function resupplyBeans()
-- refilling from filing cabinet below us
for i=1,16 do
selectSlot(i)
if stockHandle == "resupply" then
turtle.suckDown()
elseif stockHandle == "dump" then
-- we expect vacuum hopper to grab mana beans we drop
turtle.drop()
--turtle.dropDown()
elseif not stockHandle then
-- doing nothing
else
print("Wrong resupply command")
exit()
end
end
end
local args = {...}
if args[1] and tonumber(args[1]) then
cycleCount = tonumber(args[1])
end
if args[2] == "resupply" then
stockHandle = "resupply"
elseif args[2] == "dump" then
stockHandle = "dump"
else
print("No resupply command")
end
if args[3] == "left" or args[3] == "right" or args[3] == "around" or args[3] == "none" then
turnDirection = args[3]
else
print("Using default turn direction")
end
if args[4] == "continousDrop" then
dropMode = args[4]
else
print("No special drop mode")
end
for cycle = 1,cycleCount do
goUpAndDown()
end