Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NOTE FOR NORMAL MINECRAFT USE cutTree() INSTEAD OF THE FOR LOOP WITH turtle.dig()
- os.loadAPI("turtleChest.lua")
- function findStartPosition()
- for i = 1, 4 do
- success, item = turtle.inspect()
- if item.name == "minecraft:chest" then
- break
- end
- turtle.turnLeft()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function checkList(list, thing)
- for _, str in ipairs(list) do
- if thing == str then
- return true
- end
- end
- return false
- end
- function cutTree(logNames)
- height = 0
- turtle.dig()
- turtle.forward()
- success, item = turtle.inspectUp()
- while checkList(logNames, item.name) do
- turtle.digUp()
- turtle.up()
- height = height + 1
- success, item = turtle.inspectUp()
- end
- for i = 0, height do
- turtle.down()
- end
- turtle.back()
- end
- function guessAndCheckAll()
- turtle.turnRight()
- turtleChest.insertAll()
- end
- function guessAndCheckSome()
- turtle.turnRight()
- turtleChest.insertSome(2)
- end
- function refuelSaplings()
- turtle.select(1)
- turtle.suckDown()
- if turtle.getItemCount(1) == 0 then
- sapling = false
- return "out"
- else
- turtle.place()
- end
- end
- function placeSapling(saplingNames)
- turtle.place()
- success, item = turtle.inspect()
- if item.name == nil then
- return refuelSaplings()
- end
- --if turtle accidentally doesn't place a sapling
- if not checkList(saplingNames, item.name) then
- turtle.dig()
- for i = 1, 4 do
- guessAndCheckAll()
- end
- -- if Chest is full (since turtle isn't empty)
- if turtleChest.countCheck(count) ~= 0 then
- full = true
- return "out"
- else
- return refuelSaplings()
- end
- end
- end
- logNames = {
- "minecraft:oak_log",
- "minecraft:spruce_log",
- "minecraft:birch_log",
- "minecraft:jungle_log",
- "minecraft:acacia_log",
- "minecraft:dark_oak_log",
- "minecraft:crimson_stem",
- "minecraft:warped_stem",
- }
- saplingNames = {
- "minecraft:oak_sapling",
- "minecraft:spruce_sapling",
- "minecraft:birch_sapling",
- "minecraft:jungle_sapling",
- "minecraft:acacia_sapling",
- "minecraft:dark_oak_sapling",
- "minecraft:azalea",
- "minecraft:flowering_azalea",
- }
- fuel = turtle.getFuelLevel()
- success = true
- sapling = true
- full = false
- left = 0
- findStartPosition()
- turtle.select(1)
- if turtle.getItemCount(1) == 0 then
- turtle.suckDown()
- end
- turtle.turnLeft()
- placeSapling(saplingNames)
- turtle.turnRight()
- placeSapling(saplingNames)
- turtle.turnRight()
- placeSapling(saplingNames)
- while fuel >= 100 and sapling == true and not full do
- success, item = turtle.inspect()
- if fuel >= 100 then
- if item ~= nil and checkList(logNames, item.name) then
- cutTree(logNames)
- turtle.suckUp()
- turtle.suck()
- if placeSapling(saplingNames) == "out" then
- break
- end
- for i = 1, 4 do
- guessAndCheckSome()
- turtle.turnRight()
- end
- end
- fuel = turtle.getFuelLevel()
- end
- turtle.turnLeft()
- left = left + 1
- if left == 3 then
- turtle.turnLeft()
- left = 0
- end
- end
- findStartPosition()
- if fuel <= 100 then
- print("Stopping: Fuel Level Low")
- elseif full == true then
- print("Stopping: Chest Full")
- else
- print("Stopping: Out of Saplings")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement