Fatherless

startup

Dec 18th, 2024 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. --[[
  2.  
  3. This program will tell a turtle to cut down a 1x1 spruce tree.
  4. This should be passive and shouldn't have to be activated by the user
  5. There will probably be a helper computer to sort the logs and saplings from eachother.
  6. The turtle should only move in a line up and down.
  7. It will dump everything into the inventory below it.
  8. Assume that there are hoppers to collect all of the dropped saplings.
  9. The inventory below it should contain any saplings that are dropped. (Supposedly in the first slot)
  10. ]]
  11.  
  12. --[[ Constants ]]
  13.  
  14. MAX_HEIGHT = 12 -- Maximum height of a 1x1 spruce tree
  15.  
  16. --[[ Functions ]]
  17.  
  18. local function up() -- Moves turtle up one block, breaking any block in the way
  19. while not turtle.up() do
  20. turtle.digUp()
  21. end
  22. end
  23.  
  24. local function reset() -- Resets turtle to starting position
  25. while turtle.down() do end
  26. end
  27.  
  28. local function fell() -- Turtle chops a tree down and resets to starting position
  29. repeat
  30. turtle.dig()
  31. up()
  32. until not turtle.detect()
  33. reset()
  34. end
  35.  
  36. local function deposit()
  37. turtle.select(1)
  38. turtle.refuel(2)
  39. for i = 1, 16 do
  40. turtle.select(i)
  41. turtle.dropDown()
  42. end
  43. end
  44.  
  45. local function plant() -- Turtle retrieves a sapling and plants it in front of it
  46. turtle.select(1)
  47. turtle.suckDown(1)
  48. turtle.place()
  49. end
  50.  
  51. local function isAirborne() -- Returns true if the turtle is in the air (might not be necessary)
  52. return not turtle.detectDown()
  53. end
  54.  
  55.  
  56. --[[ Main ]]
  57.  
  58. if isAirborne then
  59. fell()
  60. deposit()
  61. plant()
  62. end
  63.  
  64. if not turtle.detect() then
  65. deposit()
  66. plant()
  67. end
  68.  
  69. while true do
  70. local has_block, data = turtle.inspect()
  71. if has_block and data.name == "minecraft:spruce_log" then
  72. fell()
  73. deposit()
  74. plant()
  75. end
  76. end
  77.  
Advertisement
Add Comment
Please, Sign In to add comment