Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Static variables (Settings)
- leaves = {"minecraft:leaves"}
- log = {"minecraft:log"}
- dirt = {"minecraft:dirt", "minecraft:grass"}
- sapling = {"minecraft:sapling"}
- chest = {"minecraft:chest"}
- turnLeft = {"minecraft:planks"}
- turnRight = {"minecraft:double_wooden_slab"}
- goUp = {"minecraft:cobblestone"}
- inventory_size = 16
- fuel_level = 5000
- sapling_slots = 1
- -- Functions
- function isType(e, t)
- if e == nil then
- return false
- end
- i = 1
- while(t[i] ~= nil) do
- if(e.name == t[i]) then
- return true
- end
- i = i + 1
- end
- return false
- end
- function PlaceSapling()
- for i = 1, inventory_size, 1 do
- item = turtle.getItemDetail(i)
- if isType(item, sapling) then
- turtle.select(i)
- turtle.placeDown()
- return true
- end
- end
- return false
- end
- function turtleMove(dir)
- check = {forward = turtle.inspect, up = turtle.inspectUp, down = turtle.inspectDown}
- move = {forward = turtle.forward, up = turtle.up, down = turtle.down}
- dig = {forward = turtle.dig, up = turtle.digUp, down = turtle.digDown}
- attack = {forward = turtle.attack, up = turtle.attackUp, down = turtle.attackDown}
- while attack[dir]() do
- os.sleep(0.05)
- end
- _, block = check[dir]()
- if isType(block, leaves) then
- dig[dir]()
- end
- return move[dir]()
- end
- function unload()
- -- Clear sapling spaces
- for i = 1, sapling_slots, 1 do
- turtle.select(i)
- item = turtle.getItemDetail()
- if isType(item, sapling) == false then
- turtle.dropDown()
- end
- end
- -- Clear remaining inventory
- for i = sapling_slots + 1, inventory_size, 1 do
- turtle.select(i)
- item = turtle.getItemDetail()
- if isType(item, sapling) then
- for n = 1, sapling_slots, 1 do
- turtle.transferTo(n)
- end
- end
- turtle.dropDown()
- end
- end
- function refuel()
- turtle.select(inventory_size)
- turtle.drop()
- while turtle.getFuelLevel() < fuel_level do
- turtle.suckUp(1)
- turtle.refuel()
- end
- turtle.suck()
- end
- function checkChests()
- chests_found = false
- -- Unload
- _, block = turtle.inspectDown()
- if isType(block, chest) then
- unload()
- chests_found = true
- end
- -- Refuel
- _, block = turtle.inspectUp()
- if isType(block, chest) then
- refuel()
- chests_found = true
- end
- return chests_found
- end
- -- Do startup
- turtleMove("up")
- -- Main loop
- while (1) do
- turtle.suck()
- _, block = turtle.inspect()
- -- Handle trees
- if isType(block, log) then
- while turtle.dig() == false do
- os.sleep(0.05)
- end
- turtleMove("up")
- elseif isType(block, sapling) then
- turtleMove("up")
- turtleMove("forward")
- -- Handle control blocks
- elseif isType(block, turnLeft) then
- turtle.turnLeft()
- elseif isType(block, turnRight) then
- turtle.turnRight()
- elseif isType(block, goUp) then
- while (isType(block, goUp)) do
- turtleMove("up")
- _, block = turtle.inspect()
- end
- turtleMove("forward")
- -- Handle chests
- elseif checkChests() then
- turtleMove("forward")
- else
- -- Check ground
- if turtleMove("down") == false then
- _, block = turtle.inspectDown()
- if isType(block, dirt) then
- turtleMove("up")
- PlaceSapling()
- end
- turtleMove("forward")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement