Advertisement
darktagnan

followLine

Oct 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. function cutDownTree()
  2.     print("Cutting down tree")
  3.     s, d = turtle.inspect()
  4.     while s do
  5.         turtle.dig()
  6.         turtle.digUp()
  7.         turtle.up()
  8.         s, d = turtle.inspect()
  9.     end
  10.    
  11.     print("Going down")
  12.     s, d = turtle.inspectDown()
  13.     while not s do
  14.         turtle.down()
  15.         s, d = turtle.inspectDown()
  16.     end
  17.     print("Tree down")
  18. end
  19.  
  20. function getAroundTree()
  21.     print("Getting around tree")
  22.     turtle.turnRight()
  23.     turtle.forward()
  24.     turtle.turnLeft()
  25.     turtle.forward()
  26.     turtle.forward()
  27.     turtle.turnLeft()
  28.     turtle.forward()
  29.     turtle.turnRight()
  30. end
  31.  
  32. function tryForward()
  33.     -- Try to go forward
  34.     if not turtle.forward() then
  35.         s, d = turtle.inspect()
  36.         if d.name == "ic2:rubber_wood" then
  37.             cutDownTree()
  38.             return true
  39.         elseif d.name == "ic2:sapling" then
  40.             getAroundTree()
  41.             return true
  42.         else
  43.             print("Can not go forward")
  44.             return false    -- return false if stuck
  45.     end
  46.  
  47.     -- return false if not line
  48.     s, d = turtle.inspectDown()
  49.     if d.name ~= "minecraft:stone_slab" then
  50.         print("Line lost")
  51.         turtle.back()
  52.         return false
  53.     end
  54.     return true
  55. end
  56.  
  57. function followLine()
  58.     while true do
  59.         if not tryForward() then
  60.             turtle.turnRight()
  61.             if not tryForward() then
  62.                 turtle.turnLeft()
  63.                 turtle.turnLeft()
  64.  
  65.                 if not tryForward() then
  66.                     print("Stuck")
  67.                     return
  68.                 end
  69.             end
  70.         end
  71.     end
  72. end
  73.  
  74. followLine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement