Advertisement
Guest User

mine

a guest
Aug 1st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.45 KB | None | 0 0
  1.  full = false
  2.  Fuel = true
  3.  cposi = 0
  4.  pposi = 0
  5.  cposiB = 0
  6.  pposiB = 0
  7.  branch = false
  8.  cposiB = 0
  9.  
  10. function forward()
  11.   moved = turtle.forward()
  12.   while not(moved) do
  13.     sleep(1)
  14.     turtle.dig()
  15.     moved=turtle.forward()
  16.   end
  17. end
  18.    
  19. function checkInv()
  20.   if turtle.getItemCount(15) ~= 0 then
  21.      full = true
  22.   end
  23. end
  24.  
  25. function checkFuel()
  26. CFuel = turtle.getFuelLevel()
  27.    if not(branch) then
  28.     if CFuel <= cposi then
  29.       Fuel = false
  30.     end
  31.     if CFuel <= cposi + 5 then
  32.       Fuel = false
  33.     end
  34.    else
  35.      if CFuel <= cposi or CFuel <= 5+cposi or CFuel <= 42+cposi then
  36.        Fuel =false
  37.      end
  38.    end
  39. end
  40.  
  41. function checkifbranch()
  42.   n=0
  43.   while n < cposi  do
  44.     n=n+4
  45.   end
  46.   if n == cposi and not(n==0) then
  47.     branch = true
  48.   end
  49. end
  50.  
  51. function gohome()
  52.   while cposi ~= 0 do
  53.       forward()
  54.       cposi = cposi-1
  55.   end
  56. end
  57.  
  58. function gomine()
  59.   while cposi ~= pposi do
  60.       forward()
  61.       cposi = cposi+1
  62.   end
  63. end
  64.  
  65. function home()
  66.   turtle.turnLeft()
  67.   turtle.turnLeft()
  68.   gohome()
  69.   turtle.turnLeft()
  70.   turtle.turnLeft()
  71.   for i=2,15 do
  72.     turtle.select(i)
  73.     turtle.dropDown()
  74.   end
  75.      turtle.select(1)
  76.   full = false
  77.   if turtle.getItemCount(16) > 64 then
  78.     turtle.select(16)
  79.     turtle.suckUp()
  80.     turtle.select(2)
  81.     turtle.dropUp()
  82.     turtle.select(1)
  83.   end
  84.   while turtle.getFuelLevel() < 2*pposi do
  85.     q=turtle.getItemCount(1)
  86.     q= q -1    
  87.     turtle.select(2)
  88.     turtle.refuel(q)
  89.     turtle.select(1)
  90.     print("refueling...")
  91.     sleep(15)
  92.   end
  93.   Fuel = true
  94.   gomine()
  95. end
  96.  
  97. function ifhomeL()
  98.    checkInv()
  99.    if full then
  100.      turtle.turnRight()
  101.      turtle.turnRight()
  102.      while cposiB ~= 0 do
  103.        forward()
  104.        cposiB = cposiB - 1
  105.      end
  106.      turtle.turnLeft()
  107.      home()
  108.      turtle.turnLeft()
  109.      while cposiB ~= pposiB do
  110.        forward()
  111.        cposiB = cposiB + 1
  112.      end
  113.   end
  114. end
  115.      
  116. function ifhomeR()
  117.    checkInv()
  118.    if full then
  119.      turtle.turnRight()
  120.      turtle.turnRight()
  121.      while cposiB ~= 0 do
  122.        forward()
  123.        cposiB = cposiB - 1
  124.      end
  125.      turtle.turnRight()
  126.      home()
  127.      turtle.turnRight()
  128.      while cposiB ~= pposiB do
  129.        forward()
  130.        cposiB = cposiB + 1
  131.      end
  132.   end
  133. end
  134.  
  135. function gobranchLeft()
  136.   pposiB = 0
  137.   turtle.turnLeft()
  138.   while cposiB ~= 21 do
  139.     pposiB = pposiB + 1
  140.     cposiB = cposiB + 1
  141.     forward()
  142.     ifhomeL()
  143.     turtle.digUp()
  144.     ifhomeL()
  145.     turtle.digDown()
  146.     ifhomeL()
  147.   end
  148.   turtle.turnLeft()
  149.   turtle.turnLeft()
  150.   while cposiB ~= 0 do
  151.        forward()
  152. if cposiB == 7 or cposiB== 14 or cposiB== 20 then
  153.         turtle.select(16)
  154.         turtle.placeDown()
  155.         turtle.select(1)
  156.     end
  157.        cposiB = cposiB - 1
  158.   end  
  159.   pposiB= 0
  160. turtle.turnLeft()
  161. end
  162.  
  163.  
  164. function gobranchRight()
  165.   pposiB = 0
  166.   turtle.turnRight()
  167.   while cposiB ~= 21 do
  168.     pposiB = pposiB + 1
  169.     cposiB = cposiB + 1
  170.     forward()
  171.     ifhomeR()
  172.     turtle.digUp()
  173.     ifhomeR()
  174.     turtle.digDown()
  175.     ifhomeR()
  176.   end
  177.   turtle.turnLeft()
  178.   turtle.turnLeft()
  179.   while cposiB ~= 0 do
  180.        forward()
  181.     if cposiB == 7 or cposiB== 14 or cposiB== 20 then
  182.         turtle.select(16)
  183.         turtle.placeDown()
  184.         turtle.select(1)
  185.     end
  186.        cposiB = cposiB - 1
  187.   end  
  188.   pposiB= 0
  189.   turtle.turnRight()
  190. end
  191.  
  192. function mineM()
  193. turtle.select(1)  
  194. checkInv()
  195.   checkifbranch()
  196.   checkFuel()
  197.   if full == true or Fuel==false then
  198.     home()
  199.   end
  200.   if branch then
  201.     gobranchLeft()
  202.     checkFuel()
  203.     checkInv()
  204.     if not(Fuel) or full then
  205.       home()
  206.     end
  207.     gobranchRight()
  208.     branch=false
  209. t=0
  210.  while t < cposi  do
  211.     t=t+8
  212.   end
  213.   if t == cposi and not(t==0) then
  214.     turtle.select(16)
  215.     turtle.placeDown()
  216.     turtle.select(1)
  217.   end
  218.  
  219.     checkFuel()
  220.     checkInv()
  221.     if not(Fuel) or full then
  222.       home()
  223.     end
  224.   end
  225.   forward()
  226.   cposi= cposi+1
  227.   pposi= pposi+1
  228.   checkInv()
  229.   if full then
  230.     home()
  231.   end
  232.   turtle.digUp()
  233.   checkInv()
  234.   if full then
  235.     home()
  236.   end
  237.   turtle.digDown()
  238.   checkInv()
  239.   if full then
  240.     home()
  241.   end
  242.   turtle.turnLeft()
  243.   forward()
  244.   checkInv()
  245.   if full then
  246.     turtle.turnRight()
  247.     turtle.turnRight()
  248.     forward()
  249.     turtle.turnLeft()
  250.     home()
  251.     turtle.turnLeft()
  252.     forward()
  253.   end
  254.   turtle.digDown()
  255.     checkInv()
  256.   if full then
  257.     turtle.turnRight()
  258.     turtle.turnRight()
  259.     forward()
  260.     turtle.turnLeft()
  261.     home()
  262.     turtle.turnLeft()
  263.     forward()
  264.  end
  265.    turtle.digUp()
  266.     checkInv()
  267.   if full then
  268.     turtle.turnRight()
  269.     turtle.turnRight()
  270.     forward()
  271.     turtle.turnLeft()
  272.     home()
  273.     turtle.turnLeft()
  274.     forward()
  275.  end
  276.     turtle.turnRight()
  277.     turtle.turnRight()
  278.     forward()
  279. forward()
  280.   if full then
  281.     turtle.turnRight()
  282.     turtle.turnRight()
  283.     forward()
  284.     turtle.turnRight()
  285.     home()
  286.     turtle.turnRight()
  287.     forward()
  288.  end
  289. turtle.digUp()
  290.     checkInv()
  291.   if full then
  292.     turtle.turnRight()
  293.     turtle.turnRight()
  294.     forward()
  295.     turtle.turnRight()
  296.     home()
  297.     turtle.turnRight()
  298.     forward()
  299.  end
  300. turtle.digDown()
  301.     checkInv()
  302.   if full then
  303.     turtle.turnRight()
  304.     turtle.turnRight()
  305.     forward()
  306.     turtle.turnRight()
  307.     home()
  308.     turtle.turnRight()
  309.     forward()
  310.  end
  311.     turtle.turnRight()
  312.     turtle.turnRight()
  313.     forward()
  314.     turtle.turnRight()
  315. end
  316.  
  317. tArgs={...}
  318. q = tArgs[1]
  319.  
  320.  target= q*4
  321.  
  322. while pposi~= target do
  323. mineM()
  324. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement