Q009

ComputerCraft turtle program - mining layer

Aug 2nd, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local usedFuel = 0
  2.  
  3. function fuelChk()
  4.     if turtle.getFuelLevel() < 20 then
  5.         turtle.select(1)
  6.         if turtle.refuel(1) == false then
  7.             print("Out of fuel!")
  8.             exit()
  9.         end
  10.         usedFuel = usedFuel + 1
  11.     end
  12. end
  13.  
  14. function doStuffAndThings()
  15.     print("Thank you for using our amazing freaking program")
  16.     print("Q009 says hello")
  17.     print("Please specify length of the area")
  18.     local len = io.read()
  19.     print("Please specify width of the area")
  20.     local width = io.read()
  21.     len = tonumber(len)
  22.     width = tonumber(width)
  23.     local foundMats = 0
  24.     if len < 4 then len = 4 end
  25.     if width < 4 then width = 4 end
  26.    
  27.     fuelChk()
  28.     while turtle.detect() do
  29.         turtle.dig()
  30.         sleep(0.5)
  31.     end
  32.  
  33.     turtle.forward()
  34.     for i = 1, len, 1 do
  35.         fuelChk()
  36.         if i % 2 == 0 then turtle.turnRight()
  37.         else turtle.turnLeft() end
  38.         for j = 1, width, 1 do
  39.             turtle.select(2)
  40.             if turtle.detectDown() and turtle.compareDown()
  41.             then
  42.                 turtle.digDown()
  43.                 foundMats = foundMats + 1
  44.             end
  45.  
  46.             while (turtle.detect()) and (j < width) do
  47.                 turtle.dig()
  48.                 sleep(0.5)
  49.             end
  50.             if j < width then turtle.forward() end
  51.         end
  52.  
  53.         if i % 2 == 0 then turtle.turnLeft()
  54.         else turtle.turnRight() end
  55.         while turtle.detect() do
  56.             turtle.dig()
  57.             sleep(0.5)
  58.         end
  59.         turtle.forward()
  60.     end
  61.    
  62.     turtle.back()
  63.     if len % 2 ~= 0 then
  64.         turtle.turnRight()
  65.         for i = 1, width, 1 do turtle.forward() end
  66.         turtle.turnLeft()
  67.     end
  68.     turtle.turnLeft() turtle.turnLeft()
  69.     for i = 1, len, 1 do turtle.forward() end
  70.     print("Done! Used fuel: " .. usedFuel .. " | ammount mined material: " .. foundMats)
  71. end
  72.  
  73. doStuffAndThings()
Advertisement
Add Comment
Please, Sign In to add comment