Advertisement
Guest User

stripmine

a guest
Jun 28th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. print("Mining program")
  2.  
  3. print("")
  4. print("Place turtle on the surface facing away")
  5. print("from a chest.  Turtle will dig down to")
  6. print("bedrock and then come back up and place")
  7. print("blocks in the chest.  It will continue to")
  8. print("mine in a grid until it reaches the max")
  9. print("grid size that you specify.")
  10. print("Be sure to fuel the turtle before mining.")
  11.  
  12. print("")
  13. print("How many squares forward should it mine?")
  14. local x = tonumber(read())
  15.  
  16. print("")
  17. print("How many squares right should it mine?")
  18. local y = tonumber(read())
  19.  
  20. print("")
  21.  
  22. -- function to move the turtle
  23. -- with up to three retries
  24.  
  25. local function go(movefunc)
  26.  
  27.   local moved = false
  28.   local retry = 0
  29.  
  30.   while moved == false and retry < 3 do
  31.  
  32.     if retry > 0 then
  33.       os.sleep(0.25)
  34.     end
  35.  
  36.     moved = movefunc()
  37.     retry = retry + 1
  38.  
  39.   end
  40.  
  41.   if moved == false then
  42.     error("failed to move turtle")
  43.   end
  44.  
  45. end
  46.  
  47. isMore = true
  48. lasty = -1
  49. lastx = -1
  50.  
  51. while isMore do
  52.  
  53.   if turtle.getFuelLevel() < (x + y + 128) then
  54.     error("Not enough fuel")
  55.   end
  56.  
  57.   -- go to the initial square (1,1)
  58.  
  59.   loopy = 1
  60.   loopx = 1
  61.  
  62.   if turtle.detect() then
  63.     turtle.dig()
  64.   end
  65.  
  66.   go(turtle.forward)
  67.  
  68.   -- find the column we are working on
  69.   -- go right until you hit a wall
  70.   -- or hit the end of the grid
  71.  
  72.   turtle.turnRight()
  73.  
  74.   if lasty < 0 then
  75.     while loopy < y and turtle.detect() == false do
  76.       go(turtle.forward)
  77.       loopy = loopy + 1
  78.     end
  79.   else
  80.   end
  81.  
  82.   -- find the row we are working on
  83.   -- go forward until you hit a wall
  84.   -- or get to the end of the grid
  85.  
  86.   turtle.turnLeft()
  87.  
  88.   if lastx < 0 then
  89.     while loopx < x and turtle.detect() == false do
  90.       go(turtle.forward)
  91.       loopx = loopx + 1
  92.     end
  93.   else
  94.   end
  95.  
  96.   -- if we got to the end of the column
  97.   -- and had finished the whole thing
  98.   -- go back and start a new column
  99.   -- otherwise this is the spot
  100.  
  101.   if loopx < x then
  102.  
  103.     turtle.dig()
  104.     go(turtle.forward)
  105.     loopx = loopx + 1
  106.  
  107.   elseif loopy < y then
  108.  
  109.     turtle.turnRight()
  110.     turtle.turnRight()
  111.  
  112.     while loopx > 1 do
  113.       go(turtle.forward)
  114.       loopx = loopx - 1
  115.     end
  116.  
  117.     turtle.turnLeft()
  118.     turtle.dig()
  119.  
  120.     go(turtle.forward)
  121.     loopy = loopy + 1
  122.  
  123.     turtle.turnLeft()
  124.  
  125.   else
  126.     isMore = false
  127.   end
  128.  
  129.   if isMore == true then
  130.  
  131.     z = 0
  132.  
  133.     while turtle.detectDown() == false or turtle.digDown() do
  134.       go(turtle.down)
  135.       z = z + 1
  136.     end
  137.  
  138.     for loopz=1,z do
  139.       go(turtle.up)
  140.     end
  141.   end
  142.  
  143.   -- return home
  144.  
  145.   turtle.turnLeft()
  146.  
  147.   while loopy > 1 do
  148.     go(turtle.forward)
  149.     loopy = loopy - 1
  150.   end
  151.  
  152.   turtle.turnLeft()
  153.  
  154.   while loopx > 0 do
  155.     go(turtle.forward)
  156.     loopx = loopx - 1
  157.   end
  158.    
  159.   for i=1,16 do
  160.     turtle.select(i)
  161.     turtle.drop()
  162.   end
  163.  
  164.   turtle.turnRight()
  165.   turtle.turnRight()
  166.  
  167. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement