Advertisement
Guest User

tunnel

a guest
Aug 1st, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1.  full = false
  2.  Fuel = true
  3.  cposi = 0
  4.  pposi = 0
  5.  
  6.  
  7. function forward()
  8.   moved = turtle.forward()
  9.   while not(moved) do
  10.     sleep(1)
  11.     turtle.dig()
  12.     moved=turtle.forward()
  13.   end
  14. end
  15.    
  16. function checkInv()
  17.   if turtle.getItemCount(15) ~= 0 then
  18.      full = true
  19.   end
  20. end
  21.  
  22. function checkFuel()
  23. CFuel = turtle.getFuelLevel()
  24.    if not(branch) then
  25.     if CFuel <= cposi then
  26.       Fuel = false
  27.     end
  28.     if CFuel <= cposi + 5 then
  29.       Fuel = false
  30.     end
  31.    else
  32.      if CFuel <= cposi or CFuel <= 5+cposi or CFuel <= 42+cposi then
  33.        Fuel =false
  34.      end
  35.    end
  36. end
  37.  
  38.  
  39. function gohome()
  40.   while cposi ~= 0 do
  41.       forward()
  42.       cposi = cposi-1
  43.   end
  44. end
  45.  
  46. function gomine()
  47.   while cposi ~= pposi do
  48.       forward()
  49.       cposi = cposi+1
  50.   end
  51. end
  52.  
  53. function home()
  54.   turtle.turnLeft()
  55.   turtle.turnLeft()
  56.   gohome()
  57.   turtle.turnLeft()
  58.   turtle.turnLeft()
  59.   for i=2,15 do
  60.     turtle.select(i)
  61.     turtle.dropDown()
  62.   end
  63.      turtle.select(1)
  64.   full = false
  65.   if turtle.getItemCount(16) > 64 then
  66.     turtle.select(16)
  67.     turtle.suckUp()
  68.     turtle.select(2)
  69.     turtle.dropUp()
  70.     turtle.select(1)
  71.   end
  72.   while turtle.getFuelLevel() < 2*pposi do
  73.     q=turtle.getItemCount(1)
  74.     q= q -1    
  75.     turtle.select(2)
  76.     turtle.refuel(q)
  77.     turtle.select(1)
  78.     print("refueling...")
  79.     sleep(15)
  80.   end
  81.   Fuel = true
  82.   gomine()
  83. end
  84.  
  85. function mineM()
  86. turtle.select(1)  
  87. checkInv()
  88.   checkFuel()
  89.   if full == true or Fuel==false then
  90.     home()
  91.   end
  92.   t=0
  93.  while t < cposi  do
  94.     t=t+8
  95.   end
  96.   if t == cposi and not(t==0) then
  97.     turtle.select(16)
  98.     turtle.placeDown()
  99.     turtle.select(1)
  100.   end
  101.   forward()
  102.   cposi= cposi+1
  103.   pposi= pposi+1
  104.   checkInv()
  105.   if full then
  106.     home()
  107.   end
  108.   turtle.digUp()
  109.   checkInv()
  110.   if full then
  111.     home()
  112.   end
  113.   turtle.digDown()
  114.   checkInv()
  115.   if full then
  116.     home()
  117.   end
  118.   turtle.turnLeft()
  119.   forward()
  120.   checkInv()
  121.   if full then
  122.     turtle.turnRight()
  123.     turtle.turnRight()
  124.     forward()
  125.     turtle.turnLeft()
  126.     home()
  127.     turtle.turnLeft()
  128.     forward()
  129.   end
  130.   turtle.digDown()
  131.     checkInv()
  132.   if full then
  133.     turtle.turnRight()
  134.     turtle.turnRight()
  135.     forward()
  136.     turtle.turnLeft()
  137.     home()
  138.     turtle.turnLeft()
  139.     forward()
  140.  end
  141.    turtle.digUp()
  142.     checkInv()
  143.   if full then
  144.     turtle.turnRight()
  145.     turtle.turnRight()
  146.     forward()
  147.     turtle.turnLeft()
  148.     home()
  149.     turtle.turnLeft()
  150.     forward()
  151.  end
  152.     turtle.turnRight()
  153.     turtle.turnRight()
  154.     forward()
  155. forward()
  156.   if full then
  157.     turtle.turnRight()
  158.     turtle.turnRight()
  159.     forward()
  160.     turtle.turnRight()
  161.     home()
  162.     turtle.turnRight()
  163.     forward()
  164.  end
  165. turtle.digUp()
  166.     checkInv()
  167.   if full then
  168.     turtle.turnRight()
  169.     turtle.turnRight()
  170.     forward()
  171.     turtle.turnRight()
  172.     home()
  173.     turtle.turnRight()
  174.     forward()
  175.  end
  176. turtle.digDown()
  177.     checkInv()
  178.   if full then
  179.     turtle.turnRight()
  180.     turtle.turnRight()
  181.     forward()
  182.     turtle.turnRight()
  183.     home()
  184.     turtle.turnRight()
  185.     forward()
  186.  end
  187.     turtle.turnRight()
  188.     turtle.turnRight()
  189.     forward()
  190.     turtle.turnRight()
  191. end
  192.  
  193. tArgs={...}
  194. q = tArgs[1]
  195.  
  196.  target= q*4
  197.  
  198. while pposi~= target do
  199. mineM()
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement