Advertisement
drewhoener

Mine

Oct 20th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. -- Tunnel Mining Turtle (with return)
  2. -- Mines, places torches, builds floor
  3. -- Variables
  4. turtle.select(1)
  5. local tArgs = { ... }
  6. local togo = tonumber(tArgs[1])
  7. togo = togo or 1
  8. local torch = 0
  9. local cobble = 0
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. print(os.getComputerLabel() .. " at your service!")
  13. print()
  14. print("Please place blocks as follows:")
  15. print("Slot 1 - Fuel (coal or lava)")
  16. print("Slot 2 - Torches (optional)")
  17. print("Slot 3 - Cobble (optional)")
  18. print()
  19. print("Press [ENTER] when ready.")
  20. read(input)
  21.  
  22. -- Starting Out
  23. if turtle.getItemCount(1) < 1 then
  24.   print("No fuel! Abort!")
  25.   quit()
  26. end
  27. torch = 0
  28. if turtle.getItemCount(2) > 0 then
  29.   torch = 1
  30. end
  31. if turtle.getItemCount(3) > 0 then
  32.   cobble = 1
  33. end
  34. local i = 0
  35.  
  36. -- Functions
  37. function tfuel(amount)
  38.  if turtle.getFuelLevel() < 16 then
  39.   turtle.select(1)
  40.   turtle.refuel(amount)
  41.  end
  42. end
  43.  
  44. function turnaround()
  45.   turtle.turnRight()
  46.   turtle.turnRight()
  47. end
  48.  
  49. function uandd()
  50.   if turtle.detectUp() then
  51.    repeat
  52.     turtle.digUp()
  53.         sleep(0.5)
  54.    until turtle.detectUp() == false
  55.   end
  56.   if turtle.detectDown() then
  57.    repeat
  58.     turtle.digDown()
  59.    until turtle.detectDown() == false
  60.   end
  61.   if cobble > 0 then
  62.     turtle.down()
  63.         if turtle.detectDown() == false then
  64.       turtle.select(3)
  65.       turtle.placeDown()
  66.           turtle.select(1)
  67.         end
  68.     turtle.up()
  69.   end
  70. end
  71.  
  72. function mydig()
  73.   tfuel(1)
  74.   if turtle.detect() then
  75.    repeat
  76.     turtle.dig()
  77.     sleep(0.5)
  78.    until turtle.detect() == false
  79.    turtle.forward()
  80.    uandd()
  81.   else
  82.    turtle.forward()
  83.    uandd()
  84.   end
  85. end
  86.  
  87. function discard() -- run back to start and drop off items
  88.   turnaround()
  89.   for f = 1,i do
  90.     tfuel(1)
  91.     while turtle.forward() == false do
  92.       turtle.dig()
  93.     end
  94.   end
  95.   for x = 2+torch+cobble,16 do
  96.     turtle.select(x)
  97.         turtle.dropDown()
  98.   end
  99.   turnaround()
  100.   for f = 1,i do
  101.     tfuel(1)
  102.     while turtle.forward() == false do
  103.       turtle.dig()
  104.     end
  105.   end
  106.   turtle.select(1)
  107. end
  108.  
  109. -- Main Loop
  110. repeat
  111.   i = i + 1
  112.   term.clear()
  113.   term.setCursorPos(1,1)
  114.   local pct = (i/togo)*100
  115.   print("Mining "..i.." of "..togo.." ("..pct.."%)")
  116.   print("Fuel: "..turtle.getFuelLevel())
  117.   mydig()
  118.   turtle.turnRight()
  119.   mydig()
  120.   turnaround()
  121.   turtle.forward()
  122.   mydig()
  123.   turnaround()
  124.   turtle.forward()
  125.   turtle.turnLeft()
  126.   if togo >= 8 and torch > 0 then
  127.    if (i % 8 == 0) then
  128.     turtle.select(2)
  129.     turtle.placeDown()
  130.         turtle.select(1)
  131.    end
  132.   end
  133.   -- check to see if turtle is full
  134.   if turtle.getItemCount(16) > 0 then
  135.     discard()
  136.   end
  137.   turtle.select(1)
  138. until i >= togo
  139.  
  140. --Lets assume that worked and he made it
  141. turnaround()
  142. for r = 1, togo do
  143.   tfuel(1)
  144.   while turtle.forward() == false do
  145.     turtle.dig()
  146.   end
  147. end
  148. for x = 1,16 do
  149.   turtle.select(x)
  150.   turtle.dropDown()
  151. end
  152. turtle.select(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement