Advertisement
Guest User

Untitled

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