Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --version: 2.16
- saplingSlot = 1
- minimumSaplings = 4
- minimumFuelLevel = 128
- compareSlot = 16 --put there a block to compare with
- compareBlockDir = "compareDown" --where the same block is placed // "compareDown" or "compareUp"
- chestDir = "dropUp"
- plantSaplings = true
- --DO NOT TOUCH THE CODE BELOW
- local args = { ... }
- local height = 0
- local work = true
- function drop_all_items()
- for i = 2, 14 do
- if turtle.getItemCount(i)~=0 then
- turtle.select(i)
- turtle[chestDir]()
- end
- end
- turtle.select(saplingSlot)
- end
- function checkSaplings()
- if turtle.getItemCount(saplingSlot)>=minimumSaplings then
- return true
- end
- print("Not enough saplings!")
- return false
- end
- function plant2x2()
- if plantSaplings then
- turtle.place()
- turtle.turnRight()
- turtle.back()
- turtle.place()
- turtle.turnLeft()
- turtle.place()
- turtle.back()
- turtle.place()
- end
- end
- function cutUp()
- turtle.digUp()
- turtle.up()
- end
- function cutDown()
- turtle.digDown()
- turtle.down()
- end
- function run()
- height = 0
- turtle.select( saplingSlot )
- -- chop down the first block
- turtle.dig()
- turtle.forward() -- ]]
- while turtle.digUp()==true do
- turtle.dig()
- turtle.up()
- height = height + 1 --count height of the tree
- end
- turtle.turnRight(); turtle.dig(); turtle.forward(); turtle.turnLeft() --turn on the top
- for i=1, height do
- cutDown()
- turtle.dig()
- end
- --print("End of tree or no blocks found. End of while")
- --Only plants from
- -- ##
- -- #@
- plant2x2()
- drop_all_items()
- print("Jobs done! Current height: " ..height)
- end
- function continueDown()
- turtle.select( compareSlot )
- while turtle.compareDown()==false do cutDown(); turtle.dig() end
- print("detectDown==false //01")
- turtle.select( saplingSlot )
- plant2x2(); drop_all_items()
- end
- function continueUp()
- height = 0
- if turtle.detect() then turtle.dig() end
- while turtle.digUp()==true do
- turtle.dig()
- turtle.up()
- height = height + 1 --count height of the tree
- end
- turtle.turnRight(); turtle.dig(); turtle.forward(); turtle.turnLeft() --turn on the top
- for i=1, height do
- cutDown()
- turtle.dig()
- end
- print("Sucessfully worked with given height, continueDown")
- continueDown()
- end
- function detectDirection()
- turtle.select(compareSlot)
- if turtle[ compareBlockDir ]() then --everythings fine, we're on the floor
- print("Dir: I am on the floor")
- turtle.select( saplingSlot ) --bug fixed in 2.15
- return true
- end
- turtle.select(saplingSlot)
- if turtle.detectUp() then
- if turtle.detect() then turtle.dig() end
- continueUp()
- elseif turtle.detectDown() then
- if turtle.detect() then turtle.dig() end
- continueDown()
- else
- if turtle.up() and turtle.detectUp() then --if there's a 1 block space between tree and turtle
- continueUp()
- elseif turtle.down() and turtle.down() and turtle.detectDown() then
- continueDown()
- else
- print("Can't find the tree or I ran out of fuel")
- print("Fuel level: "..turtle.getFuelLevel())
- shell.exit()
- end
- end
- turtle.select(saplingSlot)
- end
- local function work()
- while os.pullEvent("work") do
- if turtle.compare()==true then --sleep if it's the sapling
- --mySleep() --15sec
- else
- if checkSaplings() then
- run()
- else
- work = false
- end
- --mySleep() --60sec
- end
- end
- end
- local function keyInput()
- sleep(.1) os.queueEvent("start")
- while true do
- local event, char = os.pullEvent("char")
- if char == "s" then
- print("Stopped working!")
- work = false
- elseif char == "g" then -- go
- print("Beginning to work!")
- work = true
- os.queueEvent("start")
- os.queueEvent("work")
- elseif char == "p" then
- print("Getting current direction...")
- detectDirection()
- elseif char == "l" then
- print("Exitting...")
- break
- end
- end
- end
- local function mySleepTimer()
- while os.pullEvent("start") do
- while work do
- os.queueEvent("work")
- sleep(15)
- end
- end
- end
- if turtle.getFuelLevel()<minimumFuelLevel then
- print("I don't have fuel!")
- shell.exit()
- end
- print("Hello!")
- print("Keys avaible:\n")
- print("S - stop working\nG - Go & Work\nP - get current position and work\nL - exit")
- if #args==1 then
- if turtle.getItemCount(compareSlot)~=0 and checkSaplings() then
- print("Continuing my job!")
- detectDirection()
- print("dDir end")
- else print("Setup me properly first!"); error()
- end
- end
- turtle.select(saplingSlot)
- parallel.waitForAny(work, keyInput, mySleepTimer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement