Advertisement
neonerz

build-tools

Feb 2nd, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.17 KB | None | 0 0
  1. iDebug = true
  2. slot = 2
  3. iPriority = 4
  4.  
  5. local mov ={}
  6.  
  7. mov.forwardSafe = function ()
  8.     if slot == 1 then
  9.         slot = 2
  10.     end
  11.     while turtle.detect() do
  12.         turtle.dig()
  13.         sleep(1)
  14.     end
  15.     run = 1
  16.     while not turtle.compareDown() do
  17.         if slot > 16 then
  18.             run = run+1
  19.             slot = 2
  20.         end
  21.         if run == 2 then
  22.             debugPrint("OH NO OUT OF BLOCKS!",0)
  23.             return
  24.         end
  25.         turtle.select(slot)
  26.         slot=slot+1
  27.     end
  28.     slot=slot-1
  29.     if slot == 1 then
  30.         slot = 2
  31.     end
  32.     while not turtle.forward() do
  33.         sleep(0.1)
  34.     end
  35.     return true
  36. end
  37.  
  38. mov.forward = function ()
  39.     while turtle.detect() do
  40.         turtle.dig()
  41.         sleep(1)
  42.     end
  43.     while not turtle.forward() do
  44.         sleep(0.1)
  45.     end
  46.     return true
  47. end
  48.  
  49. mov.back = function ()
  50.     while not turtle.back() do
  51.         sleep(0.1)
  52.     end
  53.     return true
  54. end
  55.  
  56. mov.up = function ()
  57.     while not turtle.up() do
  58.         sleep(0.1)
  59.     end
  60.     return true
  61. end
  62.  
  63. mov.down = function ()
  64.     while not turtle.down() do
  65.         sleep(0.1)
  66.     end
  67.     return true
  68. end
  69.  
  70. mov.place = function ()
  71.     while turtle.getItemCount(slot) < 1 do
  72.         slot=slot+1
  73.         if slot > 16 then
  74.             debugPrint("Error: We ran out of blocks!",0)
  75.             return false
  76.         end
  77.     end
  78.     while not turtle.placeDown() do
  79.         sleep(0.1)
  80.     end
  81.     return true
  82.  
  83. end
  84.  
  85. function checkNextItem()
  86.     while turtle.getItemCount(slot) < 1 do
  87.         slot=slot+1
  88.         if slot > 16 then
  89.             debugPrint("Error: We ran out of blocks!",0)
  90.             return false
  91.         end
  92.     end
  93.     turtle.select(slot)
  94.     run = 1
  95.     while not turtle.compareDown() do
  96.         if slot > 16 then
  97.             run = run+1
  98.             slot = 2
  99.         end
  100.         if run == 2 then
  101.             debugPrint("Error: No match blocks",0)
  102.             return false
  103.         end
  104.         turtle.select(slot)
  105.         slot=slot+1
  106.     end
  107.     return true
  108. end
  109.  
  110. function goRestock(yPosition)
  111.     if yPosition == 1 then
  112.         turtle.turnLeft()
  113.         for slot = 2,16 do
  114.             turtle.select(slot)
  115.             if not turtle.compareDown() then
  116.                 turtle.dropUp()
  117.                 turtle.suck()
  118.             else
  119.                 turtle.suck()
  120.             end
  121.         end
  122.         turtle.turnRight()
  123.     end
  124. end
  125.  
  126. function goHome (direction)
  127.     if direction == "left" then
  128.         turtle.turnLeft()
  129.         for i = 1,x-1 do
  130.             mov.forward()
  131.         end
  132.         turtle.turnRight()
  133.         for i = 1,z-1 do
  134.             mov.forward()
  135.         end
  136.         turtle.turnRight()
  137.     end
  138.     if direction == "right" then
  139.         for i = 1,z do
  140.             mov.forward()
  141.         end
  142.         turtle.turnRight()
  143.     end
  144. end
  145.  
  146. local tArgs = { ... }
  147.  
  148. if #tArgs <= 2 then
  149.     print "you're using it wrong!"
  150.     return
  151. end
  152.  
  153. x=tArgs[1]
  154. y=tArgs[2]
  155. z=tArgs[3]
  156.  
  157. mov.detectBlock = function ()
  158.     while turtle.detectDown() do
  159.         if turtle.compareDown() then
  160.             return false
  161.         else
  162.             return true
  163.         end
  164.     end
  165. end
  166.  
  167. function debugPrint (mess,priority)
  168.     if iDebug == true and priority <= iPriority then
  169.         print(mess)
  170.     end
  171. end
  172.  
  173. function checkBlockCount ()
  174.     iblocks = 0
  175.     blocks = (x*2)+(z*2)
  176.     for i = 2,16 do
  177.         turtle.select(i)
  178.         if turtle.compareDown() then
  179.             iblocks = tonumber(iblocks)+tonumber(turtle.getItemCount(i))
  180.         end
  181.     end
  182.     turtle.select(slot)
  183.     if iblocks > blocks then
  184.         return true
  185.     else
  186.         return false
  187.     end
  188. end
  189.  
  190. turtle.select(slot)
  191. while turtle.getItemCount(slot) < 1 do
  192.     slot=slot+1
  193.     if slot > 16 then
  194.         debugPrint("Error: No blocks loaded",0)
  195.     end
  196. end
  197. turtle.select(slot)
  198.  
  199. debugPrint("Structure Size: "..x..","..y..","..z,1)
  200. direction = "right"
  201.  
  202. for i =1,z do
  203.     for i = 1,x do
  204.         if turtle.detectDown() then
  205.             if turtle.compareDown() then
  206.                 mov.forwardSafe()
  207.             else
  208.                 turtle.digDown()
  209.                 mov.place()
  210.                 mov.forwardSafe()
  211.             end
  212.         else   
  213.             mov.place()
  214.             mov.forwardSafe()  
  215.         end
  216.     end
  217.     mov.back()
  218.     debugPrint(direction,2)
  219.     if direction == "right" then
  220.         turtle.turnRight()
  221.         mov.forwardSafe()
  222.         turtle.turnRight()
  223.         direction = "left"
  224.     else
  225.         turtle.turnLeft()
  226.         mov.forwardSafe()
  227.         turtle.turnLeft()
  228.         direction = "right"
  229.     end
  230. end
  231.  
  232. debugPrint("final: "..direction,2)
  233.  
  234. if direction == "left" then
  235.     turtle.turnRight()
  236.     mov.forward()
  237. end
  238. if direction == "right" then
  239.     turtle.turnLeft()
  240. end
  241. yPosition = 1
  242. if not checkBlockCount() then
  243.     debugPrint("NEED MORE BLOCKS",1)
  244.     debugPrint("Blocks loaded: "..iblocks,1)
  245.     debugPrint("Blocks needed for next row: "..blocks,1)
  246.     position = "start"
  247.     goHome(direction)
  248.     goRestock(1)
  249. else
  250.     debugPrint("Blocks loaded: "..iblocks,1)
  251.     debugPrint("Blocks needed for next row: "..blocks,1)
  252.     debugPrint("WE ARE GOOD TO MOVE ON",0)
  253.     position = "go"
  254.     goHome(direction)
  255. end
  256.  
  257. for i = 2,y-1 do
  258. turtle.select(slot)
  259.     checkNextItem()
  260.     mov.up()
  261.         for i = 1,x do
  262.             mov.place()
  263.             mov.forwardSafe()  
  264.         end
  265.         mov.back()
  266.         turtle.turnRight()
  267.         mov.forwardSafe()  
  268.         for i = 1,z-1 do
  269.             mov.place()
  270.             mov.forwardSafe()  
  271.         end
  272.         mov.back()
  273.         turtle.turnRight()
  274.         mov.forwardSafe()
  275.         for i = 1,x-1 do
  276.             mov.place()
  277.             mov.forwardSafe()  
  278.         end    
  279.         mov.back()
  280.         turtle.turnRight()
  281.         mov.forwardSafe()
  282.         for i = 1,z-2 do
  283.             mov.place()
  284.             mov.forwardSafe()  
  285.         end
  286.         turtle.turnRight()
  287.     if not checkBlockCount() then
  288.         debugPrint("NEED MORE BLOCKS",1)
  289.         debugPrint("Blocks loaded: "..iblocks,1)
  290.         debugPrint("Blocks needed for next row: "..blocks,1)
  291.         position = "start"
  292.         goRestock(1)
  293.     else
  294.         debugPrint("Blocks loaded: "..iblocks,1)
  295.         debugPrint("Blocks needed for next row: "..blocks,1)
  296.         debugPrint("WE ARE GOOD TO MOVE ON",0)
  297.         position = "go"
  298.     end    
  299. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement