Advertisement
danlemberg

stripmine

Jun 28th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 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 move forward")
  6. print("one block and then mine in a X by Y grid.")
  7. print("Be sure to fuel the turtle before mining.")
  8.  
  9. print("")
  10. print("How many squares forward should it mine?")
  11. local x = tonumber(read())
  12.  
  13. print("")
  14. print("How many squares right should it mine?")
  15. local y = tonumber(read())
  16.  
  17. print("")
  18. print("How many squares down should it mine? (0 = to bedrock)")
  19. local z = tonumber(read())
  20.  
  21. if z == 0 then
  22.     z = 999
  23. end
  24.  
  25. if x < 1 or y < 1 or z < 1 then
  26.   error("Invalid arguments")
  27. end
  28.  
  29. print("")
  30.  
  31. -- function to move the turtle
  32. -- with up to five retries
  33.  
  34. local function go(movefunc)
  35.  
  36.   local moved = false
  37.   local retry = 0
  38.  
  39.   while moved == false and retry < 10 do
  40.  
  41.     if retry > 0 then
  42.       if movefunc == turtle.forward and turtle.detect() == false then
  43.         turtle.attack()
  44.       end
  45.       os.sleep(0.5)
  46.     end
  47.  
  48.     if movefunc == turtle.forward and turtle.detect() then
  49.       turtle.dig()
  50.     end
  51.  
  52.     moved = movefunc()
  53.     retry = retry + 1
  54.  
  55.   end
  56.  
  57.   if moved == false then
  58.     error("failed to move turtle")
  59.   end
  60.  
  61. end
  62.  
  63. -- docking station is assumed to be 0,1
  64. -- chest is assumed to be -1,1
  65.  
  66. for loopy=1,y do
  67.   for loopx=1,x do
  68.  
  69.     -- check fuel level
  70.  
  71.     if turtle.getFuelLevel() < (loopx + loopy + 128) then
  72.       error("Not enough fuel")
  73.     end
  74.  
  75.     -- go to the initial square (1,1)
  76.  
  77.     go(turtle.forward)
  78.  
  79.     -- find the column we are working on
  80.  
  81.     col = 1
  82.     turtle.turnRight()
  83.  
  84.     while col < loopy do
  85.       go(turtle.forward)
  86.       col = col + 1
  87.     end
  88.  
  89.     -- find the row we are working on
  90.  
  91.     row = 1
  92.     turtle.turnLeft()
  93.  
  94.     while row < loopx do
  95.       go(turtle.forward)
  96.       row = row + 1
  97.     end
  98.  
  99.     -- dig to bedrock
  100.  
  101.     depth = 0
  102.  
  103.     while depth < z and (turtle.detectDown() == false or turtle.digDown()) do
  104.       go(turtle.down)
  105.       depth = depth + 1
  106.     end
  107.  
  108.     for loopz=1,depth do
  109.       go(turtle.up)
  110.     end
  111.  
  112.     -- return home
  113.     turtle.turnLeft()
  114.  
  115.     while col > 1 do
  116.       go(turtle.forward)
  117.       col = col - 1
  118.     end
  119.  
  120.     turtle.turnLeft()
  121.  
  122.     while row > 0 do
  123.       go(turtle.forward)
  124.       row = row - 1
  125.     end
  126.  
  127.     for i=1,16 do
  128.       turtle.select(i)
  129.       turtle.drop()
  130.     end
  131.  
  132.     turtle.turnRight()
  133.     turtle.turnRight()
  134.  
  135.   end
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement