Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lapis_minimum = 30000
- local lapis_recomended = 90000
- local lapis_precraft_size = 30000
- local component = require('component')
- local keyboard = require('keyboard')
- local gpu = component.gpu
- local modem = component.modem
- local event = require('event')
- local math = require('math')
- local nuc, me, xr, yr = nil
- local fingerprint = {name='minecraft:lapis_block',damage=0}
- local isWork = true
- local nucWork, producesEnergy, totalEUfromNucs = 0, 0, 0
- local preCraft = false
- local inProcess = false
- local isDone,isCanceled = true,false
- local request = nil
- modem.open(1)
- modem.setWakeMessage('Wake!')
- function getDevice(name)
- name=name or 'computer'
- local device={}
- local c=component.list()
- for k,v in pairs(c) do if string.find(v,name) then
- device[#device+1]=component.proxy(k) end
- end
- return device
- end
- local lapis = getDevice('me_')[1].getCraftables(fingerprint)[1]
- if lapis and lapis.request then
- request = lapis.request
- preCraft = true
- end
- function nuc_off()
- for num in pairs(nuc) do
- nuc[num].stopReactor()
- end
- return false
- end
- function nuc_on()
- for num in pairs(nuc) do
- nuc[num].startReactor()
- end
- return true
- end
- function is_nuc_work()
- local output = nil
- nucWork, producesEnergy, totalEUfromNucs = 0, 0, 0
- for num in pairs(nuc) do
- gpu.set(xr-26,4,'Проверка реактора '..num..' ')
- if nuc[num].isReactorWorking() then
- nucWork = nucWork+1
- output = nuc[num].getReactorEUOutput()
- if output > 0 then
- producesEnergy = producesEnergy + 1
- totalEUfromNucs = totalEUfromNucs + output
- end
- end
- end
- gpu.fill(xr-26,4,26,1,' ')
- end
- function lapis_available()
- local lapis, cooldown, second = me.getItemsInNetwork(fingerprint)[1].size
- if not lapis then
- local timer = second.sub(second,1,#second-1)+1
- while timer >= 0 do os.sleep(1)
- timer = timer - 1
- gpu.set(xr-26,5,cooldown .. second)
- end
- return lapis_available()
- end
- return lapis
- end
- function lapisPreCraft()
- return request(lapis_precraft_size)
- end
- function nuc_control()
- xr, yr = gpu.getResolution()
- nuc = getDevice('reactor_chamber')
- me = getDevice('me_')[1]
- is_nuc_work()
- local text = nucWork .. '/' .. #nuc
- gpu.set(xr-26,1,'Реакторов включено: ' .. text)
- text = nucWork - producesEnergy.. '/' .. nucWork
- gpu.set(xr-26,2,'Из них без топлива: ' .. text)
- text = tostring(math.floor(totalEUfromNucs))
- gpu.set(xr-26,3,'EU реакторов: ' .. text)
- local lapis = lapis_available()
- gpu.set(xr-26,5,'Блоков лазурита: ' .. lapis..' ')
- --Выключение при малом количестве лазурита
- if isWork and lapis < lapis_minimum then
- gpu.set(xr-26,4,'Мало лазурита. Выключение')
- isWork = nuc_off()
- gpu.set(xr-26,4,'Реакторы выключены ')
- end
- --Включение пр достаточном количестве лазурита
- if not isWork and lapis >= lapis_recomended then
- gpu.set(xr-26,4,'Включение... ')
- isWork = nuc_on()
- gpu.set(xr-26,4,'Реакторы включены ')
- end
- --Докрафт при малом количестве лазурита
- if preCraft and lapis <= lapis_recomended then
- if not inProcess then
- gpu.set(xr-26,4,'Докрафт лазуритовых блоков')
- inProcess = true
- local craft=lapisPreCraft()
- isDone = craft.isDone
- isCanceled = craft.isCanceled
- else
- --inProgress = not isDone()
- end
- if isDone() and inProcess then
- gpu.set(xr-26,4,'Докрафт лазурита завершён')
- inProcess = false
- else
- if inProcess and isCanceled() then
- gpu.set(xr-26,4,'Неудачная попытка докрафта')
- end
- end
- end
- return true
- end
- local nucMonitoringID=event.timer(59,nuc_control,math.huge)
- while true do --absolutely nothing
- event.pull(1.9)
- if keyboard.isKeyDown(keyboard.keys.delete) then
- event.cancel(nucMonitoringID)
- nucMonitoringID=nil
- break
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement