spenk

CC turtle

Jul 3rd, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local x, y, z, running, rot
  2. rot = "left"
  3. dir = "Top"
  4.  
  5.  
  6. function mine()
  7.   if turtle.detect() then
  8.     turtle.dig()
  9.     sleep(0.5)
  10.     mine()
  11.   else
  12.     turtle.forward()
  13.   end
  14. end
  15.  
  16. function turn()
  17.   if rot == "left" then
  18.     turtle.turnLeft()
  19.     mine()
  20.     turtle.turnLeft()
  21.     rot = "right"
  22.   else
  23.     turtle.turnRight()
  24.     mine()
  25.     turtle.turnRight()
  26.     rot = "left"
  27.   end
  28. end
  29.  
  30. function ascend()
  31.   if dir == "top" then
  32.     turtle.digUp()
  33.     turtle.up()
  34.   else
  35.     turtle.digDown()
  36.     turtle.down()
  37.   end
  38.   turtle.turnRight()
  39.   turtle.turnRight()
  40. end
  41.  
  42. function checkFuelNeed()
  43.   if turtle.getFuelLevel() < 1 then
  44.     for i = 1, 16 do -- loop through the slots
  45.       turtle.select(i) -- change to the slot
  46.       if turtle.refuel(0) then -- if it's valid fuel
  47.         turtle.refuel(1) -- consume half the stack as fuel
  48.         return true
  49.       end
  50.     end
  51.     return false
  52.   end
  53. end
  54.  
  55. function awaitFuel()
  56.   while checkFuelNeed() == false do
  57.     print "Please feed me!"
  58.     os.sleep(5)
  59.   end
  60. end
  61.  
  62. function runMiner()
  63.   for ly = y, 1, -1 do
  64.     for lz = z, 1, -1 do
  65.       for lx = x, 2, -1 do
  66.         awaitFuel()
  67.         mine()
  68.         print "mine"
  69.       end
  70.       if lz ~= 1 then
  71.         turn()
  72.         print "turn"
  73.       else
  74.         print "Fail turn"
  75.       end
  76.     end
  77.     if ly ~= 1 then
  78.       ascend()
  79.       print "ascend"
  80.     else
  81.       print "Fail ascend"
  82.     end
  83.   end
  84.   print "Done"
  85. end
  86.  
  87. function init()
  88.   print("Please enter the width of the quary")
  89.   x = read()
  90.   print("Please enter the height of the quary")
  91.   y = read()
  92.   print("Please enter the depth of the quary")
  93.   z = read()
  94.   print("Please enter the direction to dig to (left|right)")
  95.   rot = read()
  96.   print("Please enter the direction to dig to (top|bottom)")
  97.   dir = read()
  98.   runMiner()
  99. end
  100.  
  101. init()
Advertisement
Add Comment
Please, Sign In to add comment