Advertisement
DaBananaboat

[FTB] Strip Miner v1.1.5

Mar 28th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. local height = 0
  2. local movedBlocks = 0
  3. local direction = "up"
  4. local canMine = true
  5.  
  6. local function FetchItems()
  7.   turtle.suck()
  8.   turtle.suckUp()
  9.   turtle.suckDown()
  10. end
  11.  
  12. local function CheckFuel()
  13.   if turtle.getFuelLevel() == 0 then
  14.     turtle.refuel(1)
  15.   end
  16. end
  17.  
  18. local function PlaceTorch()
  19.   if (movedBlocks % 5 == 0) and (height == 2) then
  20.     turtle.select(2)
  21.     turtle.digUp()
  22.     turtle.placeUp()
  23.     turtle.select(1)
  24.   end
  25. end
  26.  
  27. local function CheckBackpack()
  28.   emptySlots = 0
  29.   for i = 1, 16 do
  30.     if turtle.getItemCount(i) == 0 then
  31.       emptySlots = emptySlots + 1
  32.     end
  33.   end
  34.  
  35.   if emptySlots == 0 then
  36.     canMine = false
  37.   end
  38. end
  39.  
  40. local function TryMove(direction)
  41.   attempt = 1
  42.  
  43.   while true do
  44.     CheckFuel()
  45.     if direction == "up" then
  46.       if turtle.up() == true then
  47.         break
  48.       else
  49.         turtle.digUp()
  50.       end
  51.     elseif direction == "down" then
  52.       if turtle.down() == true then
  53.         break
  54.       else
  55.         turtle.digDown()
  56.       end
  57.     elseif direction == "forward" then
  58.       if turtle.forward() == true then
  59.         break
  60.       else
  61.         turtle.dig()
  62.       end
  63.     elseif direction == "back" then
  64.       if turtle.back() == true then
  65.         break
  66.       end
  67.     end
  68.  
  69.     if attempt > 5 then
  70.       canMine = false
  71.     end
  72.    
  73.     attempt = attempt + 1
  74.   end
  75. end
  76.  
  77. local function TryMine(direction)
  78.   while true do
  79.     if direction == "up" then
  80.       if turtle.detectUp() == true then
  81.         turtle.digUp()
  82.         FetchItems()
  83.       end
  84.     elseif direction == "down" then
  85.       if turtle.detectDown() == true then
  86.         turtle.digDown()
  87.         FetchItems()
  88.       end
  89.     elseif direction == "forward" then
  90.       if turtle.detect() == true then
  91.         turtle.dig()
  92.         FetchItems()
  93.       end
  94.     end
  95.   end
  96. end
  97.  
  98. local function Mine()
  99.   while canMine == true do  
  100.  
  101.     if (movedBlocks > 0) and (movedBlocks % 10 == 0) then
  102.       CheckBackpack()
  103.     end
  104.  
  105.     if turtle.detect() == true then
  106.       TryMine("forward")
  107.     end
  108.    
  109.     TryMove("forward")
  110.     movedBlocks = movedBlocks + 1
  111.    
  112.     for i = 1, 2 do
  113.       PlaceTorch()    
  114.       if (height < 2) and (direction == "up")  then
  115.         if turtle.detectUp() == true then
  116.           TryMine("up")
  117.         end
  118.        
  119.         TryMove(direction)
  120.         height = height + 1
  121.        
  122.         if height == 2 then
  123.           direction = "down"
  124.         end
  125.                        
  126.       elseif (height > 0) and (direction == "down") then
  127.         if turtle.detectDown() == true then
  128.           TryMine("down")
  129.         end
  130.        
  131.         TryMove(direction)
  132.         height = height - 1
  133.        
  134.         if height == 0 then
  135.           direction = "up"
  136.         end
  137.       end      
  138.     end
  139.   end
  140. end
  141.  
  142. CheckFuel()
  143. Mine()
  144.  
  145. for i = 1, height do
  146.   TryMove("down")
  147. end
  148.  
  149. for i = 1, movedBlocks do
  150.   TryMove("back")
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement