Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tRedstoneState = {} -- Holds the state of all redstone sides on the computer.
- local tCableState = {} -- Holds the state of all bundled cables on the computer.
- -- Get initial redstone state for all 6 sides.
- for _, side in pairs( rs.getSides() ) do
- tRedstoneState[ side ] = rs.getInput( side )
- end
- -- Get initial bundled cable state for all 6 sides.
- for _, v in pairs( rs.getSides() ) do
- tCableState[ v ] = rs.getBundledInput( v )
- end
- -- If a redstone side changes its state, then this function returns the event 'redstone' plus the string 'vanilla' and a table.
- -- The returned table contains only sides that have changed and it has this format: { side = new_value }
- -- If a bundled cable changes its state, then this function returns the event 'redstone' plus the string 'bundled_cable' and a table.
- -- The returned table contains only sides that have changed and it has this format: { side = { new_value, old_value } }
- function pullEvent( _sEvent, _tSide )
- local bRedstoneChanged = false
- local bCableChanged = false
- local tChangedCable = {}
- local tChangedRedstone = {}
- local event, p1, p2, p3, p4, p5 = os.pullEvent( _sEventFilter )
- local function checkRedstoneSides( _tSide )
- -- Iterate over all _tSide sides of the computer.
- -- If _tSide is not given, iterate over all 6 sides.
- for _, side in pairs( _tSide or rs.getSides() ) do
- local bCurrentInput = rs.getInput( side ) -- Get redstone input for current side.
- if bCurrentInput ~= tRedstoneState[ side ] then -- Has the state changed?
- tChangedRedstone[ side ] = bCurrentInput -- Add the changed side + its new value to the return table.
- tRedstoneState[ side ] = bCurrentInput -- Update the local state table.
- bRedstoneChanged = true
- end
- end
- return bRedstoneChanged, tChangedRedstone
- end
- local function checkBundledCableSides( _tSide )
- -- Iterate over all _tSide sides of the computer.
- -- If _tSide is not given, iterate over all 6 sides.
- for _, side in pairs( _tSide or rs.getSides() ) do
- local nCableInput = rs.getBundledInput( side ) -- Get cable input for current side.
- if nCableInput ~= tCableState[ side ] then -- Has the state changed?
- tChangedCable[ side ] = { nCableInput, tCableState[ side ] } -- Add the changed side + its new and old values to the return table.
- tCableState[ side ] = nCableInput -- Update the local state table.
- bCableChanged = true
- end
- end
- return bCableChanged, tChangedCable
- end
- if event == "redstone" then
- local bChanged, tSides = checkRedstoneSides( _tSide )
- if bChanged then return event, "vanilla", tSides, p2, p3, p4, p5 end
- local bChanged, tSides = checkBundledCableSides( _tSide )
- if bChanged then return event, "bundled_cable", tSides, p2, p3, p4, p5 end
- end
- return event, p1, p2, p3, p4, p5
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement