Advertisement
Vaerys_Dawn

new_quarry

Feb 9th, 2021
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. base = require "turtle_base"
  2.  
  3. junk = { "minecraft:stone", "minecraft:cobblestone", "minecraft:dirt", "minecraft:gravel", "minecraft:netherrack", "byg:rocky_stone", "byg:scoria_cobblestone", "byg:soapstone", "minecraft:blackstone", "byg:frost_magma"}
  4.  
  5. settings.load("settings")
  6.  
  7. rows = settings.get("turtleRows", 0)
  8. columns = settings.get("turtleColumns", 0)
  9. startY = settings.get("turtleStartY", 0)
  10.  
  11.  
  12. -- init rows
  13. if rows == 0 then
  14.   term.clear()
  15.     term.setCursorPos(1,1)
  16.     io.write("Rows: ")
  17.     rows = tonumber(io.read())
  18.   settings.set("turtleRows", rows)
  19. end
  20.  
  21. -- init columns
  22. if columns == 0 then
  23.   term.clear()
  24.     term.setCursorPos(1,1)
  25.     io.write("Columns: ")
  26.     columns = tonumber(io.read())
  27.   settings.set("turtleColumns", columns)
  28. end
  29.  
  30. -- init startingY
  31. if startY == 0 then
  32.   term.clear()
  33.     term.setCursorPos(1,1)
  34.     io.write("What Y layer do you want me to start on: ")
  35.     startY = tonumber(io.read())
  36.   settings.set("turtleStartY", startY)
  37. end
  38.  
  39. oppositeCorner = base.getOffsetLocal(columns, rows)
  40.  
  41. settings.save("settings")
  42.  
  43. function junkStuff()
  44.   base.sendStatus("Junking Trash")
  45.   for i = 1, 16, 1 do
  46.     local slotData = turtle.getItemDetail(i)
  47.     for k,v in pairs(junk or {}) do
  48.       if slotData and slotData.name == v then
  49.         turtle.select(i)
  50.         turtle.drop()
  51.       end
  52.     end
  53.   end
  54.   base.minifyStacks()
  55. end
  56.  
  57. function dumpInv()
  58.   base.sendStatus("Dumping Inventory")
  59.   needCoal = turtle.getItemSpace(1)
  60.   turtle.suck(needCoal)
  61.  
  62.   for i = 2, 16, 1 do
  63.     turtle.select(i)
  64.     turtle.drop()
  65.   end
  66. end
  67.  
  68. function returnHome()
  69.   junkStuff()
  70.   base.returnHome()
  71.   dumpInv()
  72. end
  73.  
  74. function noSpaceLeft()
  75.   returnHome()
  76.   base.returnToWork()
  77. end
  78.  
  79. function checkInv()
  80.   -- clear any junk from inventory
  81.   junkStuff()
  82.   -- check inventory for any room for more items
  83.   if not base.checkSpace() then
  84.     noSpaceLeft()
  85.   end
  86.   -- attempts to fill fuel slot, returns true if enough fuel is located in the fuel slot.
  87.   base.refuel()
  88. end
  89.  
  90. -- breaks blocks on top and below current place
  91. function digForward()
  92.   base.moveForward()
  93.   base.updateWorklocation()
  94.   while turtle.detectDown() do
  95.     turtle.digDown()
  96.   end
  97.   while turtle.detectUp() do
  98.     turtle.digUp()
  99.   end
  100. end
  101.  
  102. -- turble rotatee
  103. function nextColumn(xPos)
  104.   if xPos % 2 == 0 then
  105.     base.rotateTo(1)
  106.     digForward()
  107.     base.rotateTo(2)
  108.   else
  109.     base.rotateTo(1)
  110.     digForward()
  111.     base.rotateTo(0)
  112.   end
  113. end
  114.  
  115. function nextLayer()
  116.   base.moveToPosition(base.home.x, base.work.y, base.home.z, base.home.direction, "Next Layer")
  117.   base.moveDown()
  118.   base.moveDown()
  119.   base.moveDown()
  120.   turtle.digDown()
  121. end
  122.  
  123. function digNorth()
  124.   for zPos = base.work.z, oppositeCorner.x-2, 1 do
  125.     if not base.checkSpace() then
  126.       noSpaceLeft()
  127.     end
  128.     zPos = base.work.z
  129.     digForward()
  130.     base.sendStatus("Digging Blocks")
  131.   end
  132. end
  133.  
  134. function digSouth()
  135.   for zPos = base.work.z, base.home.z, -1 do
  136.     if not base.checkSpace() then
  137.       noSpaceLeft()
  138.     end
  139.     zPos = base.work.z
  140.     digForward()
  141.     base.sendStatus("Digging Blocks")
  142.   end
  143. end
  144.  
  145. function mineColumn()
  146.   for xPos = base.work.x, oppositeCorner.x-1, 1 do
  147.     if xPos % 2 == 0 then
  148.       digNorth()
  149.     else
  150.       digSouth()
  151.     end
  152.     checkInv()
  153.     if base.work.x ~= columns-1 then nextColumn(xPos) end
  154.   end
  155. end
  156.  
  157. function doWork()
  158.   for yPos = base.work.y, 3, -1 do
  159.     mineColumn()
  160.     nextLayer()
  161.     yPos = base.work.y
  162.   end
  163.   returnHome("To finish up")
  164.   base.sendStatus("I have finished mining")
  165.   shell.run("reset_settings.lua")
  166. end
  167.  
  168. function mine()
  169.   checkInv()
  170.   base.sendStatus("attempting to return to start")
  171.   if not base.locationNil(base.work) then
  172.     base.returnToWork()
  173.   else
  174.     returnHome()
  175.   end
  176.   base.updateWorklocation()
  177.   while base.work.y > startY do
  178.     base.sendStatus("Moving to start")
  179.     base.moveDown()
  180.     base.updateWorklocation()
  181.   end
  182.   turtle.digDown()
  183.   if base.work.y < startY then turtle.digUp() end
  184.   doWork()
  185. end
  186.  
  187. base.init(true, {base.validTools.pickaxe, base.validTools.modem})
  188. mine()
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement