LuaDotExe

ComputerCraft Line Tree Turtle

Jan 9th, 2021 (edited)
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local saplings = {"minecraft:oak_sapling", "minecraft:spruce_sapling", "minecraft:birch_sapling", "minecraft:jungle_sapling"}
  2. local logs = {"minecraft:oak_log", "minecraft:spruce_log", "minecraft:brich_log", "minecraft:jungle_log"}
  3. local turningRight = true
  4.  
  5. function fell()
  6.     success, data = turtle.inspect()
  7.     successDown = turtle.inspectDown()
  8.     breaker = false
  9.    
  10.     if success then
  11.        
  12.         -- Log
  13.         while inTable(data.name, logs) do
  14.            
  15.             os.sleep(0.5)
  16.             turtle.dig()
  17.             turtle.digUp()
  18.             turtle.up()
  19.             success, data = turtle.inspect()
  20.             successDown = turtle.inspectDown()
  21.            
  22.         end
  23.        
  24.         -- Reset
  25.         while not (success and successDown) do
  26.             turtle.down()
  27.             successDown = turtle.inspectDown()
  28.             if successDown then replant() end
  29.             success, data = turtle.inspect()
  30.         end
  31.    
  32.     end
  33. end
  34.  
  35. function replant()
  36.     for i = 1, 16 do
  37.         turtle.select(i)
  38.         iData = turtle.getItemDetail()
  39.         print(iData.name)
  40.         if inTable(iData.name, saplings) then
  41.             turtle.place()
  42.             break
  43.         end
  44.     end
  45. end
  46.  
  47. function refuel()
  48.     for i = 1, 16 do
  49.         turtle.select(i)
  50.         if turtle.refuel(0) then
  51.             local halfStack = math.ceil(turtle.getItemCount(i)/2)
  52.             turtle.refuel(halfStack)
  53.         end
  54.     end
  55. end
  56.  
  57. function inTable(obj, table)
  58.     for i in pairs(table) do
  59.         if obj == table[i] then return true end
  60.     end
  61.     return false
  62. end
  63.  
  64. function shiftRight()
  65.     turtle.turnRight()
  66.     turtle.forward()
  67.     turtle.turnLeft()
  68. end
  69.  
  70. function shiftLeft()
  71.     turtle.turnLeft()
  72.     turtle.forward()
  73.     turtle.turnRight()
  74. end
  75.  
  76. function move()
  77.     success, data = turtle.inspect()
  78.     if not (inTable(data.name, saplings) or inTable(data.name, logs)) then
  79.         turningRight = not turningRight
  80.     end
  81.     if turningRight then shiftRight()
  82.     else shiftLeft()
  83.     end
  84. end
  85.  
  86. while true do
  87.     if turtle.getFuelLevel() < 11 then
  88.         refuel()
  89.     end
  90.     move()
  91.     os.sleep(0.5)
  92.     fell()
  93.    
  94. end
Add Comment
Please, Sign In to add comment