jseely

depthFill

Jan 29th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local xWidth = tonumber(tArgs[1])
  4. local zWidth = tonumber(tArgs[2]) or 1
  5. local useEnder = tArgs[3] or false
  6.  
  7. local xPos = 1
  8. local zPos = 1
  9. local xDir, zDir = 1, 0
  10. local curSlot = 1
  11.  
  12. local function selectResource()
  13.     while turtle.getItemCount(curSlot) == 0 and curSlot < 16 do
  14.         curSlot = curSlot + 1
  15.     end
  16.     turtle.select(curSlot)
  17.     if curSlot == 16 then
  18.         if not useEnder then
  19.             return false
  20.         end
  21.         turtle.placeUp()
  22.         for i = 1, 15, 1 do
  23.             turtle.select(i)
  24.             turtle.suckUp()
  25.         end
  26.         turtle.select(curSlot)
  27.         turtle.digUp()
  28.         curSlot = 1
  29.         turtle.select(curSlot)
  30.     end
  31.     return true
  32. end
  33.  
  34. local function placeDown()
  35.     local result = selectResource()
  36.     if not result then
  37.         return false
  38.     end
  39.     return turtle.placeDown()
  40. end
  41.  
  42. local function fillUnit()
  43.     local y = 0
  44.     while not turtle.detectDown() do
  45.         local down = false
  46.         while not down do
  47.             down = turtle.down()
  48.         end
  49.         y = y - 1
  50.     end
  51.    
  52.     local result = true
  53.     while y < 0 and result do
  54.         local up = false
  55.         while not up do
  56.             up = turtle.up()
  57.         end
  58.         result = placeDown()
  59.         y = y + 1
  60.     end
  61.    
  62.     if y == 0 then
  63.         return true
  64.     end
  65.    
  66.     while y < 0 do
  67.         local up = false;
  68.         while not up do
  69.             up = turtle.up()
  70.         end
  71.         y = y + 1
  72.     end
  73.    
  74.     return false
  75. end
  76.  
  77. local function turnRight(times)
  78.     times = times or 1
  79.     for i = 1, times, 1 do
  80.         if xDir == 1 then
  81.             xDir = 0
  82.             zDir = 1
  83.         elseif xDir == -1 then
  84.             xDir = 0
  85.             zDir = -1
  86.         elseif zDir == 1 then
  87.             xDir = -1
  88.             zDir = 0
  89.         else
  90.             xDir = 1
  91.             zDir = 0
  92.         end
  93.         turtle.turnRight()
  94.     end
  95. end
  96.  
  97. local function turnLeft(times)
  98.     times = times or 1
  99.     for i = 1, times, 1 do
  100.         if xDir == 1 then
  101.             xDir = 0
  102.             zDir = -1
  103.         elseif xDir == -1 then
  104.             xDir = 0
  105.             zDir = 1
  106.         elseif zDir == 1 then
  107.             xDir = 1
  108.             zDir = 0
  109.         else
  110.             xDir = -1
  111.             zDir = 0
  112.         end
  113.         turtle.turnLeft()
  114.     end
  115. end
  116.  
  117. local function forward(times)
  118.     times = times or 1
  119.     local result = false
  120.     for i = 1, times, 1 do
  121.         while not result do
  122.             turtle.dig()
  123.             result = turtle.forward()
  124.         end
  125.        
  126.         if result then
  127.             xPos = xPos + xDir
  128.             zPos = zPos + zDir
  129.         else
  130.             return false
  131.         end
  132.     end
  133.     return true
  134. end
  135.  
  136. local result = fillUnit()
  137. local done = false
  138. local doneRow = false
  139.  
  140. while not done and result do
  141.     if doneRow then
  142.         if xDir == 1 then
  143.             turnRight()
  144.             result = forward()
  145.             result = result and fillUnit()
  146.             turnRight()
  147.         else
  148.             turnLeft()
  149.             result = forward()
  150.             result = result and fillUnit()
  151.             turnLeft()
  152.         end
  153.         doneRow = false
  154.     else
  155.         result = forward()
  156.         result = result and fillUnit()
  157.         if xPos == 1 or xPos == xWidth then
  158.             doneRow = true
  159.         end
  160.         if doneRow and zPos == zWidth then
  161.             done =  true
  162.         end
  163.     end
  164. end
  165.  
  166. if xDir == 1 then
  167.     turnLeft()
  168. else
  169.     turnRight()
  170. end
  171.  
  172. while zPos > 1 do
  173.     forward()
  174. end
  175.  
  176. turnLeft()
  177.  
  178. while xPos > 1 do
  179.     forward()
  180. end
Advertisement
Add Comment
Please, Sign In to add comment