66import net .fabricmc .fabric .api .networking .v1 .PayloadTypeRegistry ;
77import net .fabricmc .fabric .api .networking .v1 .ServerPlayNetworking ;
88import net .minecraft .network .protocol .common .custom .CustomPacketPayload ;
9- import net .minecraft .resources .ResourceLocation ;
9+ import net .minecraft .resources .Identifier ;
1010import net .minecraft .server .MinecraftServer ;
1111import net .minecraft .server .level .ServerPlayer ;
1212
3030 * @param <S> the serverbound message listener type
3131 * @param <C> the clientbound message listener type
3232 *
33- * @see #onUnknownClientboundMessage(ResourceLocation , byte[], int)
34- * @see #onUnknownServerboundMessage(MinecraftServer, ServerPlayer, ResourceLocation , byte[], int)
35- * @see #onClientboundMessageReadException(ResourceLocation , byte[], Throwable)
36- * @see #onServerboundMessageReadException(MinecraftServer, ServerPlayer, ResourceLocation , byte[], Throwable)
37- * @see #onSuccessfulClientboundMessage(ResourceLocation , Message)
38- * @see #onSuccessfulServerboundMessage(MinecraftServer, ServerPlayer, ResourceLocation , Message)
33+ * @see #onUnknownClientboundMessage(Identifier , byte[], int)
34+ * @see #onUnknownServerboundMessage(MinecraftServer, ServerPlayer, Identifier , byte[], int)
35+ * @see #onClientboundMessageReadException(Identifier , byte[], Throwable)
36+ * @see #onServerboundMessageReadException(MinecraftServer, ServerPlayer, Identifier , byte[], Throwable)
37+ * @see #onSuccessfulClientboundMessage(Identifier , Message)
38+ * @see #onSuccessfulServerboundMessage(MinecraftServer, ServerPlayer, Identifier , Message)
3939 */
4040public abstract class FabricChannelRegistrar <S extends ServerboundMessageListener , C extends ClientboundMessageListener > implements ChannelRegistrar <S , C > {
4141
@@ -79,7 +79,7 @@ public void registerClientboundMessageHandler(@NotNull NamespacedKey channel, @N
7979 return ;
8080 }
8181
82- ResourceLocation channelKey = ResourceLocation .fromNamespaceAndPath (channel .namespace (), channel .key ());
82+ Identifier channelKey = Identifier .fromNamespaceAndPath (channel .namespace (), channel .key ());
8383 ClientPlayNetworking .registerGlobalReceiver (payloadType , (payload , context ) -> {
8484 MessageByteBuffer buffer = new MessageByteBuffer (protocol , payload .data ());
8585
@@ -111,7 +111,7 @@ public void registerServerboundMessageHandler(@NotNull NamespacedKey channel, @N
111111 return ;
112112 }
113113
114- ResourceLocation channelKey = ResourceLocation .fromNamespaceAndPath (channel .namespace (), channel .key ());
114+ Identifier channelKey = Identifier .fromNamespaceAndPath (channel .namespace (), channel .key ());
115115 ServerPlayNetworking .registerGlobalReceiver (payloadType , (payload , context ) -> {
116116 MessageByteBuffer buffer = new MessageByteBuffer (protocol , payload .data ());
117117
@@ -145,7 +145,7 @@ public void registerServerboundMessageHandler(@NotNull NamespacedKey channel, @N
145145 * @param data the raw byte data payload from the message (including the message id)
146146 * @param messageId the message id that was read from the message data
147147 */
148- protected void onUnknownClientboundMessage (@ NotNull ResourceLocation channel , byte @ NotNull [] data , int messageId ) {
148+ protected void onUnknownClientboundMessage (@ NotNull Identifier channel , byte @ NotNull [] data , int messageId ) {
149149 this .logger .warn ("Received unknown packet with id " + messageId + " from server on channel \" " + channel + "\" . Ignoring." );
150150 }
151151
@@ -159,7 +159,7 @@ protected void onUnknownClientboundMessage(@NotNull ResourceLocation channel, by
159159 * @param data the raw byte data payload from the message (including the message id)
160160 * @param messageId the message id that was read from the message data
161161 */
162- protected void onUnknownServerboundMessage (@ NotNull MinecraftServer server , @ NotNull ServerPlayer sender , @ NotNull ResourceLocation channel , byte @ NotNull [] data , int messageId ) {
162+ protected void onUnknownServerboundMessage (@ NotNull MinecraftServer server , @ NotNull ServerPlayer sender , @ NotNull Identifier channel , byte @ NotNull [] data , int messageId ) {
163163 this .logger .warn ("Received unknown packet with id " + messageId + " from " + sender .getName ().getString () + " on channel \" " + channel + "\" . Ignoring." );
164164 }
165165
@@ -171,7 +171,7 @@ protected void onUnknownServerboundMessage(@NotNull MinecraftServer server, @Not
171171 * @param data the raw byte data payload from the message
172172 * @param e the exception that was thrown
173173 */
174- protected void onClientboundMessageReadException (@ NotNull ResourceLocation channel , byte @ NotNull [] data , @ NotNull Throwable e ) {
174+ protected void onClientboundMessageReadException (@ NotNull Identifier channel , byte @ NotNull [] data , @ NotNull Throwable e ) {
175175 this .logger .warn ("Failed to read message sent from server on channel \" " + channel + "\" . Received erroneous data." );
176176 e .printStackTrace ();
177177 }
@@ -186,7 +186,7 @@ protected void onClientboundMessageReadException(@NotNull ResourceLocation chann
186186 * @param data the raw byte data payload from the message
187187 * @param e the exception that was thrown
188188 */
189- protected void onServerboundMessageReadException (@ NotNull MinecraftServer server , @ NotNull ServerPlayer sender , @ NotNull ResourceLocation channel , byte @ NotNull [] data , @ NotNull Throwable e ) {
189+ protected void onServerboundMessageReadException (@ NotNull MinecraftServer server , @ NotNull ServerPlayer sender , @ NotNull Identifier channel , byte @ NotNull [] data , @ NotNull Throwable e ) {
190190 this .logger .warn ("Failed to read message sent by " + sender .getName ().getString () + " on channel \" " + channel + "\" . Received erroneous data." );
191191 e .printStackTrace ();
192192 }
@@ -217,7 +217,7 @@ protected void onServerboundMessageReadException(@NotNull MinecraftServer server
217217 * }
218218 *
219219 * {@literal @Override}
220- * protected MyClientboundMessageListener onSuccessfulClientboundMessage(ResourceLocation channel, {@literal Message<MyClientboundMessageListener>} message) {
220+ * protected MyClientboundMessageListener onSuccessfulClientboundMessage(Identifier channel, {@literal Message<MyClientboundMessageListener>} message) {
221221 * return MyMod.MESSAGE_LISTENER; // That's it. The FabricChannelRegistrar will handle the listening
222222 * }
223223 *
@@ -243,7 +243,7 @@ protected void onServerboundMessageReadException(@NotNull MinecraftServer server
243243 * null if the message should not be handled
244244 */
245245 @ Nullable
246- protected C onSuccessfulClientboundMessage (@ NotNull ResourceLocation channel , @ NotNull Message <C > message ) {
246+ protected C onSuccessfulClientboundMessage (@ NotNull Identifier channel , @ NotNull Message <C > message ) {
247247 this .logger .info ("Received message from server (" + message .getClass ().getName () + ") but it was not handled. Did you override onSuccessfulClientboundMessage()?" );
248248 return null ;
249249 }
@@ -278,7 +278,7 @@ protected C onSuccessfulClientboundMessage(@NotNull ResourceLocation channel, @N
278278 * super(protocol, logger, false); // false = on the server
279279 * }
280280 *
281- * protected MyServerboundMessageListener onSuccessfulServerboundMessage(MinecraftServer server, ServerPlayer player, ResourceLocation channel, {@literal Message<MyServerboundMessageListener>} message) {
281+ * protected MyServerboundMessageListener onSuccessfulServerboundMessage(MinecraftServer server, ServerPlayer player, Identifier channel, {@literal Message<MyServerboundMessageListener>} message) {
282282 * return MyMod.getInstance().getMessageListener(player); // That's it. The FabricChannelRegistrar will handle the listening
283283 * }
284284 *
@@ -306,15 +306,15 @@ protected C onSuccessfulClientboundMessage(@NotNull ResourceLocation channel, @N
306306 * null if the message should not be handled
307307 */
308308 @ Nullable
309- protected S onSuccessfulServerboundMessage (@ NotNull MinecraftServer server , @ NotNull ServerPlayer player , @ NotNull ResourceLocation channel , @ NotNull Message <S > message ) {
309+ protected S onSuccessfulServerboundMessage (@ NotNull MinecraftServer server , @ NotNull ServerPlayer player , @ NotNull Identifier channel , @ NotNull Message <S > message ) {
310310 this .logger .info ("Received message from " + player .getName ().getString () + " (" + message .getClass ().getName () + ") but it was not handled. Did you override onSuccessfulServerboundMessage()?" );
311311 return null ;
312312 }
313313
314314 private CustomPacketPayload .Type <RawDataPayload > initTypeIfNecessary (NamespacedKey channel ) {
315315 CustomPacketPayload .Type <RawDataPayload > type = RawDataPayload .getType ();
316316 if (type == null ) {
317- RawDataPayload .setType (type = new CustomPacketPayload .Type <>(ResourceLocation .parse (channel .toString ())));
317+ RawDataPayload .setType (type = new CustomPacketPayload .Type <>(Identifier .parse (channel .toString ())));
318318 }
319319 return type ;
320320 }
0 commit comments