Advertisement
Guest User

turtle_tunnel

a guest
Sep 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. -- Turtle Tunnel v2
  2. -- Various improvements
  3. -- TODO: Implement offset.
  4. -- TODO: Implement z-axis.
  5. -- TODO: Implement chest drop off and
  6. --       calculate fuel used.
  7. -- TODO: More updates to screen when running.
  8. -- TODO: Implement different modes (Make stairs,
  9. --       mine for ore, quarry, etc.
  10. -- FIX:  Incorrect percentages
  11. -- FIX:  Odd number of on y axis goes back
  12. --       1 space too far
  13.  
  14.  
  15. xoffset = "left"
  16. x = 0
  17. y = 0
  18. z = 0
  19. neededFuel = 0
  20. blockNum = 0
  21. termColorDefault = 1
  22. termColorAlert = 1 -- 16384 Color not supported :c
  23.  
  24.  
  25. function Intro()
  26.   term.clear()
  27.   term.setCursorPos(1,1)
  28.   print("From where the turtle is placed, which way do you want it to go?")
  29.   term.setTextColor(termColorAlert)
  30.   print("right/left:")
  31.   term.setTextColor(termColorDefault)
  32.   xoffset = string.lower(io.read())
  33.   while xoffset ~= "right" and xoffset ~= "left" do
  34.     print("You must type 'right' or 'left' without the quotes")
  35.     term.setTextColor(termColorAlert)
  36.     print("right/left:")
  37.     term.setTextColor(termColorDefault)
  38.     xoffset = string.lower(io.read())
  39.   end
  40.   print()
  41.   print("How far to the ",xoffset," will the turtle go?:")
  42.   term.setTextColor(termColorAlert)
  43.   print("Enter number:")
  44.   term.setTextColor(termColorDefault)
  45.   x = tonumber(io.read())
  46.   while not x do
  47.     term.setTextColor(termColorAlert)
  48.     print("You must enter a number:")
  49.     term.setTextColor(termColorDefault)
  50.     x = tonumber(io.read())
  51.   end
  52.   print()
  53.   print("How far forward will the turtle go?:")
  54.   term.setTextColor(termColorAlert)
  55.   print("Enter number:")
  56.   term.setTextColor(termColorDefault)
  57.   y = tonumber(io.read())
  58.   while not y do
  59.     term.setTextColor(termColorAlert)
  60.     print("You must enter a number:")
  61.     term.setTextColor(termColorDefault)
  62.     y = tonumber(io.read())
  63.   end
  64.  
  65.   print()
  66.   neededFuel = x*y+(y+2)
  67.   -- Checks turtle fuel level
  68.   while turtle.getFuelLevel() < neededFuel do
  69.     term.clear()
  70.     term.setCursorPos(1,1)
  71.     print("Your turtle doesn't have enough fuel to go the specified distance")
  72.     print("Current fuel: ", turtle.getFuelLevel())
  73.     print("Needed fuel: ", neededFuel)
  74.     print("Would you like to add fuel now?")
  75.     print("y/n")
  76.     input = string.lower(io.read())
  77.     while input ~= "y" and input ~= "yes" and input ~= "n" and input ~= "no" do
  78.       print("y/n")
  79.       input = string.lower(io.read())
  80.     end
  81.     if input == "y" or input == "yes" then
  82.       print("Add fuel to turtle inventory, then press enter")
  83.       print("This will consume all fuel in turtle")
  84.       io.read()
  85.       for i = 1, 16 do
  86.         turtle.select(i)
  87.         turtle.refuel()
  88.       end
  89.       turtle.select(1)
  90.     else
  91.       break
  92.     end
  93.   end
  94.  
  95.   term.clear()
  96.   term.setCursorPos(1,1)
  97.   print("Your turtle will go ",x," blocks to the ",xoffset," and ",y," blocks forward.")
  98.   print("Current fuel: ",turtle.getFuelLevel())
  99.   print("Needed fuel: ",neededFuel)
  100.   print("Is this correct?")
  101.   term.setTextColor(termColorAlert)
  102.   print("y/n:")
  103.   term.setTextColor(termColorDefault)
  104.   input = string.lower(io.read())
  105.   while input ~= "y" and input ~= "yes" and input ~= "n" and input ~= "no" do
  106.     term.setTextColor(termColorAlert)
  107.     print("y/n:")
  108.     term.setTextColor(termColorDefault)
  109.     input = string.lower(io.read())
  110.   end
  111.   if input == "y" or input == "yes" then
  112. --    UpdateScreen(0)
  113.     --Starting to mine!
  114.     MineTunnel()
  115. --    UpdateScreen(y)
  116.   elseif input == "n" or input == "no" then
  117.     print("Try again?")
  118.     term.setTextColor(termColorAlert)
  119.     print("y/n:")
  120.     term.setTextColor(termColorDefault)
  121.     input = string.lower(io.read())
  122.     while input ~= "y" and input ~= "yes" and input ~= "n" and input ~= "no" do
  123.       term.setTextColor(termColorAlert)
  124.       print("y/n")
  125.       term.setTextColor(termColorDefault)
  126.       input = string.lower(io.read())
  127.     end
  128.     if input == "y" or input == "yes" then
  129.       Intro()
  130.     else
  131.       --Closes program
  132.       error()
  133.     end
  134.   end
  135. end
  136.  
  137. -- Movement loop
  138. function SafeMove(blockNum, mineAround)
  139.   for i = 1, blockNum do
  140.     if mineAround then
  141.      turtle.digUp()
  142.      turtle.digDown()
  143.     end
  144.     while not turtle.forward() do
  145.       if turtle.detect() then
  146.         turtle.dig()
  147.       else
  148.         turtle.attack()
  149.       end
  150.     end
  151. --  UpdateScreen()
  152.     blockNum = blockNum + 1
  153.     UpdateScreen()
  154.   end
  155. end
  156.  
  157.  
  158. function MineTunnel()
  159.   while not turtle.up() do
  160.     turtle.digUp()
  161.   end
  162. --  turtle.digUp()
  163. --  turtle.up()
  164.   for i = 1, y/2 do
  165.     SafeMove(1, false)
  166.     turtle.turnLeft()
  167.     turtle.digUp()
  168.     turtle.digDown()
  169.     SafeMove(x-1, true)
  170.     turtle.turnRight()
  171.     turtle.digUp()
  172.     turtle.digDown()
  173.     SafeMove(1, false)
  174.     turtle.turnRight()
  175.     turtle.digUp()
  176.     turtle.digDown()
  177.     SafeMove(x-1, true)
  178.     turtle.turnLeft()
  179.     turtle.digUp()
  180.     turtle.digDown()
  181.     UpdateScreen(i*2)
  182.   end
  183.   turtle.down()
  184.   turtle.turnLeft()
  185.   turtle.turnLeft()
  186.   SafeMove(y, false)
  187.   turtle.turnLeft()
  188.   turtle.turnLeft()
  189. end
  190.  
  191. function DropItems()
  192.   for i = 1, 16 do
  193.     turtle.select(i)
  194.     turtle.drop()
  195.   end
  196. end
  197.  
  198. function StairsMode()
  199.  
  200. end
  201.  
  202. --function UpdateScreen(percent)
  203. function UpdateScreen()
  204.   term.clear()
  205.   term.setCursorPos(1,1)
  206.   term.setTextColor(termColorAlert)
  207.   print("Turtle Activated")
  208.   term.setTextColor(termColorDefault)
  209. --  print(percent/y*100, "% completed")
  210.   print(blockNum/neededFuel, "% completed")
  211.   print("Fuel Level: ", turtle.getFuelLevel())
  212. end
  213.  
  214.  
  215. Intro()
  216. --turtle.forward()
  217. --turtle.forward()
  218. --turtle.forward()
  219. --turtle.forward()
  220. --turtle.forward()
  221. --SafeMove(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement