-
Notifications
You must be signed in to change notification settings - Fork 3
/
9by9.cc.lua
468 lines (402 loc) · 9.68 KB
/
9by9.cc.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
--
-- This script will create a Direwolf20 classic 9x9 room
--
-- If the turtle is a mining turtle it can clear the area as well
-- if not it will just place the walls,floor and ceiling as needed
-- but will get stuck if there are obsticles.
--
-- It will prompt you for what to place in which slots
--
-- Version 1.0
-- Author: yazug ([email protected])
--
-- http://turtlescripts.com/project/gjdhcs-9by9
--
local tArgs = {...}
local wall_slot = 1
local floor_slot = 2
local ceiling_slot = 1
local skylight_slot = 3
local torch_slot = 4
local fuel_slot = 16
local junk_slot = 1
local forward_sleep_time = 4
local gravel_fall_time = 0.7
local isRunning=true
if tArgs[1] == "update" then
local sCode, sFile, sPin = "gjdhjd", "9by9", ""
local sPath = shell.resolve( sFile )
write( "Connecting to TurtleScripts.com... " )
local response = http.post("http://api.turtlescripts.com/getFileRaw/"..textutils.urlEncode( sCode ),"pin="..sPin)
if response then
local sResponse = response.readAll()
response.close()
local file = fs.open( sPath, "w" )
file.write( sResponse )
file.close()
print( " " )
print( "Remote: #"..sCode )
print( "Local: "..sFile )
print( "[===========================] 100%" )
print(string.len(sResponse).." bytes")
print( " " )
print( "Update Complete." )
print( " " )
else
print( "Failed to update." )
print( " " )
end
isRunning = false
end
function printUsage()
print(" Usage: ")
print(" 9by9 ")
print(" 9by9 help ")
print(" 9by9 update ")
print(" ")
end
function doCorner(count, action)
for i=1,count-1 do
action()
end
turtle.turnRight()
for i=1,count do
action()
end
end
function dig()
turtle.select(junk_slot)
turtle.digUp()
turtle.dig()
turtle.digDown()
sleep(gravel_fall_time)
while turtle.detectUp() do
turtle.digUp()
sleep(gravel_fall_time)
end
while turtle.detect() do
turtle.dig()
sleep(gravel_fall_time)
end
end
function forward()
while not turtle.forward() do
while turtle.getFuelLevel() == 0 do
turtle.select(fuel_slot)
if not refuel() then
print("Need Fuel to move... Please add fuel to slot " .. fuel_slot )
sleep(5)
end
end
turtle.select(junk_slot)
turtle.dig()
while turtle.detect() do
turtle.dig()
turtle.attack()
sleep(forward_sleep_time)
print("Blocked from going forward")
end
end
end
function doFloor()
dig()
placeDown(floor_slot)
forward()
end
function doWall()
dig()
placeWall(wall_slot)
end
function doCeiling()
dig()
placeDown(ceiling_slot)
forward()
end
function doSkylight()
dig()
placeDown(skylight_slot)
forward()
end
function doAir()
dig()
forward()
end
function placeWall(slot)
checkSupplies(slot,3)
turtle.select(slot)
turtle.placeDown()
turtle.placeUp()
forward()
turtle.select(slot)
turtle.turnRight()
turtle.turnRight()
turtle.place()
turtle.turnRight()
turtle.turnRight()
end
function checkSupplies(slot, quantity)
if turtle.getItemSpace(slot) > 60 then
--TODO: Don't steal from other named slots
for i=5,16 do
turtle.select(i)
if turtle.compareTo(slot) then
turtle.transferTo(slot)
end
if turtle.getItemSpace(slot) < 32 then
break
end
end
end
while turtle.getItemCount(slot) < quantity do
print("Need Items in " .. slot .. " quantity " .. quantity - turtle.getItemCount(slot))
sleep(10)
end
end
function placeDown(slot)
checkSupplies(slot,1)
turtle.select(slot)
turtle.placeDown()
end
function placeUp(slot)
checkSupplies(slot,1)
turtle.select(slot)
turtle.placeUp()
end
function place(slot)
checkSupplies(slot,1)
turtle.select(slot)
turtle.place()
end
function nextLoop()
turtle.turnRight()
forward()
turtle.turnLeft()
end
function nextLoopTop()
turtle.turnLeft()
forward()
turtle.turnRight()
end
function goUp(count)
for i=1,count do
while not turtle.up() do
turtle.digUp()
sleep(gravel_fall_time)
if turtle.getFuelLevel() == 0 then
turtle.select(fuel_slot)
if not turtle.refuel(1) then
print("Need Fuel to move... Please add fuel to slot " .. fuel_slot )
sleep(5)
end
print("Turtle Movement blocked going up")
end
end
end
end
-- From Excavate2
function refuel( ammount )
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" then
return true
end
local needed = ammount
if turtle.getFuelLevel() < needed then
local fueled = false
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
turtle.refuel(1)
end
if turtle.getFuelLevel() >= needed then
turtle.select(1)
return true
end
end
end
end
turtle.select(1)
return false
end
return true
end
-- Actual main function
if isRunning then
print("Place 4 stacks of wall building materials into slot " .. wall_slot .. " and others")
turtle.select(wall_slot)
-- TODO: Actually count how many other blocks of same type are in inventory
while turtle.getItemCount(wall_slot) < 64 do
print("Waiting for more items for the wall")
sleep(2)
end
print("Place 1 stack of Flooring materials into slot " .. floor_slot)
turtle.select(floor_slot)
while turtle.getItemCount(floor_slot) < 50 do
print("Waiting for more items for the floor")
sleep(2)
end
print("Place Skylight material into slot " .. skylight_slot)
turtle.select(skylight_slot)
while turtle.getItemCount(skylight_slot) < 16 do
print("Waiting for more items for the skylights")
sleep(2)
end
print("Place torches into slot " .. torch_slot)
turtle.select(torch_slot)
while turtle.getItemCount(torch_slot) < 4 do
print("Waiting for more torches")
sleep(2)
end
print("Place fuel into slot " .. fuel_slot)
turtle.select(fuel_slot)
while turtle.getFuelLevel() < 200 do
while turtle.getItemCount(fuel_slot) < 1 do
print("Waiting for more fuel. have ["..turtle.getFuelLevel() .. "] of 200")
sleep(2)
end
if not turtle.refuel(1) then
print("Item in fuel slot is not burnable!")
sleep(1)
end
end
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
print("Starting Floor Pass")
-- Begin Floor
turtle.turnLeft()
doFloor()
doCorner(4,doWall)
doWall()
doCorner(4,doWall)
doWall()
doCorner(4,doWall)
doWall()
doCorner(4,doWall)
nextLoop()
doFloor()
doCorner(3,doFloor)
doFloor()
doCorner(3,doFloor)
doFloor()
doCorner(3,doFloor)
doFloor()
doCorner(3,doFloor)
nextLoop()
doCorner(3,doFloor)
doCorner(2,doFloor)
doCorner(3,doFloor)
doCorner(2,doFloor)
nextLoop()
doCorner(2,doFloor)
doCorner(1,doFloor)
doCorner(2,doFloor)
doCorner(1,doFloor)
nextLoop()
dig()
placeDown(floor_slot)
-- end floor
goUp(1)
turtle.select(torch_slot)
turtle.placeDown()
goUp(2)
turtle.turnLeft()
forward()
forward()
forward()
forward()
turtle.turnLeft()
turtle.turnLeft()
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
print("Starting Wall Pass")
-- begin Wall pass 1
turtle.turnLeft()
doAir()
doCorner(4,doWall)
doWall()
doCorner(4,doWall)
doWall()
doCorner(4,doWall)
doWall()
doCorner(4,doWall)
turtle.turnRight()
doWall()
turtle.turnLeft()
doAir()
doCorner(3,doAir)
doAir()
doCorner(3,doAir)
doAir()
doCorner(3,doAir)
doAir()
doCorner(3,doAir)
nextLoop()
doCorner(3,doAir)
doCorner(2,doAir)
doCorner(3,doAir)
doCorner(2,doAir)
nextLoop()
doCorner(2,doAir)
doCorner(1,doAir)
doCorner(2,doAir)
doCorner(1,doAir)
nextLoop()
dig()
-- end wall pass 1
goUp(3)
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
print("Starting Ceiling pass")
-- Begin Ceiling
turtle.turnLeft()
doCeiling()
turtle.turnRight()
doCeiling()
doCorner(1,doSkylight)
doCeiling()
doCorner(1,doSkylight)
doCeiling()
doCorner(1,doSkylight)
doCeiling()
doCorner(1,doSkylight)
nextLoopTop()
doCeiling()
doCorner(2,doSkylight)
doCeiling()
doCorner(2,doSkylight)
doCeiling()
doCorner(2,doSkylight)
doCeiling()
doCorner(2,doSkylight)
nextLoopTop()
doCeiling()
doCorner(3,doCeiling)
doCeiling()
doCorner(3,doCeiling)
doCeiling()
doCorner(3,doCeiling)
doCeiling()
doCorner(3,doCeiling)
nextLoopTop()
doCeiling()
doCorner(4,doCeiling)
doCeiling()
doCorner(4,doCeiling)
doCeiling()
doCorner(4,doCeiling)
doCeiling()
doCorner(4,doCeiling)
-- end ceiling
-- return to original position
turtle.turnLeft()
forward()
turtle.turnRight()
turtle.turnRight()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.forward()
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
end