Record Class ClientPayloadContext
java.lang.Object
java.lang.Record
net.neoforged.neoforge.network.handling.ClientPayloadContext
- All Implemented Interfaces:
IPayloadContext
@Internal
public record ClientPayloadContext(ClientCommonPacketListener listener, ResourceLocation payloadId)
extends Record
implements IPayloadContext
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ClientCommonPacketListener
The field for thelistener
record component.private final ResourceLocation
The field for thepayloadId
record component. -
Constructor Summary
ConstructorDescriptionClientPayloadContext
(ClientCommonPacketListener listener, ResourceLocation payloadId) Creates an instance of aClientPayloadContext
record class. -
Method Summary
Modifier and TypeMethodDescriptionenqueueWork
(Runnable task) For handlers running on the network thread, submits the given task to be run on the main thread of the game.<T> CompletableFuture
<T> enqueueWork
(Supplier<T> task) final boolean
Indicates whether some other object is "equal to" this one.void
Marks aConfigurationTask
as completed.flow()
Returns the flow of the received payload.void
handle
(CustomPacketPayload payload) Handles a payload using the current context.final int
hashCode()
Returns a hash code value for this object.listener()
Returns the value of thelistener
record component.Returns the value of thepayloadId
record component.player()
Retrieves the player relevant to this payload.final String
toString()
Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.neoforged.neoforge.network.handling.IPayloadContext
channelHandlerContext, connection, disconnect, handle, protocol, reply
-
Field Details
-
listener
The field for thelistener
record component. -
payloadId
The field for thepayloadId
record component.
-
-
Constructor Details
-
ClientPayloadContext
Creates an instance of aClientPayloadContext
record class.- Parameters:
listener
- the value for thelistener
record componentpayloadId
- the value for thepayloadId
record component
-
-
Method Details
-
handle
Description copied from interface:IPayloadContext
Handles a payload using the current context.Used to handle sub-payloads if necessary.
- Specified by:
handle
in interfaceIPayloadContext
- Parameters:
payload
- The payload.
-
enqueueWork
Description copied from interface:IPayloadContext
For handlers running on the network thread, submits the given task to be run on the main thread of the game.For handlers running on the main thread, immediately executes the task.
On the network thread, the future will be automatically guarded against exceptions using
CompletableFuture.exceptionally(java.util.function.Function<java.lang.Throwable, ? extends T>)
. If you need to catch your own exceptions, use a try/catch block within your task.- Specified by:
enqueueWork
in interfaceIPayloadContext
- Parameters:
task
- The task to run.
-
enqueueWork
- Specified by:
enqueueWork
in interfaceIPayloadContext
- See Also:
-
finishCurrentTask
Description copied from interface:IPayloadContext
Marks aConfigurationTask
as completed.- Specified by:
finishCurrentTask
in interfaceIPayloadContext
- Parameters:
type
- The type of task that was completed.
-
flow
Description copied from interface:IPayloadContext
Returns the flow of the received payload.- Specified by:
flow
in interfaceIPayloadContext
- Returns:
- the flow of the received payload
-
player
Description copied from interface:IPayloadContext
Retrieves the player relevant to this payload. Players are only available in theConnectionProtocol.PLAY
phase.For server-bound payloads, retrieves the sending
ServerPlayer
.For client-bound payloads, retrieves the receiving
LocalPlayer
.- Specified by:
player
in interfaceIPayloadContext
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
listener
Returns the value of thelistener
record component.- Specified by:
listener
in interfaceIPayloadContext
- Returns:
- the value of the
listener
record component
-
payloadId
Returns the value of thepayloadId
record component.- Returns:
- the value of the
payloadId
record component
-