Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bonemeal = true
- local bonemealSide = "right"
- turtle.select(1)
- log_list = { "minecraft:birch_log", "minecraft:oak_log", "minecraft:spruce_log", "minecraft:jungle_log", "minecraft:acacia_log", "minecraft:dark_oak_log" }
- sapling_list = {"minecraft:birch_sapling", "minecraft:oak_sapling", "minecraft:spruce_sapling", "minecraft:jungle_sapling", "minecraft:acacia_sapling", "minecraft:dark_oak_sapling"}
- chest = peripheral.find("minecraft:chest")
- local stop = false
- function chopBlock()
- succes, data = turtle.inspect()
- for i=1,#log_list do
- if (data.name == log_list[i]) then
- if turtle.dig() then
- return true
- end
- end
- end
- end
- function chopBlockUp()
- succes, data = turtle.inspectUp()
- for i=1,#log_list do
- if (data.name == log_list[i]) then
- if turtle.digUp() then
- return true
- end
- end
- end
- end
- function chopBlockUpDown()
- succes, data = turtle.inspectDown()
- for i=1,#log_list do
- if (data.name == log_list[i]) then
- if turtle.digDown() then
- return true
- end
- end
- end
- end
- function is_sapling(slot_number)
- if slot_number == nil then
- error("no slot number given") -- find out where function is called and set slot number
- end
- item = turtle.getItemDetail(slot_number)
- if item ~= nil then
- for i=1,#sapling_list do
- if (item.name == sapling_list[i]) then
- -- print("is sapling")
- return true
- else
- -- print("is not sapling")
- return false
- end
- end
- else
- return false
- end
- end
- function place_sapling()
- if is_sapling(1) then
- if turtle.place() then
- return true
- end
- else
- return false
- end
- end
- function turn_around()
- turtle.turnRight()
- turtle.turnRight()
- end
- function get_sapling()
- local stop = false
- if (chest ~= nil) then
- if peripheral.isPresent("top") then
- print("chest found on the top, not optimal!")
- elseif peripheral.isPresent("front") then
- print("Can't place a chest here this is where the sapling must be")
- elseif peripheral.isPresent("right") then
- print("chest found on the right")
- elseif peripheral.isPresent("bottom") then
- print("chest found on the bottom")
- elseif peripheral.isPresent("back") then
- print("chest found on the back")
- turn_around()
- for slot=2, 16 do
- turtle.select(slot)
- turtle.suck()
- item = turtle.getItemDetail(slot)
- for i=1,#sapling_list do
- if item ~= nil then
- if item.name == sapling_list[i] then
- if not turtle.transferTo(1) then
- turtle.select(1)
- turtle.drop()
- turtle.select(slot)
- turtle.transferTo(1)
- end
- stop = true
- end
- end
- end
- if stop then
- break
- end
- end
- for slot=2, 16 do
- turtle.select(slot)
- turtle.drop()
- end
- turn_around()
- end
- else
- -- no chests found
- if not is_sapling(1) then
- turtle.drop()
- end
- while turtle.getItemCount(1) == 0 do
- print("need saplings!")
- -- if there's no tree find saplings
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- -- if there no items complain!
- for slot=2, 16 do
- turtle.select(slot)
- if is_sapling(slot) then
- turtle.select(1)
- turtle.dropUp()
- turtle.select(slot)
- turtle.transferTo(1)
- break
- end
- end
- turtle.select(1)
- end
- end
- turtle.select(1)
- end
- function is_sapling_infront()
- succes, item = turtle.inspect()
- if item ~= nil then
- for i=1,#sapling_list do
- if (item.name == sapling_list[i]) then
- return true
- else
- return false
- end
- end
- else
- return false
- end
- end
- print("computer ID: "..os.getComputerID())
- while true do
- if turtle.getFuelLevel() >= 20 then
- if chopBlock() then
- turtle.forward()
- while chopBlockUp() do
- turtle.up()
- end
- while turtle.down() do
- -- nothing
- end
- turtle.back()
- end
- if not turtle.detect() then
- if not place_sapling() then
- -- turtle.drop()
- get_sapling()
- end
- end
- -- wait for tree to grow
- if bonemeal then
- if is_sapling_infront() then
- rs.setOutput(bonemealSide, true)
- os.sleep(0.1)
- rs.setOutput(bonemealSide, false)
- os.sleep(0.1)
- end
- end
- else
- print("Turtle fuel level low ["..turtle.getFuelLevel().."]")
- os.sleep(5)
- end
- os.sleep(0.5)
- end
Add Comment
Please, Sign In to add comment