Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('BC_Mgr/Util/loadTable')
- function setDevices(class)
- local devices = peripheral.getNames()
- deviceList = {}
- for device, value in pairs(devices) do
- if string.find(value, class) then
- deviceList[#deviceList+1] = value
- end
- end
- file = 'BC_Mgr/classes/'..class
- tables.write(file, deviceList)
- return true
- end
- function getDevices(class)
- local file = 'BC_Mgr/classes/'..class
- return tables.load(file)
- end
- function rs_signal(capacity, total)
- if total/capacity < 0.9f then
- redstone.setAnalogOutput('bottom', 15 )
- return 'on'
- else
- redstone.setAnalogOutput('bottom', 0)
- return 'off'
- end
- end
- function fuel_engines()
- local chests = getDevices('chest')
- local engines = getDevices('engine')
- for k, engine in pairs(engines) do
- -- print('working on engine:', engine)
- local p = peripheral.wrap(engine)
- local eng_type = peripheral.getType(engine)
- local fuels = tables.load('BC_Mgr/dat/fuels')
- local eng_fuels = fuels[eng_type]
- if eng_type=='items' then
- local item = p.getItem(1)
- local count = item.count
- if count < 1 then
- print(count)
- end
- end
- end
- end
- classList = tables.load('BC_Mgr/dat/classList')
- --print(classList)
- loop=true
- main = peripheral.wrap('top')
- term.redirect(main)
- term.clear()
- term.setCursorPos(1,1)
- while loop do
- -- q = os.pullEvent('char')
- -- print(q)
- -- if q == 'q' or q=='Q' then
- -- loop=false
- -- end
- main = peripheral.wrap('top')
- --term.redirect(main)
- --term.clear()
- --term.setCursorPos(1,1)
- --print('set classes:')
- for class in ipairs(classList) do
- setDevices(class)
- end
- -- print('get classes: in forestry')
- energy = {
- ['Stored'] = 0,
- ['Capacity'] = 0,
- ['Devices'] = {}
- }
- for k, device in ipairs(getDevices('forestry')) do
- p = peripheral.wrap(device)
- e = p.getEnergyStored()
- c = p.getEnergyCapacity()
- -- print(device, c, e, c-e )
- energy['Stored'] = energy['Stored'] + e
- energy['Capacity'] = energy['Capacity'] + c
- energy['Devices'][device] = {
- ['Stored'] = e,
- ['Capacity'] = c
- }
- end
- signal = rs_signal(energy['Capacity'], energy['Stored'])
- term.clear()
- term.setCursorPos(1,1)
- print('Totals:')
- print('Capacity:', energy['Capacity'])
- print('Stored:', energy['Stored'])
- print('Deficit:',
- energy['Capacity']-energy['Stored'],
- '(',math.floor(energy['Stored']/energy['Capacity']*100),'%)')
- print('Engines:', signal)
- for k,v in pairs(energy.Devices) do
- print(k)
- for key, value in pairs(v) do
- print('\t',key, value)
- end
- end
- --fuel_engines()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement