Advertisement
Guest User

Mine

a guest
Feb 6th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. local function clear()
  2.     term.clear()
  3.     term.setCursorPos(1, 1)
  4. end
  5.  
  6. local setupDone = true
  7. local currY = 0
  8. local startY = 0
  9. local workY = 0
  10. local size = 0
  11.  
  12. clear()
  13. print("Size?")
  14. print("")
  15. write("   ")
  16. size = read()
  17. size = tonumber(size)
  18. if not size then
  19.     clear()
  20.     print("That wasn't a number, idiot.")
  21.     setupDone = false
  22. else
  23.     if size < 3 then
  24.         clear()
  25.         print("Too small! I'm no mining well, asshole.")
  26.         setupDone = false
  27.     else
  28.         clear()
  29.         print("My current Y coordinate?")
  30.         print("")
  31.         write("   ")
  32.         currY = read()
  33.         currY = tonumber(currY)
  34.         if not currY then
  35.             clear()
  36.             print("That wasn't a number, idiot.")
  37.             setupDone = false
  38.         else
  39.             startY = currY
  40.         end
  41.     end
  42. end
  43.  
  44. local function dig()
  45.     while turtle.detect() == true do
  46.         turtle.dig()
  47.     end
  48.     if turtle.getFuelLevel() > 30 then
  49.         turtle.forward()
  50.     else
  51.         if turtle.getItemCount(1) > 1 then
  52.             turtle.select(1)
  53.             turtle.refuel(1)
  54.             turtle.forward()
  55.         else
  56.             clear()
  57.             print("Out of usable fuel. Stoping.")
  58.             print("Now crashing the program!")
  59.             print("")
  60.             exit()
  61.         end
  62.     end
  63. end
  64.  
  65. local function row()
  66.     for i = 1, size-1 do
  67.         dig()
  68.     end
  69. end
  70.  
  71. local function layer()
  72.     if size % 2 == 0 then
  73.         for i = 1, (size/2)-1 do
  74.             row()
  75.             turtle.turnLeft()
  76.             dig()
  77.             turtle.turnLeft()
  78.             row()
  79.             turtle.turnRight()
  80.             dig()
  81.             turtle.turnRight()
  82.         end
  83.         row()
  84.         turtle.turnLeft()
  85.         dig()
  86.         turtle.turnLeft()
  87.         row()
  88.         turtle.turnLeft()
  89.         row()
  90.         turtle.turnRight()
  91.     else
  92.         for i = 1, (size-1)/2 do
  93.             row()
  94.             turtle.turnLeft()
  95.             dig()
  96.             turtle.turnLeft()
  97.             row()
  98.             turtle.turnRight()
  99.             dig()
  100.             turtle.turnRight()
  101.         end
  102.         row()
  103.         turtle.turnRight()
  104.         row()
  105.         turtle.turnRight()
  106.         row()
  107.     end
  108. end
  109.  
  110. local function mine()
  111.     clear()
  112.     workY = currY
  113.     while workY > 1 do
  114.         turtle.digDown()
  115.         turtle.down()
  116.         currY = currY-1
  117.         workY = currY
  118.         print("Working on Y = "..workY)
  119.         layer()
  120.         while currY < startY do
  121.             if turtle.detectUp() then
  122.                 turtle.digUp()
  123.             end
  124.             turtle.up()
  125.             currY = currY+1
  126.         end
  127.         for i = 2, 16 do
  128.             turtle.select(i)
  129.             turtle.drop(turtle.getItemCount(i))
  130.         end
  131.         turtle.turnLeft()
  132.         turtle.turnLeft()
  133.         if workY == 1 then
  134.             print("Done")
  135.         else
  136.             while currY > workY do
  137.                 if turtle.detectDown() then
  138.                     turtle.digDown()
  139.                 end
  140.                 turtle.down()
  141.                 currY = currY-1
  142.             end
  143.         end
  144.     end
  145. end
  146.  
  147. if setupDone == true then
  148.     mine()
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement