abc123mewot

Quarry

May 30th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Computercraft quarry script
  2. --(c) jeremiah Lowe 2018
  3. width = 3  --The width of the hole
  4. height = 3 --The height of the hole
  5. depth = 5  --The depth of the hole
  6. --The inventory slot for the fuel
  7. fuelSlot = 1
  8. --The minimum allowed free slots
  9. allowedFreeSlots = 4
  10.  
  11. print("Initializing SmartTurtle")
  12. if not os.loadAPI("sturtle") then
  13.   print("Failed to load SmartTurtle API")
  14. end
  15. sturtle.setFuelSlot(fuelSlot)
  16. sturtle.setFuelBufferSize(width * height)
  17. sturtle.enableAutoRefuel()
  18. sturtle.createHome("original")
  19. print("Done")
  20. print("Mining an area of " .. width .. ", " .. height .. ", " .. depth)
  21. function emptyInventory()
  22.   sturtle.createHome("back")
  23.   sturtle.home("original")
  24.   side = 4
  25.   for i=0,3 do
  26.     sturtle.turnRight()
  27.     e, b = turtle.inspect()
  28.     if e and b.name ~= nil then
  29.       if string.match(string.lower(b.name), "chest") then
  30.         side = sturtle.getDirection()
  31.         break
  32.       end
  33.     end
  34.   end
  35.   if side == 4 then
  36.     error("No chest beside turtle at home position")
  37.   end
  38.   sturtle.pointTo(side)
  39.   for i=1,16 do
  40.     if i ~= fuelSlot then
  41.       turtle.select(i)
  42.       turtle.drop()
  43.     end
  44.   end
  45.   sturtle.home("back")
  46. end
  47. function digTurn(left)
  48.   turn = sturtle.turnRight
  49.   if left then turn = sturtle.turnLeft end
  50.   if not turn() then return false end
  51.   if not sturtle.digForward(1) then return false end
  52.   if not turn() then return false end
  53.   return true
  54. end
  55. function mineLayer()
  56.   for i=1,height do
  57.     if not sturtle.digForward(width-1) then return false end
  58.     if sturtle.getFreeSlots() < allowedFreeSlots then
  59.       emptyInventory()
  60.     end
  61.     if i ~= height then
  62.       if not digTurn(i % 2 == 0) then return false end
  63.     end
  64.   end
  65.   return true
  66. end
  67. sturtle.digForward()
  68. for i=1,depth do
  69.   sturtle.createHome("layer")
  70.   while not mineLayer() do
  71.     sturtle.home("layer")
  72.   end
  73.   if i ~= depth then --No need here, were done!
  74.     sturtle.home("layer")
  75.     sturtle.digDown()
  76.   end
  77. end
  78. sturtle.home("original")
  79. emptyInventory()
Advertisement
Add Comment
Please, Sign In to add comment