88import net .hypixel .modapi .fabric .event .HypixelModAPICallback ;
99import net .hypixel .modapi .fabric .payload .ClientboundHypixelPayload ;
1010import net .hypixel .modapi .fabric .payload .ServerboundHypixelPayload ;
11+ import net .minecraft .client .MinecraftClient ;
1112import net .minecraft .network .PacketByteBuf ;
1213import net .minecraft .network .codec .PacketCodec ;
1314import net .minecraft .network .packet .CustomPayload ;
@@ -31,6 +32,7 @@ public static void reloadRegistrations() {
3132 for (String identifier : HypixelModAPI .getInstance ().getRegistry ().getClientboundIdentifiers ()) {
3233 try {
3334 registerClientbound (identifier );
35+ LOGGER .info ("Registered clientbound packet with identifier '{}'" , identifier );
3436 } catch (Exception e ) {
3537 LOGGER .error ("Failed to register clientbound packet with identifier '{}'" , identifier , e );
3638 }
@@ -39,6 +41,7 @@ public static void reloadRegistrations() {
3941 for (String identifier : HypixelModAPI .getInstance ().getRegistry ().getServerboundIdentifiers ()) {
4042 try {
4143 registerServerbound (identifier );
44+ LOGGER .info ("Registered serverbound packet with identifier '{}'" , identifier );
4245 } catch (Exception e ) {
4346 LOGGER .error ("Failed to register serverbound packet with identifier '{}'" , identifier , e );
4447 }
@@ -47,8 +50,14 @@ public static void reloadRegistrations() {
4750
4851 private static void registerPacketSender () {
4952 HypixelModAPI .getInstance ().setPacketSender ((packet ) -> {
53+ if (MinecraftClient .getInstance ().getNetworkHandler () == null ) {
54+ // The client is not connected to a server, so we can't send the packet
55+ return false ;
56+ }
57+
5058 ServerboundHypixelPayload payload = new ServerboundHypixelPayload (packet );
5159 ClientPlayNetworking .send (payload );
60+ return true ;
5261 });
5362 }
5463
0 commit comments