Advertisement
Schneiderism

[FTB Turtle] Strip Mining Program {Custom Length and Count}

Nov 24th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 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.turnLeft()
  47.     leftRuns = 0
  48.     while leftRuns < 2 do
  49.         turtle.dig()
  50.         turtle.forward()
  51.         turtle.digUp()
  52.         leftRuns = leftRuns + 1
  53.     end --while/do statement
  54.  
  55.     turtle.turnRight()
  56.     turtle.turnRight()
  57.     rightRuns = 0
  58.     while rightRuns < 6 do
  59.         turtle.dig()
  60.         turtle.forward()
  61.         turtle.digUp()
  62.         rightRuns = rightRuns + 1
  63.     end --while function
  64.     turtle.turnRight()
  65. end --function
  66.  
  67. function positionNextTunnelLeft()
  68.     turtle.turnRight()
  69.     rightRuns = 0
  70.     while rightRuns < 2 do
  71.         turtle.dig()
  72.         turtle.forward()
  73.         turtle.digUp()
  74.         rightRuns = rightRuns + 1
  75.     end --while/do statement
  76.  
  77.     turtle.turnLeft()
  78.     turtle.turnLeft()
  79.     leftRuns = 0
  80.     while leftRuns < 6 do
  81.         turtle.dig()
  82.         turtle.forward()
  83.         turtle.digUp()
  84.         leftRuns = leftRuns + 1
  85.     end --while function
  86.     turtle.turnLeft()
  87. end --function
  88.  
  89.  
  90. function checkInv()
  91.     turtle.select(13)
  92.     if turtle.getItemCount() > 0 then
  93.         turtle.select(14)
  94.         if turtle.getItemCount() > 0 then
  95.             turtle.digDown()
  96.             turtle.placeDown()
  97.             for i = 1, 13 do
  98.                 turtle.select(i)
  99.                 turtle.dropDown()
  100.             end --while loop
  101.             turtle.select(1)
  102.         else
  103.             print("Out of storage chests! Terminating program.")
  104.             error()
  105.         end --itemCount chest function
  106.     end --inventory check function
  107.     turtle.select(1)
  108. end --function
  109.  
  110. --[[THIS IS WHERE THE MAIN PROGRAM STARTS]]--
  111.  
  112. -- Defines the length of the tunnels
  113. print("How long should the tunnels be?")
  114. length = tonumber(read())
  115.  
  116. -- Defines the number of tunnels
  117. print("How many individual tunnels should be dug?")
  118. count = tonumber(read())
  119.  
  120. -- Confirmation message
  121. print("Now excavating the tunnels!")
  122.  
  123. while runs < count do
  124.     checkFuel()
  125.     torchCount()
  126.     if distance < length then
  127.         digInFront()
  128.         distance = distance + 1
  129.     else
  130.         if runs % 2 == 0 then
  131.             positionNextTunnelRight()
  132.             runs = runs + 1
  133.             distance = 0
  134.         else
  135.             positionNextTunnelLeft()
  136.             runs = runs + 1
  137.             distance = 0
  138.         end --Check turn direction
  139.     end --Digging tunnels
  140.     checkInv()
  141.     lightLevel = lightLevel + 1
  142. end --Function
  143.  
  144. if runs % 2 == 0 then
  145.     positionNextTunnelRight()
  146. else
  147.     positionNextTunnelLeft()
  148. end --Check turn direction
  149.  
  150. print("The tunnels are complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement