Gamboodle

Gambit's ComputerCraft Quarry and Bore Turtle Program V3

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