Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Bonemeal farm
- REDSTONE_SIDE = "back" -- Сторона, к которой подключен модем
- DATA_FILE = "malafia.dat" -- Файл для сохранения данных
- TEMP_FILE = "malafia.temp" -- Временное хранилище
- REFRESH_RATE = 2 -- Seconds
- BACKGROUND_COLOR = 1 -- White
- TEXT_COLOR = 32768 -- Black
- scrX, scrY = term.getSize()
- IsFarming = false
- --------------------------------------------------
- -- Интерфейс
- --------------------------------------------------
- function DrawBackground ()
- term.setBackgroundColor(BACKGROUND_COLOR)
- term.setTextColor(TEXT_COLOR)
- term.setCursorBlink(false)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("\t\t< Malafia Industries >")
- end
- function WriteStats ()
- term.setCursorPos(1, 3)
- if IsFarming then term.write("Farming:\t\t\t\tTrue")
- else term.write("Farming:\t\t\t\tFalse") end
- end
- function WriteButtonsExplanation ()
- term.setCursorPos(1, scrY-3)
- term.write("F - farm, S - stop, X - shutdown")
- end
- --------------------------------------------------
- -- Сохранение и загрузка
- --------------------------------------------------
- function SaveToFile()
- local file = fs.open(TEMP_FILE, "w")
- file.writeLine(IsFarming .. "")
- file.close()
- fs.delete(DATA_FILE)
- fs.move(TEMP_FILE, DATA_FILE)
- return 0
- end
- function LoadFromFile()
- local file = fs.open(DATA_FILE, "r")
- IsFarming = tonumber(file.readLine())
- file.close()
- return 0
- end
- --------------------------------------------------
- -- Главный луп
- --------------------------------------------------
- function main ()
- if fs.exists(DATA_FILE) then
- LoadFromFile()
- end
- while true do
- DrawBackground()
- WriteStats()
- WriteButtonsExplanation()
- local timeout = os.startTimer(REFRESH_RATE)
- while true do
- event = {os.pullEvent()}
- if event[1] == "key" then
- if event[2] == 33 then -- F - farm
- IsFarming = true
- redstone.setOutput(REDSTONE_SIDE, true)
- break
- elseif event[2] == 31 then -- S - stop
- IsFarming = false
- redstone.setOutput(REDSTONE_SIDE, false)
- break
- elseif event[2] == 45 then -- X - shutdown
- Shutdown()
- end
- elseif event[1] == "timer" and event[2] == timeout then
- break
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement