-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrown.lua
More file actions
249 lines (224 loc) · 4.65 KB
/
drown.lua
File metadata and controls
249 lines (224 loc) · 4.65 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
p = peripheral.wrap("left")
water = 9
fullLevel = 9001
emptyLevel = 999
fullBucket = 1
wait = 1
pause = .1
length = 25
local function turn(side)
if side == "left" then
turtle.turnLeft()
elseif side == "right" then
turtle.turnRight()
elseif side == "back" then
turtle.turnRight()
turtle.turnRight()
else
print("Turn direction not recognized!")
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
end
end
function level()
local liquidType, liquidAmount = p.getLiquid()
return liquidAmount
end
function fillTank()
print("Filling tank...")
while (level() < fullLevel) do
sleep(pause)
p.suckDown()
end
print("Tank filled.")
end
function fillBucket(s)
print("Filling bucket in slot #" .. s .. "...")
turtle.select(s)
while not turtle.compareTo(fullBucket) do
sleep(pause)
if(level() > emptyLevel) then
p.pack()
print("Bucket filled.")
else
print("Not enough water in tank, refilling tank...")
fillTank()
end
end
print("Bucket filled.")
end
function fillBuckets()
print("Filling all buckets...")
for i = 2, 16, 1 do
sleep(pause)
print("Bucket in slot #" .. i .. "...")
turtle.select(i)
if turtle.compareTo(fullBucket) then
print("Bucket is full.")
else
print("Bucket is empty, filling...")
fillBucket(i)
end
end
print("All buckets filled.")
end
function fillAll()
print("Filling tank and buckets...")
fillBuckets()
fillTank()
print("Everything filled.")
end
function refillTankFromBuckets(n)
print("Refilling...")
for i = 0, n, 1 do
sleep(pause)
print("Refill #" .. i .. ":")
if(level() < fullLevel) then
print("Tank not full, continuing...")
for ii = 2, 16, 1 do
sleep(pause)
print("Attempting to fill from slot #" .. ii .. "...")
turtle.select(fullBucket)
if turtle.compareTo(ii) then
print("Slot #" .. ii .. " has a full bucket.")
turtle.select(ii)
p.unpack()
print("Filled from slot #" .. ii .. ", done with refill #" .. i .. ".")
break
else
print("Slot #" .. ii .. " does not have a full bucket.")
end
end
else
print("Tank is full. Cannot continue filling.")
break
end
print("Done with refill #" .. i .. ".")
end
print("Done refilling.")
end
function drainTankToBuckets(n)
print("Draining...")
for i = 0, n, 1 do
sleep(pause)
print("Drain #" .. i .. ":")
if(level() > emptyLevel) then
print("Tank not empty, continuing...")
for ii = 2, 16, 1 do
sleep(pause)
print("Attempting to drain to slot #" .. ii .. "...")
turtle.select(fullBucket)
if not turtle.compareTo(ii) then
print("Slot #" .. ii .. " has an empty bucket.")
turtle.select(ii)
p.pack()
print("Drained to slot #" .. ii .. ", done with drain #" .. i .. ".")
break
else
print("Slot #" .. ii .. " does not have an empty bucket.")
end
end
else
print("Tank is empty. Cannot continue draining.")
break
end
print("Done with drain #" .. i .. ".")
end
print("Done draining.")
end
function dump()
print("Dumping...")
if(level() <= emptyLevel) then
print("Not enough in tank, refilling...")
refillTankFromBuckets(1)
end
local dumped = p.dropDown()
-- Returns nil for some reason
--print("Dumped " .. dumped .. "mB.")
end
function pick()
print("Picking...")
if(level() >= fullLevel) then
print("Too much in tank, draining...")
drainTankToBuckets(1)
end
picked = p.suckDown()
print("Picked " .. picked .. "mB.")
end
function park()
print("Parking...")
turtle.forward()
turtle.forward()
turn("back")
end
function unpark()
print("Unparking...")
turtle.forward()
turtle.forward()
end
function drown()
print("Drowning...")
fillAll()
unpark()
for i = 1, length, 1 do
sleep(pause)
print("Spot #" .. i .. "...")
dump()
if i < length then
print("Continuing...")
turtle.forward()
end
end
print("Turning around...")
turn("back")
print("Returning...")
for i = length, 1, -1 do
sleep(pause)
if i > 1 then
turtle.forward()
end
end
park()
fillAll()
end
function clear()
print("Clearing...")
unpark()
turtle.down()
for i = 1, length, 1 do
sleep(pause)
if i < length then
turtle.forward()
end
end
turtle.up()
print("Turning around...")
turn("back")
print("Returning...")
for i = length, 1, -1 do
sleep(pause)
if i > 1 then
turtle.forward()
end
end
park()
end
while true do
if redstone.getInput("back") then
print("Signal detected, drowning...")
drown()
print("Drown complete.")
while redstone.getInput("back") do
sleep(pause)
print("Signal detected.")
sleep(wait)
end
print("Signal no longer detected, clearing...")
clear()
else
print("Signal not detected.")
end
sleep(wait)
end