Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wireSide = ...
- assert(wireSide, "Argument (wireSide) missing")
- local lightControlID = 155
- local myID = 154
- local modem = peripheral.find("modem")
- modem.open(myID)
- local function getMachineSetup(onByDefault, color, func)
- return {
- current = onByDefault and color or 0,
- color = color,
- func = func
- }
- end
- local machines = {
- lights = getMachineSetup(true, colors.brown, function(currentStatus) modem.transmit(lightControlID, myID, currentStatus) end),
- spawner = getMachineSetup(true, colors.red),
- grinders = getMachineSetup(false, colors.green)
- }
- local function getMachineStatus(machine)
- if (machines[machine]) then
- return machines[machine].current
- end
- end
- local function update()
- local color = 0
- for name, machine in pairs(machines) do
- color = colors.combine(color, machine.current)
- if machine.func then
- machine.func(machine.current ~= 0)
- end
- end
- rs.setBundledOutput(wireSide, color)
- end
- local function getStatus(id)
- modem.transmit(id, myID, machines)
- end
- local function onMessage(message)
- local query = message[5]
- if query.machine then
- machines[query.machine].current = query.status and machines[query.machine].color or 0
- end
- update()
- getStatus(message[3])
- end
- update()
- while true do
- onMessage({os.pullEvent("modem_message")})
- end
Advertisement
Add Comment
Please, Sign In to add comment