Advertisement
SlyCedix

Quarry Turtle

Mar 19th, 2023 (edited)
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. -- pastebin get ezcuP8Aw bin/quarry.lua
  2.  
  3. -- Config
  4. local FUEL_CHEST = 1            -- Slot for fuel chest
  5. local ITEM_CHEST = 2            -- Slot for items chest
  6. local MAX_HEIGHT = 0
  7. local MIN_HEIGHT = -59          -- Minimum height when digging down
  8.  
  9. -- Local variables
  10. local direction = START_DIRECTION
  11. local startPos
  12. local startHeading
  13.  
  14. if not fs.exists("lib/serialize.lua") then
  15.     shell.run("pastebin", "get", "WdDfvs6u", "lib/serialize.lua")
  16. end
  17. os.loadAPI("lib/serialize.lua")
  18.  
  19. if not fs.exists("lib/serialize.lua") then
  20.     shell.run("pastebin", "get", "Gp82YPAm", "lib/LAML.lua")
  21. end
  22. os.loadAPI("lib/LAML.lua")
  23.  
  24. function EmptyInventory()
  25.     turtle.select(ITEM_CHEST)
  26.     turtle.digUp()
  27.     turtle.placeUp()
  28.     for slot = 3, 16 do
  29.         turtle.select(slot)
  30.         turtle.dropUp()
  31.     end
  32.     turtle.select(ITEM_CHEST)
  33.     turtle.digUp()
  34. end
  35.  
  36. function Refuel()
  37.     turtle.select(FUEL_CHEST)
  38.  
  39.     while turtle.detectUp() do
  40.         turtle.digUp()
  41.     end
  42.  
  43.     turtle.placeUp()
  44.     turtle.select(FUEL_CHEST)
  45.     turtle.suckUp()
  46.     turtle.refuel()
  47.     turtle.digUp()
  48. end
  49.  
  50. function Check()
  51.     if turtle.getItemCount(16) > 0 then -- Turtle inventory is full
  52.         EmptyInventory()
  53.     end
  54.  
  55.     if turtle.getFuelLevel() < 100 then
  56.         Refuel()
  57.     end
  58. end
  59.  
  60. function Advance()
  61.     while turtle.detect() do
  62.         turtle.dig()
  63.     end
  64.     LAML.forward()
  65. end
  66.  
  67. function init()
  68.     startPos = serialize.unserialize("startPos")
  69.     startHeading = serialize.unserialize("startHeading")
  70.  
  71.     LAML.init()
  72.     if startPos ~= nil then
  73.         print(startPos.x)
  74.         print(startPos.y)
  75.         print(startPos.z)
  76.  
  77.         pos = startPos
  78.         pos.y = LAML.getY()
  79.        
  80.         LAML.goto(pos)
  81.         LAML.face(startHeading)
  82.     end
  83. end
  84.  
  85.  
  86. function Main()
  87.     init()
  88.  
  89.     while true do
  90.         startPos = LAML.getPos()
  91.         startHeading = LAML.getOrientation()
  92.    
  93.         serialize.serialize(startPos, "startPos")
  94.         serialize.serialize(startHeading, "startHeading")
  95.  
  96.         offset = 0
  97.  
  98.         while LAML.getPos().y > MIN_HEIGHT do
  99.             print("Mining y=", LAML.getPos().y)
  100.             for x = 1, 16 do
  101.                 for z = 1, 15 do
  102.                     Check()
  103.                     Advance()
  104.                 end
  105.  
  106.                 if ((x + offset) % 2) == 1 then
  107.                     LAML.turnRight()
  108.                 else
  109.                     LAML.turnLeft()
  110.                 end
  111.  
  112.                 if not (x == 16) then
  113.                     Advance()
  114.                 end
  115.  
  116.                 if ((x + offset) % 2) == 1 then
  117.                     LAML.turnRight()
  118.                 else
  119.                     LAML.turnLeft()
  120.                 end
  121.             end
  122.  
  123.             turtle.digDown()
  124.             LAML.down()
  125.  
  126.             offset = offset + 1
  127.         end
  128.  
  129.         pos = startPos
  130.        
  131.         LAML.face(startHeading)
  132.  
  133.         pos = pos + LAML.getOrientationVector() * 16
  134.  
  135.         pos.y = MAX_HEIGHT
  136.  
  137.         LAML.goto(pos)
  138.  
  139.         LAML.face(startHeading)
  140.     end
  141. end
  142.  
  143. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement