Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- saplings = 1 -- the slot where the saplings are
- charbon = 2
- bois=3
- coffre=4
- home=vector.new(-668,65,-1)
- function goTo(x,y,z)
- local position = vector.new(gps.locate(2))
- local home = vector.new(x,y,z)
- local deplacement = home:sub(position)
- local move = home:sub(vector.new(gps.locate(2)))
- while move.y > 0 do
- turtle.up()
- move = home:sub(vector.new(gps.locate(2)))
- end
- turtle.forward()
- move = home:sub(vector.new(gps.locate(2)))
- if math.abs(deplacement.x) - math.abs(move.x) == 0 then
- turtle.back()
- turtle.turnLeft()
- turtle.forward()
- move = home:sub(vector.new(gps.locate(2)))
- end
- if math.abs(deplacement.x) - math.abs(move.x) == -1 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- while math.abs(home:sub(vector.new(gps.locate(2))).x) > 0 do
- if not turtle.forward() then
- turtle.up()
- end
- end
- turtle.turnLeft()
- turtle.forward()
- move = home:sub(vector.new(gps.locate(2)))
- if math.abs(deplacement.z) - math.abs(move.z) == -1 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- while math.abs(home:sub(vector.new(gps.locate(2))).z) > 0 do
- turtle.forward()
- end
- move = home:sub(vector.new(gps.locate(2)))
- while move.y < 0 do
- turtle.down()
- move = home:sub(vector.new(gps.locate(2)))
- end
- end
- function recupSaplings()
- turtle.turnLeft()
- turtle.select(saplings)
- turtle.suck(64-turtle.getItemCount(saplings))
- turtle.turnRight()
- end
- function reEnergy()
- turtle.select(charbon)
- turtle.suckDown(64-turtle.getItemCount(charbon))
- if turtle.getFuelLevel() < 800 then
- turtle.refuel()
- end
- if turtle.getFuelLevel() < 100 then
- print('No much fuel !')
- os.shutdown()
- end
- turtle.select(saplings)
- end
- function pose()
- turtle.select(bois)
- turtle.drop(turtle.getItemCount(bois)-1)
- turtle.select(saplings)
- end
- function oriente()
- turtle.select(saplings)
- while not turtle.compare() do
- turtle.turnRight()
- end
- turtle.turnLeft()
- end
- function init()
- goTo(home.x,home.y,home.z)
- oriente()
- turtle.select(saplings) -- select the saplings
- while turtle.getItemCount(saplings) > 0 do -- while more saplings in inventory
- turtle.select(coffre)
- turtle.turnLeft()
- if turtle.compare() then
- reEnergy()
- pose()
- end
- turtle.turnRight()
- turtle.select(saplings)
- for i = 1, 5 do -- plant 5 saplings in a row
- turtle.turnRight()
- if not turtle.compare() then -- if not a sapling, then a tree grew
- turtle.dig()
- turtle.forward()
- turtle.select(bois)
- while turtle.compareUp() do -- dig tree out
- turtle.digUp()
- turtle.up()
- end
- turtle.select(saplings)
- while not turtle.detectDown() do -- back down to ground
- turtle.down()
- end
- turtle.back()
- turtle.place() -- put down new sapling
- end
- turtle.turnLeft()
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- for i = 1, 5 do -- plant 5 saplings in a row
- turtle.turnLeft()
- if not turtle.compare() then -- if not a sapling, then a tree grew
- turtle.dig()
- turtle.forward()
- turtle.select(bois)
- while turtle.compareUp() do -- dig tree out
- turtle.digUp()
- turtle.up()
- end
- turtle.select(saplings)
- while not turtle.detectDown() do -- back down to ground
- turtle.down()
- end
- turtle.back()
- turtle.place() -- put down new sapling
- end
- turtle.turnRight()
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- recupSaplings()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- os.sleep(180) -- sleep for 60 seconds to allow trees to grow
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement