Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Ce programme [cree pas TriiNoxYs] est libre de droits ;)
- -- Si vous le modifier/publiez/presentez/etc, SVP pensez a citer son auteur.
- -- Consultez tout les autres scripts de TriiNoxys sur le lien pastein.com/benjfn71
- -- Ou sur la page de TriiNoxYs: pastebin.com/u/TriiNoxYs
- local InfiniteWork = true --set an infinite loop or not
- local CoolDownDuration = 10--idle time to let the trees grow : not necessary for big forrests.
- local MinimumRide = 800 --necessary fuel to start : the max fuel consumation is if the forrest is full of grown trees.
- local MinimumRoots = 8 --The turtle does not start if there is less saplings.
- local FurnaceFuelDose = 8 --amount of charcoal to save for the furnace : 8 means a stack of wood can burn
- local MinFuelStock = 10 --turtle always keeps this minimal amount of charcoal. The furnace will use wood if there is too few charcoals.
- local FuelSlot = 16
- local RootSlot = 15
- local EdgeSlot = 14
- local WoodSlot = 1
- local Roof = 5 --max ups that the turtle has to do (inc ase there is a roof)
- local dir = {L=0,R=1,U=2,D=3,F=4}
- local AvoidRoot = { dir.R,dir.F,dir.L,dir.F,dir.F, dir.L, dir.F,dir.R }
- local RightTurn = { dir.R,dir.F,dir.F,dir.F,dir.F, dir.R}
- local LeftTurn = { dir.L,dir.F,dir.F,dir.F,dir.F, dir.L}
- local bAltDirection
- function move(directions)
- turtle.select(RootSlot)
- for i=0, table.maxn(directions) do
- direction = directions[i]
- if direction==dir.L then
- turtle.turnLeft()
- elseif direction==dir.R then
- turtle.turnRight()
- elseif direction==dir.U then
- if turtle.up()==false then
- return false
- end
- elseif direction==dir.D then
- if turtle.down()==false then
- return false
- end
- elseif direction==dir.F then
- if turtle.forward()==false then
- return false
- end
- end
- turtle.suck()
- end
- return true;
- end
- function goBack()
- turtle.turnRight()
- while turtle.detect()==false do
- turtle.suck()
- turtle.forward()
- end
- if turtle.detectDown() then
- goBack()
- end
- end
- function turn180()
- turtle.turnRight()
- turtle.turnRight()
- end
- function meetEdge()
- local success
- if bAltDirection>0 then
- success= move(LeftTurn)
- else
- success= move(RightTurn)
- end
- if success then
- bAltDirection = (bAltDirection+1)%2
- doRow(0)
- else
- goBack()
- end
- end
- function dig360()
- turtle.select(EdgeSlot)
- if turtle.compare()==false then --avoid breaking the edge slot..
- turtle.dig() turtle.suck()
- end
- turtle.turnLeft()
- turtle.dig()turtle.suck()
- turn180()--nothing to suck behind
- turtle.dig()turtle.suck()
- turtle.turnLeft()
- end
- function digTree()
- turtle.dig()
- turtle.suck()
- turtle.select(RootSlot)
- turtle.digUp()
- turtle.suckUp()
- if turtle.getItemCount(RootSlot)>1 then
- turtle.place()
- end
- turtle.up()
- ups = 1
- while turtle.detect() and ups<Roof do
- dig360()
- turtle.digUp()turtle.suckUp()
- turtle.up()
- ups=ups+1
- end
- turtle.dig()
- turtle.forward()
- dig360()
- turtle.forward()
- if ups==0 then return end
- while ups>0 do
- dig360()
- turtle.digDown()
- turtle.suckDown()
- turtle.down()
- ups=ups-1
- end
- -- turtle.dig()
- -- turtle.forward()
- -- ups = 0
- -- turtle.select(WoodSlot)
- -- while turtle.compareUp() do
- -- turtle.digUp()
- -- turtle.up()
- -- ups=ups+1
- -- end
- -- if ups==0 then
- -- return
- -- end
- -- while ups>1 do --back to level 1 to plant the new root !
- -- turtle.down()
- -- ups=ups-1
- -- end
- -- if turtle.getItemCount(RootSlot)>0 then
- -- turtle.select(RootSlot)
- -- turtle.placeDown()
- -- turtle.dig()--make one step in front to save the root
- -- turtle.forward()
- -- turtle.down()
- -- else
- -- turtle.down()
- -- end
- end
- function doRow(offset)
- turtle.select(RootSlot)
- stepcounter=offset
- while turtle.detect()==false do
- turtle.suck()
- if stepcounter%4==1 and turtle.detectDown() and turtle.getItemCount(RootSlot)>1 then
- --detection means the turtle can plant
- turtle.forward()
- turn180()
- turtle.select(RootSlot)
- turtle.place()
- turn180()
- else
- turtle.forward()
- end
- stepcounter=stepcounter+1
- end
- --detect edge
- turtle.select(EdgeSlot)
- if turtle.compare() then
- meetEdge()
- else
- turtle.select(WoodSlot)
- if turtle.compare() then
- digTree()
- else
- if move(AvoidRoot)==false then
- error("Unexpected block during AvoidRoot operation")
- end
- end
- doRow(2)
- return
- end
- end
- function unloadInventory()
- turtle.select(WoodSlot)
- if (turtle.getItemCount(WoodSlot)>1) then
- turtle.dropUp(turtle.getItemCount(WoodSlot)-1)--keep one block of wood
- end
- index = WoodSlot+1
- while index<EdgeSlot and turtle.getItemCount(index) > 0 do
- turtle.select(index)
- turtle.drop()
- index=index+1
- end
- end
- function furnaceAndChestOp()
- --front of the furnace.
- --Drop furnace fuel : charcoal first, but keep minimal amount
- dropped = false
- if turtle.getItemCount(FuelSlot) >= (FurnaceFuelDose+MinFuelStock) then
- turtle.select(FuelSlot)
- if turtle.drop(FurnaceFuelDose) then
- dropped=true
- print("turtle has dropped "..FurnaceFuelDose.." charcoals !")
- end
- end
- if dropped==false and turtle.getItemCount(WoodSlot)>1 then
- --drop wood instead
- turtle.select(WoodSlot)
- woodtodrop = math.min(FurnaceFuelDose, turtle.getItemCount(WoodSlot)-1)
- turtle.drop(woodtodrop)
- print("turtle has dropped "..woodtodrop.." Wood")
- end
- --Drop wood
- turtle.digUp()--yes, there can be a leaf block
- turtle.up()
- turtle.forward()
- turn180()
- turtle.select(WoodSlot)
- if turtle.getItemCount(WoodSlot)>1 then
- turtle.dropDown(turtle.getItemCount(WoodSlot)-1)
- end
- index=WoodSlot+1
- turtle.select(index)
- while index < EdgeSlot and turtle.compareTo(WoodSlot) and turtle.getItemCount(index)>0 do
- if turtle.dropDown()==false then --fails if the furnace is full
- index=EdgeSlot --Leave Loop
- end
- index=index+1
- turtle.select(index)
- end
- step=10
- delay = CoolDownDuration/10
- while step<=100 do
- sleep(delay)
- print(step.."%")
- step=step+10
- end
- --suck results
- turtle.forward()
- turtle.down()
- turtle.down()
- turtle.back()
- turtle.select(FuelSlot)
- turtle.suckUp()
- --go to chest
- turtle.forward()
- turtle.turnLeft()
- turtle.up()
- unloadInventory()
- --back to position
- turtle.turnRight()
- end
- function mainloop()
- --checking fuel
- turtle.select(FuelSlot)
- while turtle.getFuelLevel()< MinimumRide do
- if turtle.refuel(1)==false then
- error("The turtle needs more fuel on slot 16")
- end
- end
- --checking saplings
- if turtle.getItemCount(RootSlot)< MinimumRoots then
- error("The turtle needs more roots on slot 15")
- end
- print("starting run with fuel level "..turtle.getFuelLevel().." and "..turtle.getItemCount(RootSlot).." saplings")
- bAltDirection=0
- doRow(0)
- print("finishing run with fuel level "..turtle.getFuelLevel().." and "..turtle.getItemCount(RootSlot).." saplings")
- turtle.turnLeft()--face furnace
- furnaceAndChestOp()
- end
- mainloop()
- print("Wood collect over")
- while InfiniteWork==true do
- parallel.waitForAny(
- mainloop(),
- function()
- ans = read()
- error("bye")
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement