Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function move_dir( direction )
- local dir_char = direction:sub(1,1)
- if dir_char == "f" or dir_char == "" then
- return turtle.forward()
- elseif dir_char == "b" then
- return turtle.back()
- elseif dir_char == "u" then
- return turtle.up()
- elseif dir_char == "d" then
- return turtle.down()
- else
- print( "Invalid direction: "..direction )
- return false
- end
- end
- function move( direction )
- if not move_dir( direction ) then
- if turtle.getFuelLevel() == 0 then
- print( "Out of Fuel." )
- turtle.select( fuel_slot )
- if not turtle.refuel( 1 ) then
- print( "Cannot refuel." )
- print( "Waiting for fuel to continue." )
- while not turtle.refuel( 1 ) do
- sleep( 1 )
- end
- end
- print( "Refueled." )
- return move( direction )
- else
- print( "Path obstructed." )
- print( "Waiting to move." )
- while not move_dir( direction ) do
- sleep( 1 )
- end
- end
- end
- return true
- end
- fuel_slot = 1
- log_slot = 2
- sapling_slot = 3
- break_slot = 4
- turtle.select( sapling_slot )
- turtle.suck()
- turtle.select( 5 )
- turtle.drop()
- turtle.turnLeft()
- turtle.select( 1 )
- do_grid_loop = true
- while do_grid_loop do
- do_row_loop = true
- while do_row_loop do
- if turtle.detect() then
- print( "Object found." )
- turtle.dig()
- move( "f" )
- turtle.select( log_slot )
- if turtle.compareUp() then
- print( "Tree found." )
- print( "Cutting down." )
- while turtle.compareUp() do
- turtle.digUp()
- move( "u" )
- turtle.select( log_slot )
- end
- while not turtle.detectDown() do
- move( "d" )
- end
- end
- else
- print( "Nothing found." )
- print( "Skipping." )
- move( "f" )
- end
- move( "f" )
- print( "Replanting sapling." )
- turtle.turnRight()
- turtle.turnRight()
- turtle.select( sapling_slot )
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- print( "Advancing to either break loop or block." )
- turtle.select( break_slot )
- while ( not turtle.compareDown() ) and ( not turtle.detect() ) do
- move( "f" )
- turtle.select( break_slot )
- end
- if turtle.compareDown() then
- do_row_loop = false
- end
- end
- print( "Break loop found." )
- print( "Returning to start next row." )
- turtle.turnLeft()
- move( "f" )
- while not turtle.compareDown() do
- move( "f" )
- turtle.select( break_slot )
- end
- turtle.turnLeft()
- move( "f" )
- turtle.select( break_slot )
- while not turtle.compareDown() do
- move( "f" )
- turtle.select( break_slot )
- end
- turtle.turnRight()
- if turtle.detect() then
- do_grid_loop = false
- else
- move( "f" )
- turtle.select( break_slot )
- while ( not turtle.compareDown() ) or turtle.detect() do
- move( "f" )
- turtle.select( break_slot )
- end
- print( "Checking for next row." )
- if turtle.detect() then
- do_grid_loop = false
- end
- end
- turtle.turnRight()
- end
- print( "End of grid." )
- print( "Returning to start/chest." )
- turtle.turnRight()
- while not turtle.detect() do
- move( "f" )
- end
- turtle.turnRight()
- print( "Unloading chest." )
- for slot = 1, 16, 1 do
- if slot ~= fuel_slot and slot ~= log_slot and slot ~= sapling_slot and slot ~= break_slot then
- turtle.select( slot )
- turtle.drop()
- elseif slot == log_slot then
- turtle.select( slot )
- turtle.drop( turtle.getItemCount( slot ) - 1 )
- end
- end
- turtle.turnLeft()
- print( "Complete!" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement