Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- T T T
- --
- -- T T T
- -- S>
- -- W
- --
- -- > = turtle initial position
- -- W = chest for placing wood
- -- S = chest with saplings
- -- T = tree spots
- local sapling, wood = 1, 2
- local left, right = 1, 2
- local depth = 4 -- number of trees
- local width = 4 -- number of trees, must be divisable by 2
- local space = 3 -- distance between trees
- function CheckFuel()
- print( "Current fuel level: " .. turtle.getFuelLevel() )
- if ( turtle.getFuelLevel() < 200 ) then
- print( "Need more fuel! ahhh~")
- local attempts = 0
- shell.run("refuel")
- while ( attempts < 10 and turtle.getFuelLevel() < 200 ) do
- attempts = attempts + 1
- os.sleep(10)
- if ( turtle.getFuelLevel() >= 200 ) then
- print( "Delicious~, fuel now at " .. turtle.getFuelLevel() )
- return
- end
- end
- end
- end
- function UnloadInventory()
- woodAmount = turtle.getItemCount(wood)
- if ( woodAmount < 1 ) then
- print( "No logs loaded, dofus! Saplings in slot 1, wood in slot 2!" )
- local attempts = 0
- while ( attempts < 10 and woodAmount < 1 ) do
- os.sleep(10)
- woodAmount = turtle.getItemCount(wood)
- attempts = attempts + 1
- end
- if ( woodAmount < 1 ) then
- print "Ah, I give up."
- os.exit()
- return
- end
- end
- if ( woodAmount == 1 ) then
- return
- end
- turtle.select(wood)
- turtle.drop( woodAmount - 1 )
- local slotNumber = wood + 1
- while ( slotNumber <= 16 and turtle.getItemCount(slotNumber) > 0 ) do
- turtle.select(slotNumber)
- turtle.drop()
- slotNumber = slotNumber + 1
- end
- end
- function LoadSaplings()
- if ( turtle.getItemCount(sapling) > 0 ) then
- return
- end
- turtle.select(sapling)
- turtle.suck()
- end
- function moveForward(spaces)
- local count = 0
- while ( count < space ) do
- if ( turtle.forward() == false ) then
- local tries = 0
- os.sleep(3)
- while ( tries < 10 and turtle.forward() == false ) do
- tries = tries + 1
- os.sleep(3)
- end
- if ( tries >= 10 ) then
- print("I've been blocked!")
- os.exit()
- return
- end
- end
- count = count + 1
- end
- end
- function Turn(direction)
- if ( direction == left ) then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function AntiTurn(direction)
- if ( direction == right ) then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function CutDownTree()
- turtle.dig()
- if ( turtle.forward() == false ) then
- print( "Failed to cut down tree" )
- os.exit()
- return
- end
- local height = 0
- while ( turtle.detectUp() ) do
- turtle.digUp()
- if ( turtle.up() == false ) then
- print ( "Failed to cut up tree" )
- os.exit()
- return
- end
- height = height + 1
- end
- while ( height > 0 ) do
- if ( turtle.down() == false ) then
- print ( "Failed to succumb to gravity's embrace" )
- os.exit()
- return
- end
- height = height - 1
- end
- if ( turtle.back() == false ) then
- print ( "BEEP BEEP BEEP!" )
- os.exit()
- return
- end
- end
- function CutRow(direction)
- moveForward(space)
- local count = 0
- while ( count < depth ) do
- Turn(direction)
- turtle.select(wood)
- if ( turtle.compare() == true ) then
- CutDownTree()
- end
- turtle.select(sapling)
- turtle.place()
- AntiTurn(direction)
- moveForward(space)
- count = count + 1
- end
- end
- function ChopAllTrees()
- local loops = width / 2
- local loopCount = 1
- while ( loopCount <= loops ) do
- CutRow(left)
- turtle.turnLeft()
- moveForward(space)
- turtle.turnLeft()
- CutRow(right)
- turtle.turnRight()
- moveForward(space)
- turtle.turnRight()
- loopCount = loopCount + 1
- end
- end
- function ReturnHome()
- turtle.turnRight()
- -- local distanceToHome = ( space * ( width + 1 ) )
- -- moveForward(distanceToHome)
- while ( turtle.detect() == false ) do
- turtle.forward()
- end
- end
- -- main loop
- print("Running GauLogger!")
- if ( turtle.detect() == false ) then
- turtle.turnRight()
- end
- UnloadInventory()
- while true do
- CheckFuel()
- turtle.turnRight()
- LoadSaplings()
- turtle.turnLeft()
- turtle.turnLeft()
- ChopAllTrees()
- ReturnHome()
- UnloadInventory()
- os.sleep(600)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement