Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local verbose = args[1] and args[1] or false
- local typestr_modem = "modem"
- local typestr_reactor = "BigReactors-Reactor"
- local typestr_turbine = "BigReactors-Turbine"
- _sides = {"front","back","right","left","top","bottom"}
- function err(...)
- printError(...)
- do return end
- end
- function combineTables(a,b)
- local old_num_a = #a
- for n,v in pairs(b) do
- a[#a+1] = v
- end
- assert(#a == old_num_a + #b)
- return a
- end
- function findLocalPeripherals(type, discriminator)
- local r = {}
- for n,side in ipairs(_sides) do
- if (peripheral.isPresent(side) and peripheral.getType(side) == type) then
- if (not discriminator) then
- r[#r+1] = peripheral.wrap(side)
- elseif (discriminator(side)) then
- r[#r+1] = peripheral.wrap(side)
- end
- end
- end
- return r
- end
- function findRemotePeripherals(modem, type, discriminator)
- local r = {}
- for n,name in ipairs(modem.getNamesRemote()) do
- if (modem.getTypeRemote(name) == type) then
- local o = peripheral.wrap(name)
- if (not discriminator) then
- r[#r+1] = o
- elseif (discriminator(o)) then
- r[#r+1] = o
- end
- end
- end
- return r
- end
- function findPeripherals(type, modems, discriminator)
- local r = {}
- r = findLocalPeripherals(type, discriminator)
- for n,modem in ipairs(modems) do
- r = combineTables(r, (findRemotePeripherals(modem, type, discriminator)))
- end
- return r
- end
- local function isConnected(o)
- local r = o.getConnected() == true
- if (verbose and r == false) then
- printError(name, " is not connected! Either the multiblock structure isn't complete, or the modem is glitched.")
- end
- return r
- end
- _modems = findLocalPeripherals(typestr_modem, function(side) return (peripheral.call(side, "isWireless") == false) end)
- _reactors = findPeripherals(typestr_reactor, _modems, isConnected)
- _turbines = findPeripherals(typestr_turbine, _modems, isConnected)
- if (verbose) then
- print(#_modems, " modems, ", #_reactors, " reactors, and ", #_turbines, " turbines found.")
- end
- if (#_reactors < 1) then
- if (#_modems < 1) then
- printError("No modems or reactors found!")
- else
- printError("No reactors found!")
- end
- do return end
- end
- _init_has_run = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement