Vaerys_Dawn

new_quarry.lua

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