Advertisement
Guest User

go2

a guest
Aug 1st, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.76 KB | None | 0 0
  1.  
  2. xCoord = 207
  3. zCoord = 323
  4. yCoord = 65
  5.  
  6. mineStop = 5
  7.  
  8. xHome = xCoord
  9. zHome = zCoord
  10. yHome = yCoord
  11.  
  12. yTunnelTravel = 20
  13. yQuarryTravel = 80
  14.  
  15.  
  16. woodAmount = 10
  17. coalAmount = 0
  18. MinFuel = 5
  19.  
  20. oreslots = {}
  21. curOreslot = 0
  22.  
  23.  
  24. orientation = 1
  25. orientations = {"north", "east", "south", "west"}
  26.  
  27. xCont = {}
  28. zCont = {}
  29. yCont = {}
  30.  
  31. xChange = {0,1,0,-1}
  32. zChange = {-1,0,1,0}
  33. direction = orientations[orientation]
  34.  
  35. lines = 10
  36. lineLength = 10
  37.  
  38. lineLength = lineLength - 1
  39.  
  40. xQuarry = 999
  41. zQuarry = 999
  42. yQuarry = 999
  43.  
  44. xTunnel = 999
  45. zTunnel = 999
  46. yTunnel = 20
  47.  
  48. xTarget = 999
  49. zTarget = 999
  50. yTarget = 20
  51.  
  52. tunnelFinish = 50
  53. yMin = yCoord
  54.  
  55. function face(direction)
  56.  while direction ~= orientations[orientation] do
  57.   right()
  58.  end
  59. end
  60.  
  61. function left()
  62.  orientation = orientation - 1
  63.  orientation = (orientation - 1) % 4
  64.  orientation = orientation + 1
  65.  
  66.  turtle.turnLeft()
  67. end
  68.  
  69. function right()
  70.  orientation = orientation - 1
  71.  orientation = (orientation + 1) % 4
  72.  orientation = orientation + 1
  73.  
  74.  turtle.turnRight()
  75. end
  76.  
  77. function moveForward()
  78.  addCoal = turtle.compare()
  79.  if addCoal then coalAmount = coalAmount + 1
  80.  end
  81.   xCoord = xCoord + xChange[orientation]
  82.   zCoord = zCoord + zChange[orientation]
  83.  
  84.  moved = false
  85.  
  86. while not(moved) do
  87.  turtle.dig()
  88.  moved = turtle.forward()
  89.  end
  90. end
  91.  
  92. function moveUp()
  93.  yCoord = yCoord + 1
  94.  
  95.  moved = false
  96.  while not(moved) do
  97.  turtle.digUp()
  98.  moved = turtle.up()
  99.  end
  100. end
  101.  
  102. function moveDown()
  103.  yCoord = yCoord - 1
  104.  
  105.  moved = false
  106.  while not(moved) do
  107.  turtle.digDown()
  108.  moved = turtle.down()
  109.  
  110.  if yMin > yCoord then
  111.  yMin = yCoord
  112.   end
  113.  end
  114. end
  115.  
  116. function goto(xTarget, zTarget, yTarget)
  117.  
  118.  while yTarget < yCoord do
  119.   moveDown()
  120.  end
  121.  
  122.  while yTarget > yCoord do
  123.   moveUp()
  124.  end
  125.  
  126.  while xTarget < xCoord do
  127.   face("west")
  128.  
  129. moveForward()
  130.  end
  131.  
  132.  while xTarget > xCoord do
  133.   face("east")
  134.  moveForward()
  135.  end
  136.  
  137.  while zTarget < zCoord do
  138.   face("north")
  139.  moveForward()
  140.  end
  141.  
  142.  while zTarget > zCoord do
  143.   face("south")
  144.  moveForward()
  145.  
  146.   end
  147.  
  148.  end
  149.  
  150. function digline()
  151.  for i = 1,lineLength do
  152.   moveForward()
  153.  end
  154.  
  155.  inventoryFull()
  156.  
  157.  checkFuel()
  158.  
  159.  if full then
  160.   returnItems()
  161.  
  162.  end
  163. end
  164.  
  165. function digLayer()
  166.  for i = 1,lines do
  167.  digline()
  168.  
  169.   if (i%2) == 1 and i < lines then
  170.    left()
  171.    moveForward()
  172.    left()
  173.  
  174.   elseif i < lines then
  175.    right()
  176.    moveForward()
  177.    right()
  178.   end
  179.  end
  180.  
  181.  goto(xQuarry,zQuarry,yCoord)
  182.  face("north")
  183.  moveDown()
  184. end
  185.    
  186. function checkFuel()
  187.  
  188.  print("Checking Fuel")
  189.  
  190.  needFuel = turtle.getFuelLevel() < MinFuel
  191.  
  192.  if needFuel then
  193.   turtle.select(16)
  194.   turtle.refuel(woodAmount - 10)
  195.   woodAmount = woodAmount - woodAmount + 10
  196.  end
  197.  
  198. end
  199.  
  200. function goHome()
  201.  print("returning home")
  202.  goto(xHome,zHome,yQuarryTravel)
  203.  goto(xHome,zHome,yHome)
  204.  face("west")
  205.  
  206. end
  207.  
  208. function returnItems()
  209.  goHome()
  210.  face("north")
  211.  for i = 2,16 do
  212.   turtle.select(i)
  213.   turtle.drop()
  214.  end
  215. turtle.select(1)
  216. end
  217.  
  218.  
  219. function digQuarry(xTarget,zTarget,yTarget)
  220.  
  221. checkFuel()
  222.  
  223.  xQuarry = xTarget
  224.  zQuarry = zTarget
  225.  yQuarry = yTarget
  226.  
  227.  goto(xQuarry,zQuarry,yQuarryTravel)
  228.  
  229.  goto(xQuarry,zQuarry,yQuarry)
  230.  face("north")
  231.  
  232.  while yMin > 7 do
  233.   digLayer()
  234.  end
  235.  
  236.  goto(xHome,zHome,yTravel)
  237.  goto(xHome,zHome,yHome)
  238. end
  239.  
  240. function digLayerT()
  241. moveForward()
  242. left()
  243. turtle.dig()
  244. moveUp()
  245. turtle.dig()
  246. right()
  247. right()
  248. turtle.dig()
  249. moveDown()
  250. turtle.dig()
  251. left()
  252.  
  253. end
  254.  
  255. function digTunnel(xTarget,zTarget,yTarget)
  256.  
  257.  term.write("How Far:")
  258.  tunnelFinish = read()
  259.  
  260.  print("Tunnelling")
  261.  
  262.  checkFuel()
  263.  
  264.  print("Fuel Check Done")
  265.  
  266.  xTunnel = xTarget
  267.  zTunnel = zTarget
  268.  yTunnel = yTarget
  269.  
  270.  goto(xTunnel,zTunnel,yTunnel)
  271.  face("west")
  272.  
  273.  for i = 1,tunnelFinish do
  274.   digLayerT()
  275.  end
  276.  
  277. end
  278.  
  279. function checkAir()
  280.  air= false
  281.  moved = false
  282.  moved = turtle.forward()
  283.    
  284.  if moved then
  285.   turtle.back()
  286.   air = true
  287.   return
  288.  end
  289. end
  290.  
  291. function checkOre()
  292.  
  293.  trashSlots = 3
  294.  
  295.  for t = 1,4 do
  296.   ore = true
  297.  
  298.   for i = 1,trashSlots do
  299.    turtle.select(i)
  300.    if turtle.compare() then
  301.     ore = false
  302.    end   
  303.   end
  304.    
  305.  
  306.   if ore then
  307.   checkAir()
  308.    if air then
  309.     ore = false
  310.    end
  311.   end
  312.  
  313.   if ore then
  314.  
  315.  
  316.    return
  317.   end  
  318.  
  319.  
  320.  
  321.   right()
  322.   end
  323.  end
  324.  
  325.  
  326.  
  327. function checkSameOre()
  328.  same = false
  329.  
  330.  for t = 1,4 do
  331.   turtle.select(oreslots[curOreslot])
  332.  
  333.   if turtle.compare() then
  334.    same = true
  335.    
  336.    print("ore is same")
  337.    
  338.    return
  339.   end
  340.   right()
  341.  end
  342.  
  343. end
  344.  
  345.  
  346.  
  347. function saveCoords()
  348.  table.insert(xCont,xCoord)
  349.  table.insert(zCont,zCoord)
  350.  table.insert(yCont,yCoord)
  351. end
  352.  
  353.  
  354. function removeCoords()
  355.  table.remove(xCont)
  356.  table.remove(zCont)
  357.  table.remove(yCont)
  358. end
  359.  
  360. function checkUD()
  361.  
  362.  if turtle.compareDown() then same = true
  363.  end
  364.  if turtle.compareUp() then same = true
  365.  end
  366. end
  367.  
  368.  
  369. first = true
  370.  
  371. function gatherVein()
  372.  
  373.  same = false
  374.  turtle.select(oreslots[curOreslot])
  375.  
  376.  if first then
  377.   xStart = xCoord
  378.   zStart = zCoord
  379.   yStart = yCoord
  380.  
  381.   turtle.select(oreslots[curOreslot])
  382.  
  383.   turtle.dig()
  384.   moveForward()
  385.  
  386.  saveCoords()
  387.  
  388.  end
  389.  
  390.  first = false
  391.  
  392.  while turtle.compareUp() do
  393.  
  394.  
  395.  
  396.   saveCoords()
  397.  
  398.   moveUp()
  399.    
  400.   if not(turtle.compareUp()) then
  401.    checkSameOre()
  402.    if same then
  403.     return
  404.    end
  405.   end
  406.  
  407.  end
  408.  
  409.  
  410.  
  411.  while turtle.compareDown() do
  412.  
  413.   saveCoords()
  414.  
  415.   moveDown()
  416.  
  417.   if not(turtle.compareDown()) then
  418.    checkSameOre()
  419.    if same then
  420.     return
  421.    end
  422.   end
  423.  
  424.  end
  425.  
  426.  
  427.   if  turtle.compare() then
  428.  
  429.  
  430.    saveCoords()
  431.    moveForward()
  432.    
  433.     checkSameOre()
  434.    
  435.     checkUD()
  436.  
  437.     if same then
  438.      return
  439.     end
  440.  
  441.   end
  442.  
  443.  
  444.   C = #xCont
  445.  
  446.   if C > 0 then
  447.  
  448.    goto(xCont[C],zCont[C],yCoord)
  449.    goto(xCont[C],zCont[C],yCont[C])
  450.    
  451.  
  452.    removeCoords()
  453.    checkSameOre()
  454.    checkUD()
  455.    
  456.    if same then return
  457.    end
  458.  
  459.  
  460.     same = true
  461.  
  462.    return
  463.   end
  464.  
  465.   goto(xStart,zStart,yStart)
  466.  
  467.   same = false
  468.   first = true
  469.  
  470. end
  471.  
  472. function changeOreslot()
  473. print("changing ore slot")
  474.  
  475. lowestSlot = #oreslots
  476.  
  477. changeSlotStart = oreslots[lowestSlot]
  478. print("the lowest slot is:".. changeSlotStart)
  479.  
  480.  
  481.   for i = changeSlotStart,4,-1 do
  482.    if turtle.getItemCount(i) < 1 then
  483.     table.insert(oreslots,i)
  484.     curOreslot = #oreslots
  485.  
  486.     return
  487.    end
  488.    
  489.   end
  490.    
  491.  end
  492.  
  493. function checkSameOreSlot()
  494. sameSlot = false
  495.  if curOreslot == 0 then
  496.   print("first ore")
  497.   table.insert(oreslots,14)
  498.   curOreslot = 1
  499.  
  500.   sameSlot = true
  501.   return
  502.  end
  503.  
  504.  
  505.  for i = 1,#oreslots do
  506.   print("checking if same ore")
  507.   turtle.select(oreslots[i])
  508.   if turtle.compare() then
  509.    print("this is the same")
  510.    curOreslot = oreslots[i]
  511.    sameSlot = true
  512.    return
  513.   end
  514.  end
  515.  print("this is not the same")
  516.  sameSlot = false
  517.  return
  518. end
  519.  
  520.  
  521.  
  522. function digShaft()
  523.  same = false
  524.  ore = false
  525.  sameSlot = false
  526.  
  527.  moveDown()
  528.  
  529.  
  530.  while yCoord > mineStop do
  531.  
  532.   moveDown()
  533.   checkOre()
  534.   print("checked ore")
  535.  
  536.  while ore do
  537.  
  538.   print("1")
  539.   checkSameOreSlot()
  540.  
  541.   if  sameSlot == false then
  542.   print("changing slot")
  543.    changeOreslot()
  544.    print("changed ore slot")
  545.    end
  546.    
  547.    print("2")
  548.    turtle.select(oreslots[curOreslot])
  549.    print("3")
  550.  
  551.    gatherVein()
  552.    
  553.    while same do
  554.     gatherVein()
  555.    end
  556.    
  557.    checkOre()
  558.    
  559.   end
  560.  
  561.  end
  562.  
  563.  goto(xCoord,zCoord,65)
  564.  print("finished")
  565. end
  566.  
  567.  
  568.  
  569.  
  570. function getTree()
  571.  turtle.select(16)
  572.  moveForward()
  573.  woodAmount = woodAmount + 1
  574.  
  575.  while turtle.compareUp(16) do
  576.   checkFuel()
  577.   moveUp()
  578.   woodAmount = woodAmount + 1
  579.  end
  580.  
  581.  while not (turtle.detectDown()) do
  582.  moveDown()
  583.  end
  584.  
  585. end
  586.  
  587. function start()
  588. turtle.select(1)
  589. digShaft()
  590. face("north")
  591.  
  592. end
  593.  
  594. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement