LuaDotExe

Computercraft Simple Tree Turtle

Jan 9th, 2021 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 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.         if not (iData == nil) then
  40.             if inTable(iData.name, saplings) then
  41.                 turtle.place()
  42.                 break
  43.             end
  44.         end
  45.     end
  46. end
  47.  
  48. function refuel()
  49.     for i = 1, 16 do
  50.         turtle.select(i)
  51.         if turtle.refuel(0) then
  52.             local halfStack = math.ceil(turtle.getItemCount(i)/2)
  53.             turtle.refuel(halfStack)
  54.         end
  55.     end
  56. end
  57.  
  58. function inTable(obj, table)
  59.     for i in pairs(table) do
  60.         if obj == table[i] then return true end
  61.     end
  62.     return false
  63. end
  64.  
  65. function shiftRight()
  66.     turtle.turnRight()
  67.     turtle.forward()
  68.     turtle.turnLeft()
  69. end
  70.  
  71. function shiftLeft()
  72.     turtle.turnLeft()
  73.     turtle.forward()
  74.     turtle.turnRight()
  75. end
  76.  
  77. function move()
  78.     success, data = turtle.inspect()
  79.     if not (inTable(data.name, saplings) or inTable(data.name, logs)) then
  80.         turningRight = not turningRight
  81.     end
  82.     if turningRight then shiftRight()
  83.     else shiftLeft()
  84.     end
  85. end
  86.  
  87. while true do
  88.     if turtle.getFuelLevel() < 11 then
  89.         refuel()
  90.     end
  91.     move()
  92.     -- os.sleep(0.5)
  93.     fell()
  94.    
  95. end
Add Comment
Please, Sign In to add comment