Code cleanup

This commit is contained in:
Shadowfacts 2021-02-14 16:03:40 -05:00
parent 633f9d94aa
commit 583afd3dc9
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 6 additions and 5 deletions

View File

@ -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)!!
}

View File

@ -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)
}
}