bigougit

vertMine

Apr 17th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. --[[
  2. vertMine v1 by bigougit
  3.  
  4. This program is for turtles only,
  5. ideally mining turtles.
  6.  
  7. To install in-game, make sure
  8. that http = true in your
  9. computercraft config.
  10.  
  11. To install, open your turtle
  12. and type:
  13. pastebin get RbRkXpCa vertMine
  14.  
  15. Usage: turtle will dig a straight
  16. tunnel a set distance of a set
  17. height. Edit depth and distance
  18. variables below as desired.
  19. REMEMBER TO PUT AN ENDER CHEST
  20. IN SLOT 1 OR TURTLE WILL THROW
  21. ITEMS ON GROUND.
  22.  
  23. THIS PROGRAM DOES NOT CHECK FOR
  24. FUEL OR REFUEL THE TURTLE. MAKE
  25. SURE TURTLES HAVE PLENTY OF FUEL
  26. BEFORE STARTING!
  27.  
  28. report any errors to me on youtube or
  29. twitter.
  30.  
  31. http://youtube.com/user/bigougit
  32. http://twitter.com/bigougit
  33.  
  34. --]]
  35.  
  36. -- how far up or down to dig
  37. local depth = 70
  38.  
  39. -- how far away to dig
  40. local distance = 100
  41. local traveled = 0
  42.  
  43. function tryUp()
  44.   local trys = 0
  45.   while not turtle.up() do
  46.     turtle.digUp()
  47.     turtle.attackUp()
  48.     trys = trys + 1
  49.     if trys >= 20 then
  50.       return false
  51.     end
  52.   end
  53.   return true
  54. end
  55.  
  56. function tryDown()
  57.   local trys = 0
  58.   while not turtle.down() do
  59.     turtle.digDown()
  60.     turtle.attackDown()
  61.     trys = trys + 1
  62.     if trys >= 20 then
  63.       return false
  64.     end
  65.   end
  66.   return true
  67. end
  68.  
  69. function tryForward()
  70.   local trys = 0
  71.   while not turtle.forward() do
  72.     turtle.dig()
  73.     turtle.attack()
  74.     trys = trys + 1
  75.     if trys >= 20 then
  76.       return false
  77.     end
  78.   end
  79.   return true
  80. end
  81.  
  82. --return how many items in [slot]
  83. local function sCount(slot)
  84.   return turtle.getItemCount(slot)
  85. end
  86.  
  87. function haveRoom()
  88.   local hasRoom = false
  89.   for i=1,16 do
  90.     if sCount(i) == 0 then
  91.       hasRoom = true
  92.     end
  93.   end
  94.   return hasRoom
  95. end
  96.  
  97. function checkInventory()
  98.   if not haveRoom() then
  99.     turtle.select(1)
  100.     while not turtle.placeUp() do
  101.       turtle.digUp()
  102.       turtle.attackUp()
  103.     end
  104.     for i=2,16 do
  105.       turtle.select(i)
  106.       while not turtle.dropUp() do
  107.         sleep(0.5)
  108.       end
  109.     end
  110.     turtle.select(1)
  111.     turtle.digUp()
  112.   end
  113. end
  114.  
  115. -- start of main
  116.  
  117. while traveled < distance do
  118.  
  119.   while tryDown() do
  120.     checkInventory()
  121.   end
  122.  
  123.   if tryForward() then
  124.     traveled = traveled + 1
  125.   end
  126.  
  127.   for i=1,depth do
  128.     if not tryUp() then
  129.       print("HELP! IM STUCK!")
  130.       sleep(400)
  131.     end
  132.     checkInventory()
  133.   end
  134.  
  135.   if tryForward() then
  136.     traveled = traveled + 1
  137.   end
  138.    
  139. end
  140.  
  141. turtle.turnLeft()
  142. turtle.turnLeft()
  143. for i=1, traveled do
  144.   tryForward()
  145. end
Advertisement
Add Comment
Please, Sign In to add comment