Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --minecraft:dirt
- --minecraft:chest
- --minecraft:log(meta 2)
- --minecraft:leaves(meta 2)
- --minecraft:sapling(damage 2)
- --minecraft:log(damage 2)
- args = {...}
- function getInventory()
- local inventory = {}
- for i=1,16 do
- if (turtle.getItemDetail(i)) then
- data = turtle.getItemDetail(i)
- data["slot"] = i
- table.insert(inventory, data)
- end
- end
- return inventory
- end
- function digWalls()
- for i=1,4 do
- turtle.dig()
- turtle.turnLeft()
- end
- end
- -- sort
- function sortInvent(item)
- --sortInvent("minecraft:sapling")
- local inventory = getInventory()
- for k,v in pairs(inventory) do
- if (k ~= 1 and inventory[1].count < 64 and inventory[1].name == item) then
- turtle.select(inventory[k].slot)
- turtle.transferTo(inventory[1].slot)
- inventory[1].count = inventory[1].count + inventory[k].count
- end
- end
- end
- -- depo
- -- keep first stack of saplings depo everything else
- function deposit()
- local success, data = turtle.inspectDown()
- if (not success or (success and data.name ~= "minecraft:chest")) then
- return
- end
- sortInvent()
- local inventory = getInventory()
- local sapling_slot = nil
- for k,v in pairs(inventory) do
- if (sapling_slot == nil and inventory[k].name == "minecraft:sapling") then sapling_slot = inventory[k].slot end
- if (inventory[k].slot ~= sapling_slot) then
- turtle.select(inventory[k].slot)
- turtle.dropDown()
- end
- end
- end
- -- check space:
- function detect()
- local success,data = turtle.inspect()
- if (not success) then
- -- plant if no log or sapling
- plant()
- elseif (success and data.name == "minecraft:log") then
- felling()
- end
- end
- -- felling:
- function felling()
- -- dig, forward
- turtle.dig()
- turtle.forward()
- -- loop dig up
- while turtle.digUp() do
- turtle.up()
- -- check walls while digging up
- digWalls()
- end
- turtle.back()
- goDown()
- plant()
- end
- function goDown()
- local direction = "l"
- turtle.turnLeft()
- while true do
- local success, data = turtle.inspectDown()
- if (not success or (success and (data.name == "minecraft:log" or data.name == "minecraft:leaves"))) then
- turtle.digDown()
- turtle.down()
- for i=1,2 do
- turtle.dig()
- if (direction == "l") then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- turtle.dig()
- if (direction == "l") then
- direction = "r"
- else
- direction = "l"
- end
- else
- break
- end
- end
- if (direction == "l") then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- -- planting:
- function plant()
- -- find sapling in invent
- local inventory = getInventory()
- -- select sapling
- for k,v in pairs(inventory) do
- if (inventory[k].name == "minecraft:sapling") then
- turtle.select(inventory[k].slot)
- end
- end
- -- plant in front
- turtle.place()
- end
- -- traverse
- function traverse(distance, direction)
- distance = distance - 1
- while true do
- -- dance if no coal
- if (turtle.getFuelLevel() < distance * 10) then
- while true do
- turtle.turnRight()
- end
- end
- for i=1,distance do
- detect()
- --choose turn direction based on start pos
- if (direction == "r") then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- if (direction == "r") then
- direction = "l"
- else
- direction = "r"
- end
- detect()
- deposit()
- sleep(20)
- end
- end
- traverse(args[1],args[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement