Skip to content

Commit

Permalink
Implement ServerUtil#registerCodecs for C2S & S2C
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Sep 9, 2024
1 parent 222353e commit 04c9478
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.cstav.genshinstrument.networking.packet.instrument.util.ClientDistExec;
import com.cstav.genshinstrument.util.ServerUtil;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -36,8 +35,7 @@ public class GIPacketHandler {


public static void registerCodecs() {
ServerUtil.registerCodecs(PayloadTypeRegistry.playC2S(), C2S_PACKETS);
ServerUtil.registerCodecs(PayloadTypeRegistry.playS2C(), S2C_PACKETS);
ServerUtil.registerCodecs(C2S_PACKETS, S2C_PACKETS);
}

public static void registerClientPackets() {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/cstav/genshinstrument/util/ServerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

public class ServerUtil {

public static void registerCodecs(
List<Class<IModPacket>> c2sPacketTypes,
List<Class<IModPacket>> s2cPacketTypes
) {
ServerUtil.registerCodecs(PayloadTypeRegistry.playC2S(), c2sPacketTypes);
ServerUtil.registerCodecs(PayloadTypeRegistry.playS2C(), s2cPacketTypes);
}

public static void registerCodecs(PayloadTypeRegistry<RegistryFriendlyByteBuf> registry, List<Class<IModPacket>> packetTypes) {
for (final Class<IModPacket> packetClass : packetTypes) {
registry.register(
Expand All @@ -23,6 +31,7 @@ public static void registerCodecs(PayloadTypeRegistry<RegistryFriendlyByteBuf> r
}
}


public static void registerServerPackets(final List<Class<IModPacket>> packetTypes) {
for (final Class<IModPacket> packetClass : packetTypes) {
ServerPlayNetworking.registerGlobalReceiver(
Expand Down

0 comments on commit 04c9478

Please sign in to comment.