Skip to content

Commit

Permalink
fix more networking stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tasgon committed Sep 16, 2024
1 parent f5f0fe0 commit fcce635
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/src/main/kotlin/observable/net/BetterChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package observable.net
import dev.architectury.networking.NetworkManager
import dev.architectury.networking.NetworkManager.Side
import dev.architectury.networking.transformers.SplitPacketTransformer
import dev.architectury.platform.Platform
import dev.architectury.utils.Env
import kotlinx.serialization.*
import kotlinx.serialization.protobuf.ProtoBuf
import net.minecraft.network.RegistryFriendlyByteBuf
Expand Down Expand Up @@ -47,8 +49,12 @@ class BetterChannel(val id: ResourceLocation) {
buf.writeByteArray(bos.toByteArray())
}
}
NetworkManager.registerReceiver(Side.S2C, CustomPacketPayload.Type(s2cLocation), codec, listOf(SplitPacketTransformer())) { value, ctx ->
handlers[value.className]?.invoke(value.data, ctx)
if (Platform.getEnvironment() == Env.SERVER) {
NetworkManager.registerS2CPayloadType(CustomPacketPayload.Type(s2cLocation), codec, listOf(SplitPacketTransformer()))
} else {
NetworkManager.registerReceiver(Side.S2C, CustomPacketPayload.Type(s2cLocation), codec, listOf(SplitPacketTransformer())) { value, ctx ->
handlers[value.className]?.invoke(value.data, ctx)
}
}
NetworkManager.registerReceiver(Side.C2S, CustomPacketPayload.Type(c2sLocation), codec) { value, ctx ->
handlers[value.className]?.invoke(value.data, ctx)
Expand Down

0 comments on commit fcce635

Please sign in to comment.