HAJ523

Wall

Jul 10th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.66 KB | None | 0 0
  1. --get Arguements
  2. local tArgs = { ... }
  3.  
  4. --Validate Arguements
  5. if (#tArgs < 1) then
  6.         print("Invalid # of Arguements")
  7.         return
  8. end
  9.  
  10. local evenodd = tonumber(tArgs[1])
  11.  
  12. if (evenodd ~= 0) and (evenodd ~= 1) then
  13.         print("Even/Odd should = 0 or 1")
  14.         return
  15. end
  16.  
  17. local function refuel(slot)
  18.         local fuelLevel = turtle.getFuelLevel()
  19.         if fuelLevel == "unlimited" or fuelLevel > 0 then
  20.                 return
  21.         end
  22.        
  23.         local function tryRefuel()
  24.                 if turtle.getItemCount(1) > 0 then
  25.                         turtle.select(1)
  26.                         if turtle.refuel(1) then
  27.                                 return true
  28.                         end
  29.                 end
  30.                 return false
  31.         end
  32.        
  33.         if not tryRefuel() then
  34.                 print( "Add more fuel to continue." )
  35.                 while not tryRefuel() do
  36.                         sleep(5)
  37.                 end
  38.                 print( "Resuming..." )
  39.                 turtle.select(slot)
  40.         end
  41. end
  42.  
  43. local function checkStorage()
  44.         if turtle.getItemCount(16) > 0 then
  45.                 print("Clean inventory...")
  46.                 while turtle.getItemCount(16) > 0 do
  47.                         sleep(5)
  48.                 end
  49.                 print( "Resuming..." )
  50.         end
  51. end
  52.  
  53. local function tryDig()
  54.     while turtle.detect() do
  55.         if turtle.dig() then
  56.             checkStorage()
  57.             sleep(0.5)
  58.         else
  59.             return false
  60.         end
  61.     end
  62.     return true
  63. end
  64.  
  65. local function tryForward(slot)
  66.         refuel(slot)
  67.         while not turtle.forward() do
  68.                 if turtle.detect() then
  69.                         if not tryDig() then
  70.                                 return false
  71.                         end
  72.                 elseif turtle.attack() then
  73.                         checkStorage()
  74.                 else
  75.                         sleep(0.5)
  76.                 end
  77.         end
  78.         return true
  79. end
  80.  
  81. local function checkBlock(slot,first,last,block)
  82.         while turtle.getItemCount(slot) == 0 do
  83.                 slot = slot + 1
  84.                 if slot > last then
  85.                         print("Missing: " .. block)
  86.                         print("Slots: " .. first .. "-" .. last)
  87.                         local line=""
  88.                         repeat
  89.                                 print("Enter 'Y' to continue: ")
  90.                                 line = io.read()
  91.                         until string.lower(line) ~= "y"
  92.                         print("Resuming...")
  93.                         slot = first --Reset slot to first
  94.                 end
  95.         end
  96.         return slot
  97. end
  98.  
  99.  local function tryDig()
  100.     while turtle.detect() do
  101.         if turtle.dig() then
  102.             checkStorage()
  103.             sleep(0.5)
  104.         else
  105.             return false
  106.         end
  107.     end
  108.     return true
  109. end
  110.  
  111. local function tryBlock(slot,inv,first,last,block,dir)
  112.         slot=checkBlock(slot,first,last,block)
  113.         turtle.select(slot)
  114.         if (dir == 0) then
  115.                 turtle.place()
  116.         elseif (dir > 0) then
  117.                 turtle.placeUp()
  118.         else
  119.                 turtle.placeDown()
  120.         end
  121.         turtle.select(inv)
  122.         return checkBlock(slot,first,last,block)
  123. end
  124.  
  125. local function placeBehind(slot,inv,first,last,block)
  126.         turtle.turnLeft()
  127.         turtle.turnLeft()
  128.         slot = tryBlock(slot,inv,first,last,block,0)
  129.         turtle.turnLeft()
  130.         turtle.turnLeft()
  131.         return slot
  132. end
  133.  
  134. local len
  135. local slot=2
  136. local quad
  137. local seg
  138. local segpos
  139. local seglen
  140.  
  141. for quad=0,3,1 do
  142.         --set array length
  143.         len=#tArgs
  144.         --First section of Quandrant
  145.         for seg=2,len,1 do
  146.                 seglen=tonumber(tArgs[seg])
  147.                 for segpos=1,(seglen-1),1 do
  148.                         tryForward(slot)
  149.                         slot = placeBehind(slot,9,2,8,"Placement Blocks")
  150.                 end
  151.                 turtle.turnLeft()
  152.                 tryForward(slot)
  153.                 slot = placeBehind(slot,9,2,8,"Placement Blocks")
  154.                 turtle.turnRight()
  155.                 tryForward(slot)
  156.         end
  157.        
  158.         --Handle Odd Length Quadrants
  159.         if evenodd==1 then
  160.                 len=len-1
  161.         end
  162.        
  163.         --Last Section of Quandrant
  164.         turtle.turnLeft()
  165.         for seg=len,2,-1 do
  166.                 seglen=tonumber(tArgs[seg])
  167.                 for segpos=1,seglen,1 do
  168.                         tryForward(slot)
  169.                         slot = placeBehind(slot,9,2,8,"Placement Blocks")
  170.                 end
  171.                 if seg ~= 2 then
  172.                     turtle.turnRight()
  173.                     tryForward(slot)
  174.                     turtle.turnLeft()
  175.                 end
  176.         end
  177. end
Advertisement
Add Comment
Please, Sign In to add comment