Advertisement
jakikoske

test lua mine

Dec 9th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.20 KB | None | 0 0
  1. print "Turtle must be in down-left corner of a chunk not looking at a chunkwall on layer 1"
  2. print "Enderchest in slot 2 ,Fuel in slot 16 (optional, allows turtle to eat found fuel as a last resort)."
  3.  
  4. while turtle.getItemCount(2) < 1 do
  5.   print "Please put an ENDER CHEST in slot 1. Hit any key when done."
  6.   os.pullEvent("char")
  7. end
  8. while turtle.getItemCount(1) < 2 do
  9.   print "Please put three CHUNKLOADERS in slot 1. Hit any key when done."
  10.   os.pullEvent("char")
  11. end
  12.  
  13. local distance = 1
  14. local chunks = 2
  15. local chunkCounter = 0
  16.  
  17. function GetFuelFromChest()
  18.   turtle.select(2)
  19.   DigHole()
  20.   turtle.placeUp()
  21.   turtle.select(16)
  22.   turtle.dropUp()
  23.   turtle.suckUp()
  24.   turtle.select(2)
  25.   turtle.digUp()
  26.   turtle.suckUp()
  27. end
  28.  
  29. function CheckFuel()
  30.   if turtle.getFuelLevel() <= 20 then
  31.     turtle.select(16)
  32.     turtle.refuel(2)
  33.   end
  34.   if turtle.getFuelLevel() <= 1 then
  35.     GetFuelFromChest()
  36.     CheckFuel()
  37.   end
  38.   return true  
  39. end
  40.  
  41. function MoveForward()
  42.   CheckFuel()
  43.   if(turtle.forward()) then
  44.     return true
  45.   else
  46.     return false
  47.   end
  48. end
  49.  
  50. function TurnLeft()
  51.   turtle.turnLeft()
  52. end
  53.  
  54. function TurnRight()
  55.   turtle.turnRight()
  56. end
  57.  
  58. function MoveUp()
  59.   CheckFuel()
  60.   if(turtle.up()) then
  61.     return true
  62.   end
  63.   return false
  64. end
  65.  
  66. function MoveDown()
  67.   CheckFuel()
  68.   if(turtle.down()) then
  69.     return true
  70.   end
  71.   return false
  72. end
  73.  
  74. function Dig()
  75.   while(turtle.detect()) do
  76.     turtle.dig()
  77.     turtle.suck()
  78.   end
  79. end
  80.  
  81. function DigHole()
  82.   while(turtle.detectUp()) do
  83.     turtle.digUp()
  84.     turtle.suckUp()
  85.   end
  86. end
  87.  
  88. function DigUp()
  89.   for y = 1, 13 do
  90.     while(MoveUp() == false) do
  91.       turtle.digUp()
  92.       turtle.suckUp()
  93.     end
  94.   end
  95. end
  96.  
  97. function DigDown()
  98.   for y = 1, 13 do
  99.     while(MoveDown() == false) do
  100.       turtle.digDown()
  101.       turtle.suckDown()
  102.     end
  103.   end
  104. end
  105.  
  106. function DigForward()
  107.   while(MoveForward() == false) do
  108.     turtle.dig()
  109.     turtle.suck()
  110.   end
  111. end
  112.  
  113. function DumpInventory()
  114.   while turtle.detectUp() do
  115.     turtle.digUp()
  116.   end
  117.   turtle.select(2)
  118.   while turtle.placeUp() == false do
  119.     turtle.digUp()
  120.   end
  121.  
  122.   local iLastInventorySlot = 16
  123.   if(turtle.getItemCount(16) > 0) then
  124.     iLastInventorySlot = 15
  125.   end
  126.  
  127.   for i = 3, iLastInventorySlot do
  128.     turtle.select(i)
  129.     turtle.dropUp()
  130.   end
  131.   turtle.select(2)
  132.   turtle.digUp()
  133. end
  134.  
  135. function PlaceChunkUp()
  136.   turtle.select(1)
  137.   while turtle.placeUp() == false do
  138.     turtle.digUp()
  139.   end
  140. end
  141.  
  142. function PlaceChunkFront()
  143.   turtle.select(1)
  144.   while turtle.place() == false do
  145.     turtle.dig()
  146.   end
  147. end
  148.  
  149. function PlaceChunkBack()
  150.   turtle.select(1)
  151.   TurnRight()
  152.   TurnRight()
  153.   while turtle.place() == false do
  154.     turtle.dig()
  155.   end
  156.   TurnRight()
  157.   TurnRight()
  158. end
  159.  
  160. function PlaceChunk()
  161.   if(distance % 2 > 0) then
  162.       TurnLeft()
  163.       TurnLeft()
  164.       DigForward()
  165.       TurnRight()
  166.       Dig()
  167.       PlaceChunkFront()
  168.       TurnRight()
  169.       DigForward()
  170.   else
  171.     if(chunkCounter == chunk) then
  172.       TurnLeft()
  173.       MoveForward()
  174.       TurnRight()
  175.       Dig()
  176.       PlaceChunk()
  177.       TurnRight()
  178.       DigForward()
  179.       TurnLeft()
  180.     else
  181.       TurnLeft()
  182.       TurnLeft()
  183.       DigForward()
  184.       TurnLeft()
  185.       Dig()
  186.       PlaceChunkFront()
  187.       TurnLeft()
  188.       DigForward()
  189.     end
  190.   end
  191. end
  192.  
  193. function FirstRow()
  194.   CheckFuel()
  195.   turtle.digDown()
  196.   MoveDown()
  197.   PlaceChunkUp()
  198.   for i = 1 , 12 do
  199.     turtle.digDown()
  200.     MoveDown()
  201.   end
  202.   for i = 1 , 7 do
  203.     DigForward()
  204.     DigUp()
  205.     if(i == 1) then
  206.       if(distance % 2 > 0) then
  207.     if(chunkCounter > 1) then
  208.           TurnLeft()
  209.           turtle.dig()
  210.           TurnRight()        
  211.     end
  212.       else
  213.         if(chunkCounter > 1) then
  214.       TurnRight()
  215.           turtle.dig()
  216.           TurnLeft()
  217.     end
  218.       end
  219.     end
  220.     DigForward()
  221.     DigDown()
  222.   end
  223.   DigForward()
  224.   DigUp()
  225. end
  226.  
  227. function LastRowNO()
  228.   TurnRight()
  229.   DigForward()
  230.   TurnRight()
  231.   AnyRowFromUp()
  232. end
  233.  
  234.  
  235. function LastRowOZ()
  236.   TurnLeft()
  237.   DigForward()
  238.   TurnLeft()
  239.   AnyRowFromUp()
  240. end
  241.  
  242. function AnyRowFromUp()
  243.   for i = 1 , 7 do
  244.     DigDown()
  245.     DigForward()
  246.     DigUp()
  247.     DigForward()
  248.     if(turtle.getItemCount(10) > 1) then
  249.       DumpInventory()
  250.     end
  251.   end
  252.   DigDown()
  253.   DigForward()
  254.   DigUp()
  255. end
  256.  
  257. function RetrieveChunkRight()
  258.   TurnRight()
  259.   for i = 1, 14 do
  260.     DigForward()
  261.   end
  262.   turtle.dig()
  263.   TurnRight()
  264.   TurnRight()
  265.   for i = 1, 14 do
  266.     DigForward()
  267.   end
  268.   TurnRight()
  269. end
  270.  
  271. function RetrieveChunkLeft()
  272.   TurnLeft()
  273.   for i = 1, 14 do
  274.     DigForward()
  275.   end
  276.   turtle.dig()
  277.   TurnRight()
  278.   TurnRight()
  279.   for i = 1, 14 do
  280.     DigForward()
  281.   end
  282.   TurnLeft()
  283. end
  284.  
  285. function NO()
  286.   FirstRow()
  287.   if(chunkCounter == 1) then
  288.     TurnLeft()
  289.     turtle.dig()
  290.     TurnRight()
  291.   end
  292.   for y = 1 , 7 do
  293.     TurnRight()
  294.     DigForward()
  295.     TurnRight()
  296.     AnyRowFromUp()
  297.     TurnLeft()
  298.     DigForward()
  299.     TurnLeft()
  300.     AnyRowFromUp()
  301.   end
  302.   LastRowNO()
  303.   PlaceChunk()
  304.   PlaceChunkBack()
  305.   RetrieveChunkRight()
  306. end
  307.  
  308. function OZ()
  309.   FirstRow()
  310.   for y = 1 , 7 do
  311.     TurnLeft()
  312.     DigForward()
  313.     TurnLeft()
  314.     AnyRowFromUp()
  315.     if(y == 1) then
  316.       if(chunkCounter == 1) then
  317.         turtle.dig()
  318.       end
  319.     end
  320.     TurnRight()
  321.     DigForward()
  322.     TurnRight()
  323.     AnyRowFromUp()
  324.   end
  325.   LastRowOZ()
  326.   PlaceChunk()
  327.   if(chunkCounter < chunks) then
  328.     PlaceChunkBack()
  329.     RetrieveChunkLeft()
  330.   end
  331. end
  332.  
  333.  
  334. function Main()
  335.   while(true) do
  336.   print("Mining")
  337.   if(distance % 2 == 0) then
  338.     chunks = chunks + 2
  339.   else
  340.     chunks = chunks - 1
  341.   end
  342.   for i = 1 , chunks do
  343.     chunkCounter = chunkCounter + 1
  344.     if(distance % 2 == 0) then
  345.       OZ()
  346.       if(chunks > chunkCounter) then
  347.         TurnRight()
  348.       end
  349.       DigForward()
  350.       if(chunks > chunkCounter) then
  351.         TurnRight()
  352.       else
  353.     TurnLeft()
  354.       end
  355.     else
  356.       NO()
  357.       TurnLeft()
  358.       DigForward()
  359.       if(chunks > chunkCounter) then
  360.         TurnLeft()
  361.       end
  362.     end
  363.   end
  364.   chunkCounter = 0
  365.   distance = distance + 1
  366.   if(distance == 2) then
  367.     chunks = chunks - 1
  368.   end
  369.   end --while end
  370. end
  371.  
  372. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement