Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- constante
- local minute = 1/60
- local heure = 1
- local jour = 24
- local step = 0.9
- -- config
- conf = {}
- conf.attente = 7 * jour
- conf.x = 9
- conf.y = 9
- -- setup des slot
- local charbon = 1
- local graine = 2
- local function setupOk()
- local s1 = turtle.getItemCount(charbon)
- local s2 = turtle.getItemCount(graine)
- if (s1 > 1) then
- return true
- else
- if (s1 <= 1) then print("Il n'y a pas asses de charbon.") end
- if (s2 <= 1) then print("Il n'y a pas asses de graines.") end
- return false
- end
- end
- local function setup()
- print("s1 : charbon")
- print("s2 : graine")
- print("Appuyer sur une touche pour continuer.")
- local event, code = os.pullEvent("key")
- end
- while not setupOk() do
- setup()
- end
- local function trySelect(slot)
- local slots = {}
- local nbItem = 0
- turtle.select(slot)
- for s = 16, 1, -1 do
- if (s ~= slot) then
- if (turtle.compareTo(s)) then
- slots[#slots+1] = s
- nbItem = nbItem + turtle.getItemCount(s)
- end
- end
- end
- slots[#slots+1] = slot
- nbItem = nbItem + turtle.getItemCount(slot)
- if nbItem > 1 then
- turtle.select(slots[1])
- return true
- else
- return false
- end
- end
- local function farm()
- local function cueillir()
- local function plante()
- local function selectGraine()
- return trySelect(graine)
- end
- if selectGraine() then
- turtle.placeDown()
- end
- end
- turtle.digDown()
- plante()
- end
- turtle.forward()
- for pass = 1,conf.x do
- for n = 1,conf.y do
- cueillir()
- if (n==conf.y) then
- if (pass % 2 == 1) then
- turtle.turnRight()
- if (pass<conf.x) then
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnRight()
- for _ = 2,conf.y do turtle.forward() end
- turtle.turnRight()
- end
- else
- if (pass <conf.x) then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- else
- turtle.forward()
- end
- end
- end
- for n = 1, conf.x do
- if n < conf.x then
- turtle.forward()
- else
- turtle.turnRight()
- end
- end
- turtle.back()
- end
- local function libre()
- -- test inventaire plein
- local resteFuel = turtle.getFuelLevel()
- if (resteFuel == 'unlimited' or resteFuel < 80) then
- if (trySelect(charbon)) then
- return turtle.refuel(1)
- else
- return false
- end
- else
- return true
- end
- end
- local function dateTime()
- local d, t = os.day(), os.time()
- return (d*24)+t
- end
- function readAlert()
- local alert = nil
- if fs.exists("memory") then
- local memFile = io.open('memory','r')
- alert = tonumber(memFile:read("*a"))
- memFile:close()
- end
- return alert
- end
- function saveAlert(alert)
- local memFile = io.open('memory','w')
- memFile:write(alert)
- memFile:close()
- end
- local now = dateTime()
- local alert = readAlert() or (now + conf.attente)
- saveAlert(alert)
- while true do
- term.clear()
- term.setCursorPos(1,1)
- if (libre() and now > alert) then
- print("Jardinage en cours!")
- farm()
- alert = now + conf.attente
- saveAlert(alert)
- else
- local j,h = math.floor((alert-now)/jour), textutils.formatTime(((alert-now)%jour), true)
- print("En attente ...")
- print("reprise dans : " ..j.. " jour(s) et " ..h)
- end
- os.sleep(step)
- now = dateTime()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement