Class PayloadRegistrar
java.lang.Object
net.neoforged.neoforge.network.registration.PayloadRegistrar
Builder-style helper for registering
CustomPacketPayload
s, used for modded networking.-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionPayloadRegistrar
(String version) private
PayloadRegistrar
(PayloadRegistrar source) -
Method Summary
Modifier and TypeMethodDescription<T extends CustomPacketPayload>
PayloadRegistrarcommonBidirectional
(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a bidirectional payload for all phases.<T extends CustomPacketPayload>
PayloadRegistrarcommonToClient
(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a client-bound payload for all phases.<T extends CustomPacketPayload>
PayloadRegistrarcommonToServer
(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a server-bound payload for all phases.<T extends CustomPacketPayload>
PayloadRegistrarconfigurationBidirectional
(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a bidirectional payload for the configuration phase.<T extends CustomPacketPayload>
PayloadRegistrarconfigurationToClient
(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a client-bound payload for the configuration phase.<T extends CustomPacketPayload>
PayloadRegistrarconfigurationToServer
(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a server-bound payload for the configuration phase.executesOn
(HandlerThread thread) Creates a copy of this registrar with a different default handling thread.optional()
Creates a copy of this registrar with optional mode enabled.<T extends CustomPacketPayload>
PayloadRegistrarplayBidirectional
(CustomPacketPayload.Type<T> type, StreamCodec<? super RegistryFriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a bidirectional payload for the play phase.<T extends CustomPacketPayload>
PayloadRegistrarplayToClient
(CustomPacketPayload.Type<T> type, StreamCodec<? super RegistryFriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a client-bound payload for the play phase.<T extends CustomPacketPayload>
PayloadRegistrarplayToServer
(CustomPacketPayload.Type<T> type, StreamCodec<? super RegistryFriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a server-bound payload for the play phase.private <T extends CustomPacketPayload,
B extends FriendlyByteBuf>
voidregister
(CustomPacketPayload.Type<T> type, StreamCodec<? super B, T> codec, IPayloadHandler<T> handler, List<ConnectionProtocol> protocols, Optional<PacketFlow> flow, String version, boolean optional) Creates a copy of this registrar with a different version.
-
Field Details
-
version
-
optional
private boolean optional -
thread
-
-
Constructor Details
-
PayloadRegistrar
-
PayloadRegistrar
-
-
Method Details
-
playToClient
public <T extends CustomPacketPayload> PayloadRegistrar playToClient(CustomPacketPayload.Type<T> type, StreamCodec<? super RegistryFriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a client-bound payload for the play phase. -
playToServer
public <T extends CustomPacketPayload> PayloadRegistrar playToServer(CustomPacketPayload.Type<T> type, StreamCodec<? super RegistryFriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a server-bound payload for the play phase. -
playBidirectional
public <T extends CustomPacketPayload> PayloadRegistrar playBidirectional(CustomPacketPayload.Type<T> type, StreamCodec<? super RegistryFriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a bidirectional payload for the play phase.Consider using
DirectionalPayloadHandler
to wrap client and server handlers. -
configurationToClient
public <T extends CustomPacketPayload> PayloadRegistrar configurationToClient(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a client-bound payload for the configuration phase. -
configurationToServer
public <T extends CustomPacketPayload> PayloadRegistrar configurationToServer(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a server-bound payload for the configuration phase. -
configurationBidirectional
public <T extends CustomPacketPayload> PayloadRegistrar configurationBidirectional(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a bidirectional payload for the configuration phase.Consider using
DirectionalPayloadHandler
to wrap client and server handlers. -
commonToClient
public <T extends CustomPacketPayload> PayloadRegistrar commonToClient(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a client-bound payload for all phases. -
commonToServer
public <T extends CustomPacketPayload> PayloadRegistrar commonToServer(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a server-bound payload for all phases. -
commonBidirectional
public <T extends CustomPacketPayload> PayloadRegistrar commonBidirectional(CustomPacketPayload.Type<T> type, StreamCodec<? super FriendlyByteBuf, T> reader, IPayloadHandler<T> handler) Registers a bidirectional payload for all phases.Consider using
DirectionalPayloadHandler
to wrap client and server handlers. -
executesOn
Creates a copy of this registrar with a different default handling thread.When the handling thread is set to
HandlerThread.MAIN
, all registered handlers will be wrapped inMainThreadPayloadHandler
.The initial handling thread is
HandlerThread.MAIN
.- Parameters:
thread
- The default handling thread.- Returns:
- A new registrar, which will map payload handlers to the desired thread.
-
versioned
Creates a copy of this registrar with a different version. Payloads registered with the returned copy will use the passed version, instead of the version from the constructor.On Neo-Neo connections, the connection will only succeed if all registered payloads have the same version.
On other connections, the payload version is ignored, since only Neo knows how to communicate Neo payload versions.
- Parameters:
version
- The version to use.- Returns:
- A new registrar, ready to configure payloads with that version.
-
optional
Creates a copy of this registrar with optional mode enabled. Payloads registered with the returned copy will be marked as optional.If any non-optional payloads are missing during a connection attempt, the connection will fail.
- Returns:
- A new registrar, ready to configure payloads as optional.
-
register
private <T extends CustomPacketPayload,B extends FriendlyByteBuf> void register(CustomPacketPayload.Type<T> type, StreamCodec<? super B, T> codec, IPayloadHandler<T> handler, List<ConnectionProtocol> protocols, Optional<PacketFlow> flow, String version, boolean optional)
-