Code cleanup
This commit is contained in:
parent
633f9d94aa
commit
583afd3dc9
|
@ -14,6 +14,8 @@ import net.shadowfacts.phycon.block.BlockWithEntity
|
|||
*/
|
||||
abstract class DeviceBlock<T: DeviceBlockEntity>(settings: Settings): BlockWithEntity<T>(settings), NetworkComponentBlock {
|
||||
|
||||
abstract override fun getNetworkConnectedSides(state: BlockState, world: World, pos: BlockPos): Collection<Direction>
|
||||
|
||||
override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: World, pos: BlockPos): Interface? {
|
||||
return getBlockEntity(world, pos)!!
|
||||
}
|
||||
|
|
|
@ -36,9 +36,8 @@ class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
|||
return interfaces.find { it.side == side }!!
|
||||
}
|
||||
|
||||
private fun handle(frame: EthernetFrame, fromItf: Interface) {
|
||||
val itfSide = (fromItf as SwitchInterface).side
|
||||
macTable[frame.source] = itfSide
|
||||
private fun handle(frame: EthernetFrame, fromItf: SwitchInterface) {
|
||||
macTable[frame.source] = fromItf.side
|
||||
|
||||
if (frame is PacketFrame && frame.packet is ItemStackPacket) {
|
||||
val packet = frame.packet as ItemStackPacket
|
||||
|
@ -54,10 +53,10 @@ class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
|||
|
||||
if (frame.destination.type != MACAddress.Type.BROADCAST && macTable.containsKey(frame.destination)) {
|
||||
val dir = macTable[frame.destination]!!
|
||||
println("$this ($itfSide, ${fromItf.macAddress}) forwarding $frame to side $dir")
|
||||
println("$this (${fromItf.side}, ${fromItf.macAddress}) forwarding $frame to side $dir")
|
||||
interfaceForSide(dir).send(frame)
|
||||
} else {
|
||||
println("$this ($itfSide, ${fromItf.macAddress}) flooding $frame")
|
||||
println("$this (${fromItf.side}, ${fromItf.macAddress}) flooding $frame")
|
||||
flood(frame, fromItf)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue