Advertisement
chibudesu

Quarry

Oct 28th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local SLOT_ENDERCHEST = 1
  2. local SLOT_QUARRY     = 2
  3. local SLOT_PRODUCER   = 3
  4. local SLOT_BRIDGE     = 4
  5. local SLOT_CONSUMER   = 5
  6. local SLOT_SOLARPANEL = 6
  7.  
  8. local MAX_QUARRY_TIME = 1800
  9.  
  10. local tArgs = { ... }
  11.  
  12. local select    = turtle.select
  13. local dig       = turtle.dig
  14. local digDown   = turtle.digDown
  15. local digUp     = turtle.digUp
  16. local place     = turtle.place
  17. local placeDown = turtle.placeDown
  18. local placeUp   = turtle.placeUp
  19. local down      = turtle.down
  20. local up        = turtle.up
  21. local turnLeft  = turtle.turnLeft
  22. local turnRight = turtle.turnRight
  23. local drop      = turtle.drop
  24.  
  25. function forward(dist)
  26.   dist = dist or 1
  27.   for i=1,tonumber(dist) do
  28.     local forward = turtle.forward()
  29.     if (not forward and not turtle.up()) then
  30.       return false
  31.     else
  32.       i = i - 1
  33.     end
  34.   end
  35. end
  36.  
  37. function back(dist)
  38.   dist = dist or 1
  39.   for i=1,tonumber(dist) do
  40.     local back = turtle.back()
  41.     if (not forward and not turtle.up()) then
  42.       return false
  43.     else
  44.       i = i - 1
  45.     end
  46.   end
  47. end
  48.  
  49. function setupQuarry()
  50.   turnLeft()
  51.   select(SLOT_ENDERCHEST)
  52.   placeUp()
  53.   down()
  54.   select(SLOT_QUARRY)
  55.   placeUp()
  56.   back()
  57.   select(SLOT_PRODUCER)
  58.   placeUp()
  59.   back()
  60.   select(SLOT_BRIDGE)
  61.   placeUp()
  62.   back()
  63.   select(SLOT_CONSUMER)
  64.   placeUp()
  65.   back()
  66.   select(SLOT_SOLARPANEL)
  67.   placeUp()
  68.   forward(4)
  69. end
  70.  
  71. function emptyInv()
  72.   for i=7,16 do
  73.     select(i)
  74.     drop()
  75.   end
  76. end
  77.  
  78. function teardownQuarry(delay)
  79.   delay = delay or 30
  80.   back(4)
  81.   --select(SLOT_ENDERCHEST)
  82.   --place()
  83.   --emptyInv()
  84.   --select(SLOT_ENDERCHEST)
  85.   --dig()
  86.   select(SLOT_SOLARPANEL)
  87.   digUp()
  88.   forward()
  89.   select(SLOT_CONSUMER)
  90.   digUp()
  91.   forward()
  92.   select(SLOT_BRIDGE)
  93.   digUp()
  94.   forward()
  95.   select(SLOT_PRODUCER)
  96.   digUp()
  97.   sleep(tonumber(delay))
  98.   forward()
  99.   select(SLOT_QUARRY)
  100.   digUp()
  101.   up()
  102.   select(SLOT_ENDERCHEST)
  103.   digUp()
  104.   turnRight()
  105. end
  106.  
  107. function active()
  108.   return (peripheral.call('top', 'isActive') == "true")
  109. end
  110.  
  111. if #tArgs > 0 then
  112.   teardownQuarry(1)
  113. end
  114.  
  115. while true do
  116.   forward(9)
  117.   setupQuarry()
  118.   if not active() then
  119.     print("Error: Couldn't connect quarry as peripheral")
  120.     teardownQuarry()
  121.     break
  122.   end
  123.   local start = os.clock()
  124.   while active() do
  125.     sleep(5)
  126.     if (os.clock() - start) > MAX_QUARRY_TIME then
  127.       break
  128.     end
  129.   end
  130.   teardownQuarry()
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement