Advertisement
Schneiderism

[FTB Turtle] Strip Mining Program V2

Dec 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. lightLevel = 0
  2. distance = 0
  3. runs = 0
  4.  
  5. function checkFuel()
  6.     if turtle.getFuelLevel() <= 10 then
  7.         turtle.select(16)
  8.         if turtle.getItemCount() > 0 then
  9.             turtle.refuel(1)
  10.             turtle.select(1)
  11.         -- elseif turtle.getItemCount < 1 then
  12.         --  for i = 1, 13 do
  13.         --      turtle.select(i)
  14.         else
  15.             print("Out of fuel! Terminating program.")
  16.             error()
  17.         end --if statement
  18.     end --if statement
  19. end --function
  20.  
  21. function torchCount()
  22.     if lightLevel == 11 then
  23.         turtle.select(15)
  24.         if turtle.getItemCount() > 0 then
  25.             turtle.turnLeft()
  26.             turtle.dig()
  27.             turtle.place()
  28.             turtle.turnRight()
  29.             turtle.select(1)
  30.             lightLevel = 0
  31.         else
  32.             print("Out of torches! Terminating program.")
  33.             lightLevel = 0
  34.             error()
  35.         end --if statement
  36.     end --if statement
  37. end --function
  38.  
  39. function digInFront()
  40.     turtle.dig()
  41.     turtle.forward()
  42.     turtle.digUp()
  43. end --function
  44.  
  45. function positionNextTunnelRight()
  46.     turtle.turnRight()
  47.     rightRuns = 0
  48.     while rightRuns < 3
  49.         turtle.dig()
  50.         turtle.forward()
  51.         turtle.digUp()
  52.         rightRuns = rightRuns + 1
  53.     end --while function
  54.     turtle.turnRight()
  55. end --function
  56.  
  57. function positionNextTunnelLeft()
  58.     turtle.turnLeft()
  59.     leftRuns = 0
  60.     while leftRuns < 3
  61.         turtle.dig()
  62.         turtle.forward()
  63.         turtle.digUp()
  64.         leftRuns = leftRuns + 1
  65.     end --while function
  66.     turtle.turnLeft()
  67. end --function
  68.  
  69. function checkInv()
  70.     turtle.select (13)
  71.     if turtle.getItemCount() > 0 then
  72.         turtle.select(14)
  73.         if turtle.getItemCount() > 0 then
  74.             turtle.digDown()
  75.             turtle.place()
  76.             for i = 1, 13 do
  77.                 turtle.select(1)
  78.                 turtle.dropDown()
  79.             end --while loop
  80.             turtle.select(1)
  81.         else
  82.             print("Out of storage chests! Terminating program.")
  83.             error()
  84.         end --itemCount chest function
  85.     end --inventory check function
  86. end --function
  87.  
  88. --[[THIS IS WHERE THE MAIN PROGRAM STARTS]]--
  89.  
  90. -- Defines the length of the tunnels
  91. print("How long should the tunnels be?")
  92. length = tonumber(read())
  93.  
  94. -- Defines the number of tunnels
  95. print("How many individual tunnels should be dug?")
  96. count = tonumber(read())
  97.  
  98. -- Confirmation message
  99. print("Now excavating the tunnels!")
  100.  
  101. while runs < count do
  102.     checkFuel()
  103.     torchCount()
  104.     if distance < length then
  105.         digInFront()
  106.         distance = distance + 1
  107.     else
  108.         if runs % 2 == 0 then
  109.             positionNextTunnelRight()
  110.             runs = runs + 1
  111.             distance = 0
  112.         else
  113.             positionNextTunnelLeft()
  114.             runs = runs + 1
  115.             distance = 0
  116.         end --Check turn direction
  117.     end --Digging tunnels
  118.     checkInv()
  119.     lightLevel = lightLevel + 1
  120. end --Function
  121.  
  122. if runs % 2 == 0 then
  123.     positionNextTunnelRight()
  124. else
  125.     positionNextTunnelLeft()
  126. end --Check turn direction
  127.  
  128. print("The tunnels are complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement