Advertisement
redkill

CC: Tweaked Quarry

Apr 24th, 2023 (edited)
2,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 KB | None | 0 0
  1. -- Description: Quarries a 16 x 16 area, and returns to a drop off inventory directly above it's starting location.
  2.  
  3. -- Usage info:
  4.   -- 1: type in pastebin get <code at end of url> <desired program name>
  5.   -- 2: Place mining turtle in bottom right corner of chunk you want to quarry, put it with in the quarry boundaries.
  6.   -- 3: Place chest or other drop off inventory above the turtle.
  7.   -- 4: Place fuel in slot one of turtle.
  8.   -- 5: Run program, and come back to see the hole later.
  9.  
  10. -- Variable declaration zone
  11. local level = 0 -- Level turtle just completed
  12. local currentLevel = 0 -- Level turtle is currently on
  13. local layer = 0 -- Layers dug
  14. local direction = "right" -- Direction turtle must turn in next
  15. local x = 1 -- x location
  16. local z = 1 -- z location
  17. local noBedrock = true
  18. local slot = 1
  19. local goHome = 0
  20. -- End variable declaration zone
  21.  
  22. -- Function delaration zone
  23. -- Refuel script
  24. function refuel()
  25.   print("Checking fuel...")
  26.   if turtle.getFuelLevel() < 500 then
  27.     print("Refueling. Only ", turtle.getFuelLevel(), " left.")
  28.     turtle.select(1)
  29.     turtle.refuel(15)
  30.     print("Fuel inceased to: ", turtle.getFuelLevel())
  31.   end
  32. end
  33. -- Digs a layer
  34. function digLayer()
  35.   print("Preparing to dig...")
  36.   for x = 1,16 do
  37.     -- Digs a 16 block long line
  38.     for z = 1,15 do
  39.       turtle.dig()
  40.       while turtle.attack() do
  41.         sleep(1)
  42.       end
  43.       turtle.forward()
  44.     end
  45.     -- Determines if it needs to turn left or right to dig the next row
  46.     if direction == "left" and x ~= 16 then
  47.       turtle.turnLeft()
  48.       turtle.dig()
  49.       while turtle.attack() do
  50.         sleep(1)
  51.       end
  52.       turtle.forward()
  53.       turtle.turnLeft()
  54.       direction = "right"
  55.     elseif direction == "right" and x ~= 16 then
  56.       turtle.turnRight()
  57.       turtle.dig()
  58.       while turtle.attack() do
  59.         sleep(1)
  60.       end
  61.       turtle.forward()
  62.       turtle.turnRight()
  63.       direction = "left"
  64.     end
  65.   end
  66.   print("Layer complete.")
  67. end
  68. -- Checks for bedrock
  69. function checkBedrock()
  70.   print("Checking for bedrock...")
  71.   if turtle.digDown() == true then
  72.     turtle.select(2)
  73.     turtle.placeDown()
  74.     print("Not yet at bedrock.")
  75.   elseif turtle.down() == true then
  76.     turtle.up()
  77.     print("Not yet at bedrock.")
  78.   else
  79.     noBedrock = false
  80.     print("At bedrock.")
  81.   end
  82. end
  83. -- Returns to home location to drop off resources
  84. function dropOff()
  85.   print("Preparing dropoff sequence...")
  86.   -- Return home location
  87.   print("Returning home...")
  88.   turtle.turnRight()
  89.   for goHome = 1,15 do
  90.     while turtle.attack() do
  91.       sleep(1)
  92.     end
  93.     turtle.forward()
  94.   end
  95.   -- Rises to the surface to drop items off
  96.   level = 0
  97.   while turtle.attackUp() do
  98.     sleep(1)
  99.   end
  100.   while turtle.up() do
  101.     level = level + 1
  102.     while turtle.attackUp() do
  103.       sleep(1)
  104.     end
  105.   end
  106.   -- Empties inventory into drop off
  107.   print("Preparing to empty inventory...")
  108.   for slot = 2,16 do
  109.     turtle.select(slot)
  110.     turtle.dropUp()
  111.   end
  112.   print("Inventory cleared. All items dropped off.")
  113.   -- Goes back down to desired layer
  114.   retriveFuel()
  115.   print("Returning to correct floor...")
  116.   currentLevel = 0
  117.   while turtle.attackDown() do
  118.     sleep(1)
  119.   end
  120.   while level ~= currentLevel do
  121.     turtle.down()
  122.     while turtle.attackDown() do
  123.       sleep(1)
  124.     end
  125.     currentLevel = currentLevel + 1
  126.   end
  127.   print("Back at correct floor.")
  128. end
  129. -- Ending sequence
  130. function endSequence()
  131.   print("Starting end sequence...")
  132.   while turtle.attackUp() do
  133.     sleep(1)
  134.   end
  135.   while turtle.up() do
  136.     while turtle.attackUp() do
  137.       sleep(1)
  138.     end
  139.   end
  140.   print("Total number of layers dug: ", layer)
  141.   print("Mission complete. Master shall not punish me.")
  142. end
  143. -- Layer preparation
  144. function layerPrep()
  145.   print("Preforming next layer preparation...")
  146.   turtle.turnRight()
  147.   direction = "right"
  148.   turtle.digDown()
  149.   turtle.down()
  150.   print("Next layer prepared")
  151. end
  152.  
  153. function retriveFuel()
  154.   turtle.turnLeft()
  155.   turtle.select(1)
  156.   local fuelCount = turtle.getItemCount(1)
  157.   local toRefuel = 64 - fuelCount
  158.   print("Retrieving fuel... ", toRefuel, " needed.")
  159.   turtle.suck(toRefuel)
  160.   turtle.turnRight()
  161. end
  162.  
  163. -- End function declaration zone
  164.  
  165. -- Main running sequence
  166. while noBedrock do
  167.   refuel()
  168.   checkBedrock()
  169.   if noBedrock == true then
  170.     digLayer()
  171.     dropOff()
  172.     layerPrep()
  173.   end
  174.   layer = layer + 1
  175. end
  176. endSequence()
  177. -- End main running sequence
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement