Advertisement
sanovskiy

clearspiral

Jul 23rd, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. aArgs = {...}
  2. local maxRadius = tonumber(aArgs[1])
  3. local startRadius = tonumber(aArgs[2])
  4.  
  5. if not(startRadius) then
  6.   startRadius = 1
  7. end
  8. if not(maxRadius) or startRadius>maxRadius then
  9.   print('Usage: '..shell.getRunningProgram()..' <maxRadius> [startRadius]')
  10.   error()
  11. end
  12.  
  13. print("Clearing spiral in radius " .. maxRadius)
  14.  
  15. function immersiveRefuel()
  16.   print("Refuelling...")
  17.   while turtle.getFuelLevel()<10 do
  18.     turtle.refuel(1)
  19.   end
  20.   print("Done refuelling. Fuel level: "..turtle.getFuelLevel())
  21. end
  22.  
  23. function digAll(dir)
  24.   if dir=='down' then
  25.     while turtle.detectDown() do
  26.       turtle.digDown()
  27.       sleep(.3)
  28.     end
  29.   elseif dir=='up' then
  30.     while turtle.detectUp() do
  31.       turtle.digUp()
  32.       sleep(.3)
  33.     end
  34.   else
  35.     while turtle.detect() do
  36.       turtle.dig()
  37.       sleep(.3)
  38.     end
  39.   end
  40. end
  41.  
  42. function digForward(count)
  43.   for i=1,count,1 do
  44.     digAll()
  45.     while not(turtle.forward()) do
  46.       turtle.dig()
  47.       turtle.attack()
  48.       sleep(.3)
  49.     end
  50.     digAll('up')
  51.     digAll('down')
  52.     fuel=tonumber(turtle.getFuelLevel())
  53.     if fuel<10 then  
  54.       immersiveRefuel()
  55.     end
  56.   end
  57. end
  58.  
  59. function makeStep(radius)
  60.   -- entering ring
  61.   digForward(1)
  62.   turtle.turnRight()
  63.   -- dig first part
  64.   digForward(radius*2-1)
  65.   turtle.turnRight()
  66.   digForward(radius*2-1)
  67.   -- entering second part
  68.   digForward(1)
  69.   turtle.turnRight()
  70.   -- digging second part
  71.   digForward(radius*2)
  72.   turtle.turnRight()
  73.   digForward(radius*2)
  74. end
  75.  
  76. if 1<startRadius then
  77.   for i=2,startRadius,1 do
  78.     digForward(1)
  79.     turtle.turnLeft()
  80.     digForward(1)
  81.     turtle.turnRight()
  82.   end
  83. end
  84.  
  85. for step=startRadius,maxRadius,1 do
  86.   print('Clearing ring # '..step..' out of '..maxRadius)
  87.   makeStep(step)
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement