Gamboodle

Gambit's Computercraft Quarry/Bore Turtle Program 2.0 (WIP)

Apr 3rd, 2020
2,737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. turtle.refuel()
  2.  
  3. function clearScreen()
  4.     term.clear()
  5.     term.setCursorPos(1,1)
  6. end
  7.  
  8. function setup()
  9.     posX = 0
  10.     posY = 0
  11.     posZ = 0
  12.     rotation = 0
  13.     layerType = 0
  14.     clearScreen()
  15.     io.write("Quarry or bore? ")
  16.     mineType = io.read()
  17.     clearScreen()
  18.     io.write("Rows: ")
  19.     rows = io.read()
  20.     io.write("Columns: ")
  21.     columns = io.read()
  22.     clearScreen()
  23.     if mineType == "quarry" then
  24.         io.write("Current 'y' level: ")
  25.         iniY = io.read()
  26.         iniY = tonumber (iniY)
  27.         clearScreen()
  28.     end
  29.     start()
  30. end
  31.  
  32. function info()
  33.     clearScreen()
  34.     print("Creating a " .. rows .. "x" .. columns .. " " .. mineType)
  35.     print("Total distance: " .. posX + posY + posZ)
  36.     print("X: " .. posX)
  37.     print("Y: " .. posY)
  38.     print("Z: " .. posZ)
  39.     print("Rotation: " .. rotation)
  40.     print("Layer Type: " .. layerType)
  41.     print("Fuel level: " .. turtle.getFuelLevel())
  42. end
  43.  
  44. function orientate()
  45.     if rotation == 0 then
  46.         turtle.turnLeft()
  47.         rotation = 3
  48.         info()
  49.     elseif rotation == 1 then
  50.         turtle.turnLeft()
  51.         rotation = 0
  52.         info()
  53.         turtle.turnLeft()
  54.         rotation = 3
  55.         info()
  56.     elseif rotation == 2 then
  57.         turtle.turnRight()
  58.         rotation = 3
  59.         info()
  60.     end
  61. end
  62.  
  63. function recover()
  64.     orientate()
  65.     stepY = posY
  66.     stepX = posX
  67.     stepZ = posZ
  68.     for posY = stepY - 1, 0, -1 do
  69.         turtle.up()
  70.         info()
  71.     end
  72.     for posX = stepX - 1, 0, -1 do
  73.         turtle.forward()
  74.         info()
  75.     end
  76.     turtle.turnLeft()
  77.     for posZ = stepZ - 1, 0, -1 do
  78.         turtle.forward()
  79.         info()
  80.     end
  81. end
  82.  
  83. function digStraight()
  84.     turtle.digDown()
  85.     turtle.dig()
  86.     turtle.dig()
  87.     turtle.forward()
  88.     if rotation == 0 then
  89.         posZ = posZ + 1
  90.     elseif rotation == 1 then
  91.         posX = posX + 1
  92.     elseif rotation == 2 then
  93.         posZ = posZ - 1
  94.     elseif rotation == 3 then
  95.         posX = posX - 1
  96.     end
  97.     turtle.digUp()
  98.     info()
  99. end
  100.  
  101. function nextRow()
  102.     if layerType == 0 then
  103.         if rotation == 0 then
  104.             turtle.turnRight()
  105.             rotation = 1
  106.             info()
  107.             digStraight()
  108.             turtle.turnRight()
  109.             rotation = 2
  110.             info()
  111.         elseif rotation == 2 then
  112.             turtle.turnLeft()
  113.             rotation = 1
  114.             info()
  115.             digStraight()
  116.             turtle.turnLeft()
  117.             rotation = 0
  118.             info()
  119.         end
  120.     elseif layerType == 1 then
  121.         if rotation == 0 then
  122.             turtle.turnLeft()
  123.             rotation = 3
  124.             info()
  125.             digStraight()
  126.             turtle.turnLeft()
  127.             rotation = 2
  128.             info()
  129.         elseif rotation == 2 then
  130.             turtle.turnRight()
  131.             rotation = 3
  132.             info()
  133.             digStraight()
  134.             turtle.turnRight()
  135.             rotation = 0
  136.             info()
  137.         end
  138.     end
  139. end
  140.  
  141. function nextLayer()
  142.     turtle.turnRight()
  143.     if rotation == 0 then
  144.         rotation = 1
  145.         info()
  146.     elseif rotation == 2 then
  147.         rotation = 3
  148.         info()
  149.     end
  150.     turtle.turnRight()
  151.     if rotation == 1 then
  152.         rotation = 2
  153.         info()
  154.     elseif rotation == 3 then
  155.         rotation = 0
  156.         info()
  157.     end
  158.     turtle.down()
  159.     posY = posY + 1
  160.     info()
  161.     turtle.digDown()
  162.     turtle.down()
  163.     posY = posY + 1
  164.     info()
  165.     turtle.digDown()
  166.     turtle.down()
  167.     posY = posY + 1
  168.     info()
  169.     if layerType == 0 then
  170.         layerType = 1
  171.     elseif layerType == 1 then
  172.         layerType = 0
  173.     end
  174. end
  175.  
  176. function layerMove()
  177.     for c = columns, 1, -1 do
  178.         for r = rows, 2, -1 do
  179.             digStraight()
  180.         end
  181.         if c > 1 then
  182.             nextRow()
  183.         else
  184.             turtle.digDown()
  185.         end
  186.     end
  187. end
  188.  
  189. function quarry()
  190.     turtle.digDown()
  191.     turtle.down()
  192.     posY = posY + 1
  193.     info()
  194.     turtle.digDown()
  195.     turtle.down()
  196.     posY = posY + 1
  197.     info()
  198.     while posY < iniY - 2 do
  199.         layerMove()
  200.         nextLayer()
  201.     end
  202.     recover()
  203. end
  204.  
  205. function bore()
  206.     turtle.up()
  207.     posY = posY + 1
  208.     info()
  209.     turtle.dig()
  210.     turtle.forward()
  211.     posZ = posZ + 1
  212.     info()
  213.     turtle.digUp()
  214.     layerMove()
  215.     recover()
  216. end
  217.  
  218. function start()
  219.     if mineType == "quarry" then
  220.         quarry()
  221.     elseif mineType == "bore" then
  222.         bore()
  223.     else
  224.         setup()
  225.     end
  226. end
  227.  
  228. setup()
Add Comment
Please, Sign In to add comment