38 lines
1.1 KiB
Kotlin
38 lines
1.1 KiB
Kotlin
package net.shadowfacts.phycon.network.block.test
|
|
|
|
import net.minecraft.util.math.Direction
|
|
import net.shadowfacts.phycon.api.Interface
|
|
import net.shadowfacts.phycon.api.frame.EthernetFrame
|
|
import net.shadowfacts.phycon.api.packet.Packet
|
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
|
import net.shadowfacts.phycon.network.BaseInterface
|
|
import net.shadowfacts.phycon.network.DeviceBlockEntity
|
|
import net.shadowfacts.phycon.network.NetworkUtil
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class DestBlockEntity: DeviceBlockEntity(PhyBlockEntities.DEST) {
|
|
|
|
override val interfaces = listOf(BaseInterface(this))
|
|
|
|
override fun handle(packet: Packet, itf: Interface) {
|
|
println("$this ($ipAddress) received packet: $packet")
|
|
}
|
|
|
|
override fun handle(frame: EthernetFrame, fromItf: Interface) {
|
|
// println("dest ${fromItf.macAddress} received frame from ${frame.source}")
|
|
super.handle(frame, fromItf)
|
|
}
|
|
|
|
override fun findDestination(fromItf: Interface): Interface? {
|
|
for (dir in Direction.values()) {
|
|
val itf = NetworkUtil.findConnectedInterface(world!!, pos, dir)
|
|
if (itf != null) {
|
|
return itf
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
} |