Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- component = require("component")
- utils = require("utils")
- event = require("event")
- term = require("term")
- reactor = component.br_reactor
- transposer = component.transposer
- modem = component.modem
- local isRunning = true
- ENERGY_STORES = { ultimate_energy_cube = { max = "getMaxEnergy", curr = "getEnergy" } }
- MAXENERGY_PERCENT = 70
- MINENERGY_PERCENT = 30
- INTERFACE = 4
- INLET = 5
- local maxCapacity = 0
- local comps = { }
- function main()
- event.listen("key_down", onKeyDown)
- term.clear()
- for comp, data in pairs(ENERGY_STORES) do
- for add, t in component.list() do
- if t == comp then
- maxCapacity = maxCapacity + component.invoke(add, data.max)
- comps[add] = data.curr
- end
- end
- end
- print("Start")
- print("Max Energy: " .. maxCapacity)
- while isRunning do
- work()
- event.pull(5)
- end
- end
- function log(type, data)
- print("[" .. type .. "] " .. data)
- modem.broadcast(1, "reactor", type, data)
- end
- function onKeyDown(event, sender, char, code, player)
- if code == 0x0E then
- isRunning = false
- end
- end
- function getCurrentPercent()
- local current = 0
- for add, func in pairs(comps) do
- current = current + component.invoke(add, func)
- end
- return current / maxCapacity * 100
- end
- function work()
- --check energy
- local currentEnergy = getCurrentPercent()
- log("info", "Current Energy Buffer: " .. currentEnergy .. "%")
- if reactor.getActive() then
- if currentEnergy > MAXENERGY_PERCENT then
- reactor.setActive(false)
- log("info", "Reactor Stopped")
- end
- else
- if currentEnergy < MINENERGY_PERCENT then
- reactor.setActive(true)
- log("info", "Reactor Started")
- end
- end
- --check fuel
- if transposer.getStackInSlot(INLET, 1) == nil then
- if utils.refillBest(transposer, INTERFACE, INLET, 1, 1) then
- log("info", "Reactor Refill")
- else
- log("warning", "No Fuel")
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement