Lion_Kor

treefarm (wip)

Apr 6th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. local success, data = turtle.inspectDown()
  2. woodtype = data.name
  3. print("farming wood type: ", woodtype)
  4. right = true
  5.  
  6. function harvest()
  7.     turtle.select(1)
  8.  
  9.     local success, data = turtle.inspect()
  10.     wood = data.name
  11.     print(wood)
  12.    
  13.     while turtle.detect() do
  14.         turtle.dig()
  15.     end
  16.    
  17.     turtle.forward()
  18.    
  19.     while true do
  20.         local success, data = turtle.inspectUp()
  21.         if data.name == wood then
  22.             turtle.digUp()
  23.             turtle.up()
  24.         else
  25.             break
  26.         end
  27.     end
  28.    
  29.     while not turtle.detectDown() do
  30.         turtle.down()
  31.     end
  32.     turtle.back()
  33. end
  34.  
  35. function test()
  36.     local success, data = turtle.inspect()
  37.     if data.name == woodtype then
  38.         harvest()
  39.         return true
  40.     end
  41.     return false
  42. end
  43.  
  44. function move()
  45.     while not turtle.detect() do
  46.         turtle.forward()
  47.     end
  48.    
  49.     if not test() then
  50.         if right then
  51.             turtle.turnRight()
  52.             test()
  53.             turtle.forward()
  54.             test()
  55.             turtle.turnRight()
  56.             right = not right
  57.         else
  58.             turtle.turnLeft()
  59.             test()
  60.             turtle.forward()
  61.             test()
  62.             turtle.turnLeft()
  63.             right = not right
  64.         end
  65.     end
  66. end
  67.  
  68. function main()
  69.     while true do
  70.         move()
  71.     end
  72. end
  73.  
  74. main()
Advertisement
Add Comment
Please, Sign In to add comment