Advertisement
sanovskiy

Fill spiral

May 24th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 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. slotNum = 1
  14. turtle.select(slotNum)
  15.  
  16. print("Filling spiral in radius " .. maxRadius)
  17.  
  18. function immersiveRefuel()
  19.   print("Refuelling...")
  20.   while turtle.getFuelLevel()<10 do
  21.     turtle.refuel(1)
  22.   end
  23.   print("Done refuelling. Fuel level: "..turtle.getFuelLevel())
  24. end
  25.  
  26. function digAll(dir)
  27.   if dir=='up' then
  28.     while turtle.detectUp() do
  29.       turtle.digUp()
  30.       sleep(.3)
  31.     end
  32.   else
  33.     while turtle.detect() do
  34.       turtle.dig()
  35.       sleep(.3)
  36.     end
  37.   end
  38. end
  39.  
  40. function digForward(count)
  41.   for i=1,count,1 do
  42.     digAll()
  43.     while not(turtle.forward()) do
  44.       turtle.dig()
  45.       turtle.attack()
  46.       sleep(.3)
  47.     end
  48.     digAll('up')
  49.     place()
  50.     fuel=tonumber(turtle.getFuelLevel())
  51.     if fuel<10 then  
  52.       immersiveRefuel()
  53.     end
  54.   end
  55. end
  56.  
  57.  
  58. function place()
  59.   if not(turtle.detectDown()) then
  60.     checkSlot()
  61.     turtle.placeDown()
  62.   end
  63. end
  64.  
  65. function makeStep(radius)
  66.   -- entering ring
  67.   digForward(1)
  68.   turtle.turnRight()
  69.   -- dig first part
  70.   digForward(radius*2-1)
  71.   turtle.turnRight()
  72.   digForward(radius*2-1)
  73.   -- entering second part
  74.   digForward(1)
  75.   turtle.turnRight()
  76.   -- digging second part
  77.   digForward(radius*2)
  78.   turtle.turnRight()
  79.   digForward(radius*2)
  80. end
  81.  
  82. function checkSlot()
  83.   if turtle.getItemCount(slotNum)==0 then
  84.     while turtle.getItemCount(slotNum)==0 do
  85.       slotNum=slotNum+1
  86.       if slotNum==17 then
  87.         slotNum=1
  88.         turtle.select(slotNum)  
  89.         print("Add more material.")
  90.         while turtle.getItemCount(slotNum)==0 do
  91.           os.queueEvent("randomEvent")
  92.           os.pullEvent()      
  93.         end
  94.         print("Ok. Continue.")
  95.       else
  96.         turtle.select(slotNum)
  97.       end
  98.     end
  99.   end
  100. end
  101.  
  102. if 1<startRadius then
  103.   for i=2,startRadius,1 do
  104.     digForward(1)
  105.     turtle.turnLeft()
  106.     digForward(1)
  107.     turtle.turnRight()
  108.   end
  109. end
  110.  
  111. for step=startRadius,maxRadius,1 do
  112.   print('Filling ring # '..step..' out of '..maxRadius)
  113.   makeStep(step)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement