diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerFabric.java index b7cbc6ef7d..734b0acd8b 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerFabric.java @@ -1,5 +1,7 @@ package org.cyclops.cyclopscore.network; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; @@ -27,13 +29,7 @@ public PacketHandlerFabric(ModBaseFabric> mod) { public
void register(Class
clazz, CustomPacketPayload.Type
type, StreamCodec super RegistryFriendlyByteBuf, P> codec) { PayloadTypeRegistry.playS2C().register(type, codec); if (this.mod.getModHelpers().getMinecraftHelpers().isClientSide()) { - ClientPlayNetworking.registerGlobalReceiver(type, (packet, ctx) -> { - if (packet.isAsync()) { - handlePacketClient(ctx, packet); - } else { - ctx.client().execute(() -> handlePacketClient(ctx, packet)); - } - }); + registerClientSide(clazz, type, codec); } PayloadTypeRegistry.playC2S().register(type, codec); @@ -46,14 +42,26 @@ public
void register(Class
clazz, CustomPacketPayload. }); } - public void handlePacketClient(ClientPlayNetworking.Context context, PacketBase> packet) { - packet.actionClient(context.player().level(), context.player()); - } - public void handlePacketServer(ServerPlayNetworking.Context context, PacketBase> packet) { packet.actionServer(context.player().level(), context.player()); } + @Environment(EnvType.CLIENT) + protected
void registerClientSide(Class
clazz, CustomPacketPayload.Type
type, StreamCodec super RegistryFriendlyByteBuf, P> codec) { + ClientPlayNetworking.registerGlobalReceiver(type, (packet, ctx) -> { + if (packet.isAsync()) { + handlePacketClient(ctx, packet); + } else { + ctx.client().execute(() -> handlePacketClient(ctx, packet)); + } + }); + } + + @Environment(EnvType.CLIENT) + public void handlePacketClient(ClientPlayNetworking.Context context, PacketBase> packet) { + packet.actionClient(context.player().level(), context.player()); + } + @Override public void sendToServer(PacketBase packet) { ClientPlayNetworking.send(packet);