Skip to content

Commit 0e374d1

Browse files
committed
Update 9by9.cc.lua
1 parent e88684a commit 0e374d1

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

9by9.cc.lua

+63-8
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function forward()
9191
while not turtle.forward() do
9292
while turtle.getFuelLevel() == 0 do
9393
turtle.select(fuel_slot)
94-
if not turtle.refuel(1) then
94+
if not refuel() then
9595
print("Need Fuel to move... Please add fuel to slot " .. fuel_slot )
9696
sleep(5)
9797
end
@@ -103,7 +103,7 @@ function forward()
103103
turtle.attack()
104104
sleep(forward_sleep_time)
105105
print("Blocked from going forward")
106-
end
106+
end
107107
end
108108
end
109109

@@ -152,7 +152,7 @@ end
152152
function checkSupplies(slot, quantity)
153153
if turtle.getItemSpace(slot) > 60 then
154154
--TODO: Don't steal from other named slots
155-
for i=1,16 do
155+
for i=5,16 do
156156
turtle.select(i)
157157
if turtle.compareTo(slot) then
158158
turtle.transferTo(slot)
@@ -214,6 +214,42 @@ function goUp(count)
214214
end
215215
end
216216

217+
218+
-- From Excavate2
219+
function refuel( ammount )
220+
local fuelLevel = turtle.getFuelLevel()
221+
if fuelLevel == "unlimited" then
222+
return true
223+
end
224+
225+
local needed = ammount
226+
if turtle.getFuelLevel() < needed then
227+
local fueled = false
228+
for n=1,16 do
229+
if turtle.getItemCount(n) > 0 then
230+
turtle.select(n)
231+
if turtle.refuel(1) then
232+
while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
233+
turtle.refuel(1)
234+
end
235+
if turtle.getFuelLevel() >= needed then
236+
turtle.select(1)
237+
return true
238+
end
239+
end
240+
end
241+
end
242+
turtle.select(1)
243+
return false
244+
end
245+
246+
return true
247+
end
248+
249+
250+
251+
252+
-- Actual main function
217253
if isRunning then
218254

219255
print("Place 4 stacks of wall building materials into slot " .. wall_slot .. " and others")
@@ -255,7 +291,10 @@ if isRunning then
255291
sleep(1)
256292
end
257293
end
258-
print("Starting")
294+
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
295+
print("Starting Floor Pass")
296+
297+
-- Begin Floor
259298
turtle.turnLeft()
260299
doFloor()
261300
doCorner(4,doWall)
@@ -293,10 +332,12 @@ if isRunning then
293332

294333
nextLoop()
295334

296-
297335
dig()
298336

299337
placeDown(floor_slot)
338+
-- end floor
339+
340+
300341

301342
goUp(1)
302343
turtle.select(torch_slot)
@@ -310,7 +351,11 @@ if isRunning then
310351
forward()
311352
turtle.turnLeft()
312353
turtle.turnLeft()
313-
354+
355+
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
356+
print("Starting Wall Pass")
357+
358+
-- begin Wall pass 1
314359
turtle.turnLeft()
315360
doAir()
316361
doCorner(4,doWall)
@@ -350,9 +395,14 @@ if isRunning then
350395

351396
nextLoop()
352397
dig()
398+
-- end wall pass 1
399+
353400

354401
goUp(3)
355-
402+
403+
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
404+
print("Starting Ceiling pass")
405+
-- Begin Ceiling
356406
turtle.turnLeft()
357407
doCeiling()
358408
turtle.turnRight()
@@ -397,7 +447,9 @@ if isRunning then
397447
doCorner(4,doCeiling)
398448
doCeiling()
399449
doCorner(4,doCeiling)
400-
450+
-- end ceiling
451+
452+
-- return to original position
401453
turtle.turnLeft()
402454
forward()
403455
turtle.turnRight()
@@ -410,4 +462,7 @@ if isRunning then
410462
turtle.down()
411463
turtle.down()
412464
turtle.forward()
465+
466+
print("Fuel Level: ["..turtle.getFuelLevel() .. "] ")
467+
413468
end

0 commit comments

Comments
 (0)