Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local p = peripheral.wrap("back")
- function detect() -- on détecte si l'arbre a poussé ou pas
- local success, res = turtle.inspect()
- print(res.name)
- if res.name == "minecraft:log" then
- return true
- else
- return false
- end
- end
- function detectUp() -- on détecte la fin de l'arbre ou pas
- local success, res = turtle.inspectUp()
- if res.name == "minecraft:log" then
- return true
- else
- return false
- end
- end
- function leavesCleaning() -- on nettoie les feuilles autour de la turtle + récup de saplings
- local i = 1
- for i=1,4 do
- turtle.dig()
- turtle.turnRight()
- end
- end
- function searchSaplingTurtle() -- on cherche le slot de la turtle contenant les saplings
- local s = 1
- for s=1,16 do
- local res = turtle.getItemDetail(s)
- if res ~= nil then
- if res.name == "minecraft:sapling" then
- return s
- end
- end
- end
- return false
- end
- function getSaplingChest() -- On prend un sapling dans le coffre
- local fin = p.getInventorySize()
- while true do
- local s = 1
- for s=1,fin do
- local res = p.getStackInSlot(s)
- if res ~= nil then
- if res["id"] == "minecraft:sapling" then
- return p.pushItemIntoSlot("south",s,1)
- end
- end
- end
- term.clear()
- print("Pas de sapling dans le coffre, en attente...")
- sleep(1)
- end
- end
- function planteSapling() -- on plante un sapling
- local s = searchSaplingTurtle()
- print(s) -- on cherche le slot des saplings dans la turtle
- if s ~= false then
- turtle.select(s)
- turtle.place() -- si on en trouve, on le plante
- return true
- else -- sinon on en cherche dans le coffre
- getSaplingChest() -- si plus de sapling dans le coffre alors on attend avec un message à l'écran
- planteSapling() -- on plante dès qu'on a de nouveau des saplings
- return true
- end
- end
- function timber() -- on coupe l'arbre
- local r = 0
- print(r)
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.up()
- r = r + 1
- leavesCleaning()
- print(r)
- while detectUp() do
- turtle.digUp()
- turtle.up()
- r = r + 1
- leavesCleaning()
- print("fin boucle while "..r)
- end
- while r > 0 do
- turtle.down()
- r = r -1
- print("fin boucle while down "..r)
- end
- turtle.back()
- planteSapling()
- end
- function main() -- fonction principale
- while true do
- if detect() then
- timber()
- else
- sleep(5)
- end
- end
- end
- main()
- -- getInventorySize() renvoie un chiffre
- -- getStackInSlot(slotnum) renvoie un tableau, notamment la clé raw_name = "item.apple", id = "minecraft:apple"/"minecraft:log" ou display_name = "Apple"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement