-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkelp2.lua
246 lines (222 loc) · 4.26 KB
/
kelp2.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
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
--[[
Created by: Just1689
]]--
local INVENTORY_SIZE = 16
local xLen = 13
local yLen = 11
local REFUEL_MIN = 800
if #arg == 2 then
xLen = tonumber(arg[1])
yLen = tonumber(arg[2])
end
print("Using x,y:" .. xLen .. ", " .. yLen)
local ACCEPTED_FUELS = {
"minecraft:coal_block",
"minecraft:coal",
"minecraft:dried_kelp_block",
"minecraft:charcoal"
}
function turnAround()
turtle.turnLeft()
turtle.turnLeft()
end
function marchForward()
ok, err = turtle.forward()
if not ok then
turtle.dig()
marchForward()
end
end
function suckForward()
turtle.suck()
turtle.suckUp()
turtle.suckDown()
ok, err = turtle.forward()
if not ok then
turtle.dig()
suckForward()
end
end
function isEvenRow()
if yLen % 2 == 1 then
return false
end
return true
end
function inventorySort()
for j = 1, INVENTORY_SIZE do
local currentItem = turtle.getItemDetail(j)
if currentItem ~= nil then
turtle.select(j)
for k = j, INVENTORY_SIZE do
if turtle.compareTo(k) then
turtle.select(k)
turtle.transferTo(j)
turtle.select(j)
end
end
end
end
end
-- Dump inventory
function dumpInventory()
for i = 1, INVENTORY_SIZE do
local currentItem = turtle.getItemDetail(i)
if currentItem ~= nil then
turtle.select(i)
if turtle.dropDown() == false then
print("Error: no room in left ")
return
end
end
end
inventorySort()
turtle.select(1)
end
--[[
APPLICATION STARS HERE
]] --
-- Better fuel check
turtle.refuel()
if turtle.getFuelLevel() < REFUEL_MIN then
print("Error: Not enough fuel. Need at least ".. REFUEL_MIN)
return
end
-- Enter maze
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.down()
turtle.down()
turtle.down()
turtle.forward()
turtle.forward()
turtle.up()
turtle.up()
turtle.up()
turtle.up()
turtle.up()
turtle.up()
turtle.back()
turtle.turnRight()
for j = 1, 25 do
marchForward()
end
turtle.turnLeft()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
local toggleDir = true
local xOffSet = 0
-- Chop down grid
for y = 1, yLen do
for x = 1, xLen - xOffSet do
marchForward()
end
if toggleDir then
turtle.turnLeft()
marchForward()
turtle.turnLeft()
else
turtle.turnRight()
marchForward()
turtle.turnRight()
end
xOffSet = 1
toggleDir = not toggleDir
end
-- move back to first tile of maze
if not isEvenRow() then
for x = 1, xLen - xOffSet do
marchForward()
end
turtle.turnLeft()
for y = 1, yLen do
marchForward()
end
else
turtle.turnRight()
for y = 1, yLen do
marchForward()
end
end
-- move the extra off the map
local extra = 3
for n = 1, extra do
marchForward()
end
turtle.turnRight()
for n = 1, extra do
marchForward()
end
--move up to the right level
local moreHeight = 13
for n = 1, moreHeight do
turtle.up()
end
turnAround()
-- Collect
xOffSet = 0
toggleDir = true
for y = 1, yLen + (2 * extra) do
for x = 1, xLen - xOffSet + (2 * extra) do
suckForward()
end
if toggleDir then
turtle.turnLeft()
suckForward()
turtle.turnLeft()
else
turtle.turnRight()
suckForward()
turtle.turnRight()
end
xOffSet = 1
toggleDir = not toggleDir
end
-- move back to first tile of maze FROM the extra location
if not isEvenRow() then
for x = 1, xLen + extra do
marchForward()
end
turtle.turnLeft()
for y = 1, yLen + extra - 1 do
marchForward()
end
else
turtle.turnRight()
for y = 1, yLen + extra do
marchForward()
end
end
for n = 1, moreHeight do
turtle.down()
end
-- return to base
turtle.up()
turtle.up()
turnAround()
for i = 1, 24 do
marchForward()
end
turtle.turnLeft()
for i = 1, 10 do
turtle.down()
end
turtle.forward()
turtle.forward()
turtle.up()
turtle.up()
turtle.up()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turnAround()
dumpInventory()