Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ready = false
- digLeaf = false
- function saveRoutinePosition(action)
- dataFile = fs.open("Data", "w")
- dataFile.write(action)
- dataFile.close()
- end
- function readRoutine()
- dataFile = fs.open("Data", "r")
- action = dataFile.readAll()
- dataFile.close()
- return action
- end
- function refuel()
- if(turtle.getFuelLevel() < turtle.getFuelLimit()/2) then
- turtle.select(1)
- turtle.refuel(turtle.getItemCount() - 1)
- end
- end
- function dropContainer(slot, amount, where)
- turtle.select(slot)
- while turtle.getItemCount(slot) - amount < 1 do
- if amount ~= 0 then
- amount = amount - 1
- end
- end
- if amount ~= 0 then
- if where == "up" then
- return turtle.dropUp(amount)
- elseif where == "down" then
- return turtle.dropDown(amount)
- else
- return turtle.drop(amount)
- end
- else
- return false
- end
- end
- function chestArea()
- for i = 5, 16 do
- dropContainer(i, turtle.getItemCount(i), "down")
- end
- turtle.select(3)
- while not turtle.compare() do
- turtle.turnRight()
- end
- turtle.select(1)
- if turtle.getItemCount(1) <= 20 then
- turtle.suck(40)
- end
- turtle.select(4)
- if turtle.getItemCount(4) <= 20 then
- turtle.suck(40)
- end
- turtle.turnRight()
- if not turtle.detect() then
- while turtle.getItemCount() == 1 do
- print("Plus de sapling !")
- sleep(10)
- print("Go remettre des saplings !")
- end
- turtle.place()
- end
- turtle.turnRight()
- turtle.turnRight()
- if not turtle.detect() then
- while turtle.getItemCount() == 1 do
- print("Plus de sapling !")
- sleep(10)
- print("Go remettre des saplings !")
- end
- turtle.place()
- end
- turtle.select(2)
- while not turtle.compare() do
- sleep(5)
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- function checkWood()
- nTurn = 0
- while not turtle.compare() do
- if nTurn == 4 then
- if not turtle.detectUp() and digLeaf then
- saveRoutinePosition("reset")
- turtle.select(3)
- while not turtle.compareDown() do
- if turtle.detectDown() and not turtle.compareDown() then
- turtle.digDown()
- end
- turtle.down()
- end
- saveRoutinePosition("chestArea")
- chestArea()
- break
- else
- turtle.up()
- break
- end
- end
- turtle.turnRight()
- nTurn = nTurn + 1
- end
- end
- refuel()
- if fs.exists("Data") then
- if readRoutine() == "checkWoodLeafDig" then
- ready = true
- digLeaf = true
- end
- if readRoutine() == "" then
- saveRoutinePosition("chestArea")
- end
- else
- saveRoutinePosition("chestArea")
- end
- while true do
- while ready do
- --Dig wood
- turtle.select(2)
- if not turtle.compare() then
- checkWood()
- if not digLeaf then
- saveRoutinePosition("checkWoodLeafNoDig")
- else
- saveRoutinePosition("checkWoodLeafDig")
- end
- else
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- if turtle.compare() then
- turtle.dig()
- end
- if turtle.digUp() then
- saveRoutinePosition("digUp")
- digLeaf = true
- end
- turtle.up()
- if not digLeaf then
- saveRoutinePosition("checkWoodLeafNoDig")
- else
- saveRoutinePosition("checkWoodLeafDig")
- end
- end
- end
- if not ready and readRoutine() == "reset" then
- turtle.select(3)
- while not turtle.compareDown() do
- if turtle.detectDown() and not turtle.compareDown() then
- turtle.digDown()
- end
- turtle.down()
- end
- saveRoutinePosition("chestArea")
- chestArea()
- ready = true
- end
- if not ready and readRoutine() == "chestArea" then
- chestArea()
- ready = true
- end
- if not ready and readRoutine() == "digUp" then
- turtle.up()
- ready = true
- end
- if not ready and readRoutine() == "checkWoodLeafNoDig" then
- turtle.up()
- ready = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement