-
Notifications
You must be signed in to change notification settings - Fork 3
/
9by9dignext.cc.lua
346 lines (313 loc) · 7.07 KB
/
9by9dignext.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
--
-- 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)
while turtle.digUp() do end
while turtle.dig() do end
while turtle.digDown() do end
while turtle.detectUp() or turtle.detect() do
turtle.digUp()
turtle.dig()
sleep(gravel_fall_time)
end
end
function forward()
while not turtle.forward() do
turtle.select(junk_slot)
while turtle.dig() do end
while turtle.getFuelLevel() == 0 do
turtle.select(fuel_slot)
if turtle.getItemCount() == 0 or not turtle.refuel(1) 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=1,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 turtle.digUp() do end
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
function goDown(count)
for i=1,count do
while not turtle.down() do
turtle.digDown()
if turtle.getFuelLevel() == 0 then
turtle.select(fuel_slot)
if turtle.getItemCount() == 0 or not turtle.refuel(1) then
print("Need Fuel to move... Please add fuel to slot " .. fuel_slot )
sleep(5)
end
end
print("Turtle Movement blocked going down")
end
end
end
function doArea2(size,center,corner, next)
turtle.turnLeft()
center()
turtle.turnRight()
for i=1,size do
print(i)
for j=1,4 do
center()
doCorner(i,corner)
end
if i < size then
next()
end
end
end
function doArea(size,center,corner, next)
for i=1,size do
print(i)
for j=1,4 do
center()
if size-i == 0 then
return
end
doCorner(size-i,corner)
end
next()
end
end
function digRoomInsideOut()
goUp(1)
for i=1,4 do
forward()
end
turtle.turnLeft()
doArea2(3,doAir,doAir,nextLoopTop)
turtle.turnRight()
for i=1,3 do
forward()
end
goUp(2)
turtle.turnLeft()
doArea2(3,doAir,doAir,nextLoopTop)
goDown(3)
turtle.turnLeft()
forward()
turtle.turnLeft()
turtle.turnLeft()
end
function digRoom()
goUp(1)
forward()
turtle.turnLeft()
turtle.turnLeft()
forward()
turtle.turnRight()
doArea(4,doAir,doAir,nextLoop)
turtle.back()
goUp(2)
turtle.turnLeft()
for i=1,3 do
forward()
end
turtle.turnLeft()
turtle.turnLeft()
print("NextFloor")
turtle.turnLeft()
doArea(4,doAir,doAir,nextLoop)
turtle.back()
turtle.turnLeft()
goDown(3)
for i=1,4 do
forward()
end
turtle.turnLeft()
turtle.turnLeft()
turtle.back()
end
function digNext()
goUp(1)
dig()
forward()
dig()
forward()
dig()
forward()
dig()
goDown(1)
end
if isRunning then
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("Starting")
digNext()
end