MrCervelo

Rubber Tree Tapper

Jan 24th, 2013
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. function tapTree()
  2.   for i=1,4 do
  3.     if ( i%2 == 1 ) then
  4.       while ( turtle.detect() ) do
  5.         turtle.dig()
  6.         turtle.up()
  7.       end
  8.     else
  9.       while ( not turtle.detectDown() ) do
  10.         turtle.down()
  11.         turtle.dig()
  12.       end
  13.     end
  14.     if ( i ~= 4 ) then
  15.       changeSides()
  16.     end
  17.   end
  18. end
  19.  
  20. function changeSides()
  21.   turtle.turnLeft()
  22.   turtle.forward()
  23.   turtle.turnRight()
  24.   turtle.forward()
  25.   turtle.turnRight()
  26. end
  27.  
  28. function changeTrees()
  29.   turtle.turnRight()
  30.   turtle.forward()
  31.   turtle.turnLeft()
  32.   turtle.forward()
  33.   turtle.turnRight()
  34. end
  35.  
  36. function changeRows(rowNumber)
  37.   turtle.turnRight()
  38.   turtle.forward()
  39.   if ( rowNumber % 2 == 0 ) then
  40.     turtle.turnLeft()
  41.     for i=1,3 do
  42.       turtle.forward()
  43.     end
  44.     turtle.turnLeft()
  45.   else
  46.     turtle.turnRight()
  47.     turtle.forward()
  48.     turtle.turnRight()
  49.   end
  50. end
  51.  
  52. function emptyInventory()
  53.   for i = 1,16 do
  54.     turtle.select(i)
  55.     turtle.drop()
  56.   end
  57.   turtle.select(1)
  58. end
  59.  
  60. function returnHome(treeCount, rowCount)
  61.   if ( rowCount % 2 == 1 ) then
  62.     turtle.turnLeft()
  63.     for i=1,(treeCount*2) do
  64.       turtle.forward()
  65.     end
  66.     turtle.turnRight()
  67.     for i=1,(rowCount*2-1) do
  68.       turtle.forward()
  69.     end
  70.     turtle.turnLeft()
  71.   else
  72.     turtle.turnRight()
  73.     turtle.forward()
  74.     turtle.turnRight()
  75.     for i=1,((rowCount*2)-3) do
  76.       turtle.forward()
  77.     end
  78.     turtle.turnLeft()
  79.     turtle.forward()
  80.   end
  81.   emptyInventory()
  82.   turtle.turnRight()
  83.   turtle.turnRight()
  84. end
  85.  
  86. args={ ... }
  87. treeCount=tonumber(args[1])
  88. rowCount=tonumber(args[2])
  89. while true do
  90.   print("Starting Resin Collection")
  91.   print(string.format("There are %d Trees in %d Rows", treeCount, rowCount))
  92.   turtle.forward()
  93.   for i=1,rowCount do
  94.     for j=1,treeCount do
  95.       print(string.format("Starting Tree %d in Row %d", j, i))
  96.       tapTree()
  97.       if ( j ~= treeCount ) then
  98.         changeTrees()
  99.       end
  100.     end
  101.     print(string.format("Completed Row %d", i))
  102.     if ( i ~= rowCount ) then
  103.       changeRows(i)
  104.     end
  105.   end
  106.   print("Completed Tree Tapping, Returning Home")
  107.   returnHome(treeCount, rowCount)
  108.   emptyInventory()
  109.   print("Cycle Complete, sleeping for 5 minutes")
  110.   sleep(300)
  111. end
Advertisement
Add Comment
Please, Sign In to add comment