McKillopBK

EnderMine

Jan 2nd, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. local times = 0
  2. local j = 0
  3.  
  4. function Mine()
  5.   while turtle.detect() == true do
  6.     turtle.dig()
  7.     sleep(0.50)
  8.   end
  9.   turtle.forward()
  10.   sleep(0.50)
  11.   while turtle.detectUp() == true do
  12.     turtle.digUp()
  13.     sleep(0.50)
  14.   end
  15.   turtle.digDown()
  16. end
  17.  
  18. function Place(SlotNum)
  19.   turtle.select(SlotNum)
  20.   turtle.back()
  21.   turtle.placeUp()
  22.   turtle.forward()
  23. end
  24.  
  25. function PlaceChest(SlotNum)
  26.   turtle.select(SlotNum)
  27.   turtle.back()
  28.   turtle.placeDown()
  29.   for I=1, 14 do
  30.     turtle.select(I)
  31.     turtle.dropDown()
  32.   end
  33. end
  34. print("Place ender chest in slot 15.")
  35. print("Place torches in slot 16.")
  36. term.write("How long is the mineshaft? ")
  37. times = read()
  38.  
  39. function Digger()
  40.   for i=1, times do
  41.     j = j+1
  42.     Mine()
  43.     if j == 9 then
  44.           Place(16)
  45.           j = 0
  46.     end
  47.  
  48.     if turtle.getItemCount(14) >= 1 then
  49.     PlaceChest(15)
  50.     print("Sleeping for 5 Seconds")
  51.     sleep(5)
  52.     turtle.select(15)
  53.     turtle.digDown()
  54.     Mine()
  55.     end
  56.   end
  57. end
  58.  
  59. function MoveRight()
  60.   turtle.turnRight()
  61.   Mine()
  62.   Mine()
  63.   Place(16)
  64.   Mine()
  65.   turtle.turnRight()
  66. end
  67.  
  68. function MoveLeft()
  69.   turtle.turnLeft()
  70.   Mine()
  71.   Mine()
  72.   Place(16)
  73.   Mine()
  74.   turtle.turnLeft()
  75. end
  76.  
  77. function CheckFuel()
  78.   if turtle.getFuelLevel() <= 1000 then
  79.     term.write("Low Fuel, Please refuel. Hit any key to continue.")
  80.     os.pullEvent("char")
  81.   end
  82. end
  83.  
  84. function EnderChest()
  85.   Mine()
  86.   PlaceChest(15)
  87.   print("Sleeping for 5 Seconds")
  88.   sleep(5)
  89.   turtle.select(15)
  90.   turtle.digDown()
  91. end
  92.  
  93. term.write("How many double shafts? ")
  94. duration = read()
  95.  
  96. term.write("Which direction are you mining? ")
  97. direction = read()
  98.  
  99. while( not (direction == "left" or direction == "right") ) do
  100.         term.write("Invalid Answer! Try again (left/right): ")
  101.         direction = read()
  102.     end
  103.     if direction == "left" then
  104.         print("Mining Left")
  105.         for i=1, duration do
  106.           CheckFuel()
  107.           Digger()
  108.           MoveLeft()
  109.           Digger()
  110.           MoveRight()
  111.         end
  112.         EnderChest()
  113.     else
  114.         print("Mining Right")
  115.         for i=1, duration do
  116.           CheckFuel()
  117.           Digger()
  118.           MoveRight()
  119.           Digger()
  120.           MoveLeft()
  121.         end
  122.         EnderChest()
  123.     end
Add Comment
Please, Sign In to add comment