Advertisement
Xenogami

treebot2.0

Feb 9th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. -- Keeps track of what side the tree is on true is right false is left
  2. local wSide = true
  3.  
  4. -- Stay fueled up, uses the logs it harvests for fuel
  5. local function fuelTime()
  6.   if turtle.getFuelLevel() < 200 then
  7.     turtle.select(2)
  8.     turtle.refuel(1)
  9.     turtle.select(1)
  10.   end
  11. end
  12.  
  13. local function chopTime()
  14. -- Determines if the tree is on the left or right.
  15.   if wSide then
  16.     turtle.turnRight()
  17.   else
  18.     turtle.turnLeft()
  19.   end
  20. -- If there is somthing there try to harvest it.
  21.   if turtle.detect() then
  22.     turtle.dig()
  23.     turtle.forward()
  24. -- Climbs the tree
  25.     while turtle.detectUp() do
  26.       turtle.digUp()
  27.       turtle.up()
  28.     end
  29. -- Goes back to the ground
  30.     while not turtle.detectDown() do
  31.       turtle.down()
  32.     end
  33.     turtle.back()
  34.   end
  35. -- If there is nothing there plant a sapling
  36.   if not turtle.detect() then
  37.     turtle.select(1)
  38.     turtle.place()
  39.   end
  40. -- Determines what direction it wants to go
  41.   if wSide then
  42.     turtle.turnLeft()
  43.   else
  44.     turtle.turnRight()
  45.   end
  46. end
  47.  
  48. -- Moves to the next tree
  49. local function nextRow()
  50.   for i=1,4 do
  51.     turtle.forward()
  52.   end
  53. end
  54.  
  55. -- Moves to the next column of trees
  56. local function nextColumn()
  57.   turtle.forward()
  58.   if wSide then
  59.     turtle.turnRight()
  60.   else
  61.     turtle.turnLeft()
  62.   end
  63.   for i=1,4 do
  64.     turtle.forward()
  65.   end
  66.   if wSide then
  67.     turtle.turnRight()
  68.   else
  69.     turtle.turnLeft()
  70.   end
  71.     turtle.forward()
  72. -- Lets it know what side of the trees it is on
  73.     wSide = not wSide
  74. end
  75.  
  76. -- Returns back to the starting point
  77. local function homeTime()
  78.   for i=1,26 do
  79.     turtle.back()
  80.   end
  81.     turtle.turnLeft()
  82.   for i=1,24 do
  83.     turtle.forward()
  84.   end
  85.   turtle.turnRight()
  86.   wSide = true
  87. end
  88.  
  89. -- Drops what it picked up into a water flow below
  90. local function dropLoot()
  91.   for i=3,16 do
  92.     turtle.select(i)
  93.     turtle.dropDown()
  94.   end
  95.   turtle.select(1)
  96. end
  97.  
  98. -- make it run
  99. while true do
  100.   fuelTime()
  101.   turtle.forward()
  102.   turtle.forward()
  103.   for i=1,7 do
  104.     fuelTime()
  105.     for n=1,7 do
  106.       chopTime()
  107.       dropLoot()
  108.       if n < 7 then
  109.         nextRow()
  110.       end
  111.     end
  112.     if i < 7 then
  113.       nextColumn()
  114.     end
  115.   end
  116.   homeTime()
  117. -- Pause for 2 min while the trees regrow
  118.   os.sleep(120)
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement