Advertisement
charonme

chquarry

May 21st, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- chquarry
  2. --
  3. -- At the beginning everything must be already placed:
  4. -- a quarry facing North,
  5. -- an "item" enderchest on the West side of the quarry,
  6. -- a full power cell on the East side of the querry,
  7. -- a chunkloading mining turtle running this program facing the power cell from its East side,
  8. -- (ie. the turtle must face West)
  9. -- a "charged power cell" enderchest above the turtle, and
  10. -- a "discharged power cell" enderchest below the turtle.
  11. -- Download this as chquarry and put this code into the "startup" file: shell.run("chquarry")
  12.  
  13. local FUEL_SLOT = 1
  14. local QUARRY_SLOT = 2
  15. local ENERGY_CELL_SLOT = 3
  16. local CHARGED_CELLS_ENDERCHEST_SLOT = 4
  17. local EMPTY_CELLS_ENDERCHEST_SLOT = 5
  18. local ITEMS_ENDERCHEST_SLOT = 6
  19. local TRASH_SLOT = 7
  20. local RELOCATE_DISTANCE = 9
  21. local MIN_FUEL_FOR_CYCLE = RELOCATE_DISTANCE + 12
  22. local STEPS_COUNT = 3
  23. local STEP_SLEEP = 600
  24. local QUARRY_STOP_SLEEP = 30 -- wait for the quarry to stop after disconnecting power
  25.  
  26. function recharge()
  27.     turtle.select(ENERGY_CELL_SLOT)
  28.     turtle.dig()
  29.     turtle.dropDown()
  30.     while turtle.getItemCount(ENERGY_CELL_SLOT)==0 do
  31.         turtle.suckUp()
  32.         if turtle.getItemCount(ENERGY_CELL_SLOT)==0 then
  33.             sleep(1)
  34.         end
  35.     end
  36.     turtle.place()
  37. end
  38.  
  39. function cleanup()
  40.     turtle.select(TRASH_SLOT)
  41.     turtle.dig()
  42.     turtle.digUp()
  43.     turtle.digDown()
  44.     turtle.dropDown()
  45.     turtle.drop()
  46. end
  47.  
  48. function pack()
  49.     turtle.select(ENERGY_CELL_SLOT)
  50.     turtle.dig()
  51.     turtle.dropDown()
  52.     sleep(QUARRY_STOP_SLEEP)
  53.     turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT)
  54.     turtle.digUp()
  55.     turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT)
  56.     turtle.digDown()
  57.     sleep(0.5)
  58.     turtle.forward()
  59.     turtle.select(QUARRY_SLOT)
  60.     turtle.dig()
  61.     sleep(0.5)
  62.     turtle.forward()
  63.     turtle.select(ITEMS_ENDERCHEST_SLOT)
  64.     turtle.dig()
  65.     turtle.turnRight()
  66. end
  67. function unpack()
  68.     cleanup()
  69.     turtle.turnLeft()
  70.     cleanup()
  71.     turtle.select(ITEMS_ENDERCHEST_SLOT)
  72.     turtle.place()
  73.     turtle.turnRight()
  74.     turtle.turnRight()
  75.     cleanup()
  76.     turtle.forward()
  77.     turtle.turnRight()
  78.     turtle.turnRight()
  79.     turtle.select(QUARRY_SLOT)
  80.     turtle.place()
  81.     turtle.turnRight()
  82.     turtle.turnRight()
  83.     cleanup()
  84.     turtle.forward()
  85.     turtle.turnRight()
  86.     turtle.turnRight()
  87.     turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT)
  88.     turtle.placeDown()
  89.     turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT)
  90.     turtle.placeUp()
  91.     recharge()
  92. end
  93. function relocate()
  94.     for i=1,RELOCATE_DISTANCE do
  95.         cleanup()
  96.         turtle.forward()
  97.     end
  98. end
  99. function cycle()
  100.     print("waiting for quarry")
  101.     sleep(STEP_SLEEP)
  102.     for i=1,(STEPS_COUNT-1) do
  103.         print("recharging")
  104.         recharge()
  105.         sleep(STEP_SLEEP)
  106.     end
  107.     print("packing")
  108.     pack()
  109.     print("relocating")
  110.     relocate()
  111.     print("unpacking")
  112.     unpack()
  113. end
  114.  
  115. function check_fuel()
  116.     if turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE then
  117.         -- TODO: try to get fuel from the "charged cells" enderchest
  118.         print("not enough fuel, waiting for fuel")
  119.         while turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE do
  120.             sleep(5)
  121.             turtle.select(FUEL_SLOT)
  122.             turtle.suckUp()
  123.             if turtle.refuel() then
  124.                 moreFuel = True
  125.                 while moreFuel do
  126.                     sleep(3)
  127.                     turtle.suckUp()
  128.                     if not turtle.refuel() then
  129.                         moreFuel = False
  130.                         turtle.dropUp()
  131.                     end
  132.                 end            
  133.             else
  134.                 turtle.dropUp() -- not fuel, return to chest
  135.             end
  136.         end
  137.     end
  138. end
  139.  
  140. -- ***********************************************************************
  141.  
  142. print("starting automated quarry operation")
  143. while true do
  144.     check_fuel()
  145.     cycle()
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement