Advertisement
ninja_axiom

ReplaceBlock

Oct 20th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. function isEmpty(i)
  2.     if turtle.getItemCount(i)==0 then
  3.         print("Slot empty. Changing Slot")
  4.         return true
  5.     else
  6.         return false
  7.     end
  8. end
  9.  
  10. function shiftLeft()
  11.     turtle.turnLeft()
  12.     turtle.dig()
  13.     turtle.forward()
  14.     turtle.turnLeft()
  15. end
  16.  
  17. function shiftRight()
  18.     turtle.turnRight()
  19.     turtle.dig()
  20.     turtle.forward()
  21.     turtle.turnRight()
  22. end
  23.  
  24. function checkFront()
  25.     if turtle.detect() then
  26.         turtle.dig()
  27.     end
  28. end
  29.  
  30. function compareDown(i)
  31.     turtle.select(16)
  32.     if turtle.compareDown() then
  33.         turtle.select(i)
  34.         return true
  35.     else
  36.         turtle.select(i)
  37.         return false
  38.     end
  39. end
  40.  
  41. function digDown()
  42.     turtle.digDown()
  43. end
  44.  
  45. function dig()
  46.     turtle.dig()
  47. end
  48.  
  49. function placeDown()
  50.     turtle.placeDown()
  51. end
  52.  
  53.  
  54. --Main
  55.  
  56.  
  57. io.write("Enter Length: ")
  58. length = tonumber(io.read())
  59. io.write("Enter Width: ")
  60. width = tonumber(io.read())
  61.  
  62.  
  63. itemIndex = 1
  64. turtle.select(itemIndex)
  65. widthCount = 0
  66.  
  67. while true do
  68.     for l=1, (length) do
  69.         if (compareDown(itemIndex)~=true) then
  70.             digDown()
  71.             if isEmpty(itemIndex) then
  72.                 itemIndex = itemIndex+1
  73.                 turtle.select(itemIndex)
  74.             end
  75.             placeDown()
  76.         end
  77.         checkFront()
  78.         turtle.forward()
  79.         if (compareDown(itemIndex)~=true) then
  80.             digDown()
  81.             if isEmpty(itemIndex) then
  82.                 itemIndex = itemIndex+1
  83.                 turtle.select(itemIndex)
  84.             end
  85.             placeDown()
  86.         end
  87.     end
  88.    
  89.     widthCount = widthCount+1
  90.     if widthCount==width then
  91.         break
  92.     end
  93.    
  94.     shiftRight()
  95.    
  96.     for l=1, (length) do
  97.         if (compareDown(itemIndex)~=true) then
  98.             digDown()
  99.             if isEmpty(itemIndex) then
  100.                 itemIndex = itemIndex+1
  101.                 turtle.select(itemIndex)
  102.             end
  103.             placeDown()
  104.         end
  105.         checkFront()
  106.         turtle.forward()
  107.         if (compareDown(itemIndex)~=true) then
  108.             digDown()
  109.             if isEmpty(itemIndex) then
  110.                 itemIndex = itemIndex+1
  111.                 turtle.select(itemIndex)
  112.             end
  113.             placeDown()
  114.         end
  115.     end
  116.    
  117.     widthCount = widthCount+1
  118.     if widthCount==width then
  119.         break
  120.     end
  121.    
  122.     shiftLeft()
  123. end
  124.  
  125. if (width%2)~=0 then
  126.     for i=1, length do
  127.         turtle.back()
  128.     end
  129. end
  130.  
  131.  
  132.  
  133. --[[
  134. function isEmpty(i)
  135.     if turtle.getItemCount(i)==1 then
  136.         print("Empty")
  137.         return true
  138.     end
  139. end
  140.  
  141. function shiftLeft()
  142.     turtle.turnLeft()
  143.     turtle.dig()
  144.     turtle.forward()
  145.     turtle.turnLeft()
  146. end
  147.  
  148. function shiftRight()
  149.     turtle.turnRight()
  150.     turtle.dig()
  151.     turtle.forward()
  152.     turtle.turnRight()
  153. end
  154.  
  155. function widthCheck(a, b)
  156.     if a == b then
  157.         return true
  158.     end
  159.     return false
  160. end
  161.  
  162.  
  163.  
  164. --Main
  165.  
  166. io.write("Enter Length: ")
  167. length = tonumber(io.read())
  168. io.write("Enter Width: ")
  169. width = tonumber(io.read())
  170.  
  171.  
  172. itemIndex = 1
  173. turtle.select(itemIndex)
  174. widthCount = 0
  175.  
  176. while true do
  177.     for l=1, length do
  178.         if turtle.detect() then
  179.             turtle.dig()
  180.         end
  181.         if (turtle.compareDown() == false) then
  182.             turtle.digDown()
  183.             if isEmpty(itemIndex) then
  184.                 itemIndex = itemIndex + 1
  185.                 turtle.select(itemIndex)
  186.             end
  187.             turtle.placeDown()
  188.         end
  189.     end
  190.     widthCount = widthCount+1
  191.     if widthCheck(widthCount, width) then
  192.         break
  193.     end
  194.     shiftRight()
  195.    
  196.    
  197.    
  198.     for l=1, length do
  199.         if turtle.detect() then
  200.             turtle.dig()
  201.         end
  202.         if (turtle.compareDown() == false) then
  203.             turtle.digDown()
  204.             if isEmpty(itemIndex) then
  205.                 itemIndex = itemIndex + 1
  206.                 turtle.select(itemIndex)
  207.             end
  208.             turtle.placeDown()
  209.         end
  210.     end
  211.     widthCount = widthCount+1
  212.     if widthCheck(widthCount, width) then
  213.         break
  214.     end
  215.     shiftLeft()
  216. end
  217.  
  218. if (width%2) > 0 then
  219.     for i=1, length do
  220.         turtle.back()
  221.     end
  222. end
  223. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement