dealingwith

Double oak farmer

Oct 30th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. -- tree farmer
  2. -- requires a very specific tree farm setup
  3. --   which I will document somewhere and
  4. --   put a link to when that's done
  5. -- put fuel in first slot
  6. -- put 1 block of wood type in second slot
  7. -- put saplings of wood type in third slot
  8.  
  9. function fuel()
  10.   if turtle.getFuelLevel() < 30 then
  11.     turtle.select(1)
  12.     if turtle.refuel(1) then
  13.       return true
  14.     end
  15.     print("Refuelling failed.")
  16.     return false
  17.   end
  18. end
  19.  
  20. function chop ()
  21.   local blocksMovedUp = 0
  22.   while turtle.detect() do
  23.     fuel()
  24.     turtle.dig()
  25.     if turtle.detectUp() then
  26.       turtle.digUp()
  27.     end
  28.     turtle.up()
  29.     blocksMovedUp = blocksMovedUp + 1
  30.   end
  31.   while blocksMovedUp > 0 do
  32.     fuel()
  33.     turtle.down()
  34.     blocksMovedUp = blocksMovedUp - 1
  35.   end
  36.   -- plant new tree
  37.   turtle.select(3)
  38.   turtle.place()
  39.   return true
  40. end
  41.  
  42. function detectTree()
  43.   turtle.select(2)
  44.   if turtle.compare() then
  45.     return true
  46.   else
  47.     return false
  48.   end
  49. end
  50.  
  51. function farmTree()
  52.     tries = 0
  53.     while not detectTree() do
  54.       print("Tried " .. tries .. ". No tree. Waiting a minute")
  55.       os.sleep(60)
  56.       tries = tries + 1
  57.     end
  58.     chop()
  59.     right()
  60.     right()
  61.     for i=4,16,1 do
  62.       turtle.select(i)
  63.       turtle.drop()
  64.     end
  65.     right()
  66.     right()
  67.     -- if there are no more saplings
  68.     if turtle.getItemCount(3) == 0 then
  69.       print("Out of samplings")
  70.       return false
  71.     end
  72.     return true
  73. end
  74.  
  75. function right()
  76.   turtle.turnRight()
  77. end
  78.  
  79. function left()
  80.   turtle.turnLeft()
  81. end
  82.  
  83. function fif(val, a, b)
  84.   if val then a() else b() end
  85. end
  86.  
  87. function fif_flip(val, b, b)
  88.   if val then a() else b() end
  89.   return not val
  90. end
  91.  
  92. local args = {...}
  93. if #args > 1 or type(args[1]) ~= "string" then
  94.   print("Takes argument: <right/left>")
  95.   return
  96. end
  97.  
  98. ret = true
  99. left_tree = args[1] == "left"
  100. while ret == true do
  101.   ret = farmTree()
  102.   fif(left_tree, right, left)
  103.   for i=1,10,1 do
  104.     turtle.forward()
  105.   end
  106.   fif(left_tree, left, right)
  107.   left_tree = not left_tree
  108. end
Advertisement
Add Comment
Please, Sign In to add comment