portablejim

Strip Mine

Mar 22nd, 2013 (edited)
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. local FUEL = true
  2. local NUM_STRIPS = 32
  3. local STRIP_DISTANCE = 3
  4. local GRAVEL_FALL_TIME = 0.5
  5. local ENDERCHEST_FAIL_WAIT_TIME = 0.5
  6. local SLOT_ENDERCHEST_ITEMS = 1
  7. local SLOT_ENDERCHEST_FUEL = 2
  8. local SLOT_MINING = 2
  9.  
  10. local yieldTime -- variable to store the time of the last yield
  11. local function yield()
  12.         if yieldTime then -- check if it already yielded
  13.                 if os.clock() - yieldTime > 2 then -- if it were more than 2 seconds since the last yield
  14.                         os.queueEvent("someFakeEvent") -- queue the event
  15.                         os.pullEvent("someFakeEvent") -- pull it
  16.                         yieldTime = nil -- reset the counter
  17.                 end
  18.         else
  19.                 yieldTime = os.clock() -- store the time
  20.         end
  21. end
  22.  
  23. function mine1()
  24.     while turtle.detectUp() do
  25.         turtle.digUp()
  26.         sleep(GRAVEL_FALL_TIME)
  27.     end
  28.     while turtle.detect() do
  29.         turtle.dig()
  30.         sleep(GRAVEL_FALL_TIME)
  31.     end
  32.     turtle.digDown()
  33.     while not turtle.forward() do
  34.         turtle.dig()
  35.         sleep(GRAVEL_FALL_TIME)
  36.     end
  37. end
  38.  
  39. function mine1row()
  40.     for i=1,45 do
  41.         mine1()
  42.         yield()
  43.     end
  44. end
  45.  
  46. function mine2rows()
  47.     mine1row()
  48.     turtle.turnLeft()
  49.     for i=1,STRIP_DISTANCE do
  50.         mine1()
  51.         yield()
  52.     end
  53.     turtle.turnLeft()
  54.     mine1row()
  55. end
  56.  
  57. function mineFull(length)
  58.     for i=1,length do
  59.         turtle.select(2)
  60.         turtle.turnRight()
  61.         mine2rows()
  62.         turtle.turnRight()
  63.         if FUEL then
  64.             if turtle.getFuelLevel() < 140 then
  65.                 print "Need fuel ..."
  66.             end
  67.             -- Refuel
  68.             while turtle.getFuelLevel() < 140 do
  69.                 turtle.select(SLOT_ENDERCHEST_FUEL)
  70.                 turtle.digDown() -- Note: Not testing for unmineable blocks.
  71.                 turtle.placeDown()
  72.                 turtle.suckDown()
  73.                 turtle.refuel()
  74.                 turtle.digDown()
  75.                 sleep(10)
  76.             end
  77.         end
  78.         print("Continuing row ", i)
  79.  
  80.         for i=1,STRIP_DISTANCE do
  81.             mine1()
  82.             yield()
  83.         end
  84.  
  85.         turtle.back()
  86.         turtle.select(SLOT_ENDERCHEST_ITEMS)
  87.         while not turtle.place() do -- Place down enderchest
  88.             turtle.dig()
  89.         end
  90.         for j=2,10 do
  91.             turtle.select(j)
  92.             -- Wait if cannot place in enderchest
  93.             while not turtle.drop() and turtle.getItemCount(j) > 0 do
  94.                 print "Enderchest full... waiting to empty slots 2-10"
  95.                 sleep(ENDERCHEST_FAIL_WAIT_TIME)
  96.             end
  97.             yield()
  98.         end
  99.         sleep(1) -- Allow time to empty enderchest
  100.         for j=11,16 do
  101.             turtle.select(j) -- Place remaining 6 slots into enderchest
  102.             while not turtle.drop() and turtle.getItemCount(j) > 0 do
  103.                 print "Enderchest full... waiting to empty slots 11-16"
  104.                 sleep(ENDERCHEST_FAIL_WAIT_TIME)
  105.             end
  106.             yield()
  107.         end
  108.         turtle.select(SLOT_ENDERCHEST_ITEMS)
  109.         turtle.dig() -- Pick up enderchest
  110.         while turtle.detect() do
  111.             turtle.dig()
  112.             yield()
  113.         end
  114.         turtle.forward()
  115.         yield()
  116.     end
  117. end
  118.  
  119. function mineReturn()
  120.     mineFull(NUM_STRIPS)
  121.  
  122.     turtle.turnRight()
  123.     turtle.turnRight()
  124.     totalDistance = NUM_STRIPS * STRIP_DISTANCE * 2
  125.     for i=1,totalDistance do
  126.         mine1()
  127.         yield()
  128.     end
  129. end
Add Comment
Please, Sign In to add comment