Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This program will tell a turtle to cut down a 1x1 spruce tree.
- This should be passive and shouldn't have to be activated by the user
- There will probably be a helper computer to sort the logs and saplings from eachother.
- The turtle should only move in a line up and down.
- It will dump everything into the inventory below it.
- Assume that there are hoppers to collect all of the dropped saplings.
- The inventory below it should contain any saplings that are dropped. (Supposedly in the first slot)
- ]]
- --[[ Constants ]]
- MAX_HEIGHT = 12 -- Maximum height of a 1x1 spruce tree
- --[[ Functions ]]
- local function up() -- Moves turtle up one block, breaking any block in the way
- while not turtle.up() do
- turtle.digUp()
- end
- end
- local function reset() -- Resets turtle to starting position
- while turtle.down() do end
- end
- local function fell() -- Turtle chops a tree down and resets to starting position
- repeat
- turtle.dig()
- up()
- until not turtle.detect()
- reset()
- end
- local function deposit()
- turtle.select(1)
- turtle.refuel(2)
- for i = 1, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- local function plant() -- Turtle retrieves a sapling and plants it in front of it
- turtle.select(1)
- turtle.suckDown(1)
- turtle.place()
- end
- local function isAirborne() -- Returns true if the turtle is in the air (might not be necessary)
- return not turtle.detectDown()
- end
- --[[ Main ]]
- if isAirborne then
- fell()
- deposit()
- plant()
- end
- if not turtle.detect() then
- deposit()
- plant()
- end
- while true do
- local has_block, data = turtle.inspect()
- if has_block and data.name == "minecraft:spruce_log" then
- fell()
- deposit()
- plant()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment