Advertisement
dealingwith

Dark Oak Farmer

Feb 23rd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. function fuel()
  2.   if turtle.getFuelLevel() < 30 then
  3.     turtle.select(1)
  4.     if turtle.refuel(1) then
  5.       return true
  6.     end
  7.     print("Refuelling failed.")
  8.     return false
  9.   end
  10. end
  11.  
  12. function right()
  13.   turtle.turnRight()
  14. end
  15.  
  16. function left()
  17.   turtle.turnLeft()
  18. end
  19.  
  20. function forward()
  21.   turtle.forward()
  22. end
  23.  
  24. function shiftRight()
  25.   right()
  26.   forward()
  27.   left()
  28. end
  29.  
  30. function shiftLeft()
  31.   left()
  32.   forward()
  33.   right()
  34. end
  35.  
  36. function fif(val, a, b)
  37.   if val then a() else b() end
  38. end
  39.  
  40. function fifFlip(val, a, b)
  41.   if val then a() else b() end
  42.   return not val
  43. end
  44.  
  45. function dig()
  46.   if turtle.detect() then
  47.     turtle.dig()
  48.   end
  49. end
  50.  
  51. function fell()
  52.   fuel()
  53.   for i=1,10,1 do
  54.     dig()
  55.     turtle.digUp()
  56.     turtle.up()
  57.   end
  58.  
  59.   fuel()
  60.   for i=1,10,1 do
  61.     turtle.down()
  62.   end
  63. end
  64.  
  65. function fellDarkOak()
  66.   local left = true
  67.   for a=1,4,1 do
  68.     forward()
  69.     fell()
  70.     for b=1,4,1 do
  71.       fif(left, shiftRight, shiftLeft)
  72.       fell()
  73.     end
  74.     left = not left
  75.   end
  76. end
  77.  
  78. function placeSapling()
  79.   turtle.select(3)
  80.   turtle.placeDown()
  81. end
  82.  
  83. function dump(start_point,end_point)
  84.   for i=start_point,end_point,1 do
  85.     turtle.select(i)
  86.     turtle.drop()
  87.   end
  88. end
  89.  
  90. function detectTree()
  91.   turtle.select(2)
  92.   if turtle.compare() then
  93.     return true
  94.   else
  95.     return false
  96.   end
  97. end
  98.  
  99. function turnAround()
  100.   right()
  101.   right()
  102. end
  103.  
  104. go = true
  105. while go do
  106.   go = fuel()
  107.   go = turtle.getItemCount(3) > 3
  108.   tree = false
  109.   tries = 0
  110.   while not detectTree() do
  111.     print("Tried " .. tries .. ". No tree. Waiting a minute")
  112.     os.sleep(60)
  113.     tries = tries + 1
  114.   end
  115.   turnAround()
  116.   forward()
  117.   forward()
  118.   turnAround()
  119.   -- farm that tree
  120.   shiftLeft()
  121.   fellDarkOak()
  122.   right()
  123.   turtle.up()
  124.   forward()
  125.   placeSapling()
  126.   forward()
  127.   placeSapling()
  128.   right()
  129.   forward()
  130.   placeSapling()
  131.   right()
  132.   forward()
  133.   placeSapling()
  134.   forward()
  135.   left()
  136.   turtle.down()
  137.   for i=1,5,1 do
  138.     forward()
  139.   end
  140.   dump(4,16)
  141.   left()
  142.   forward()
  143.   left()
  144.   for i=1,4,1 do
  145.     forward()
  146.   end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement