Class CustomPayloadNetwork
java.lang.Object
io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetwork
This is a utility class that allows you to register custom payload receivers
using
TCDCommons
's network implementation.-
Method Summary
Modifier and TypeMethodDescriptionstatic CustomPayloadNetworkReceiver
registerReceiver
(net.minecraft.network.NetworkSide side, net.minecraft.util.Identifier packetId, CustomPayloadNetworkReceiver receiver) Registers aCustomPayloadNetworkReceiver
for a given custom payload packet.static final void
sendC2S
(net.minecraft.util.Identifier packetId, io.netty.buffer.ByteBuf packetData) Sends a custom payload from the client to the server, using theTCDCommons
network protocol.static final void
sendS2C
(net.minecraft.server.network.ServerPlayerEntity player, net.minecraft.util.Identifier packetId, io.netty.buffer.ByteBuf packetData) Sends a custom payload from the server to the client, using theTCDCommons
network protocol.static boolean
unregisterReceiver
(net.minecraft.network.NetworkSide side, net.minecraft.util.Identifier packetId) Un-Registers aCustomPayloadNetworkReceiver
for a given custom payload packet.
-
Method Details
-
registerReceiver
public static CustomPayloadNetworkReceiver registerReceiver(net.minecraft.network.NetworkSide side, net.minecraft.util.Identifier packetId, CustomPayloadNetworkReceiver receiver) Registers aCustomPayloadNetworkReceiver
for a given custom payload packet.Important: Receivers are executed on the network thread.
- Parameters:
side
- TheNetworkSide
which to listen on.packetId
- The uniqueIdentifier
of the custom payload packets to listen for.receiver
- The listener interface.- Returns:
- The
CustomPayloadNetworkReceiver
that was registered. - Throws:
NullPointerException
- If an argument is null.IllegalArgumentException
- If theNetworkSide
is "unexpected".- See Also:
-
ThreadExecutor.executeSync(Runnable)
-
unregisterReceiver
public static boolean unregisterReceiver(net.minecraft.network.NetworkSide side, net.minecraft.util.Identifier packetId) Un-Registers aCustomPayloadNetworkReceiver
for a given custom payload packet.- Parameters:
side
- TheNetworkSide
theCustomPayloadNetworkReceiver
is listening on.packetId
- The uniqueIdentifier
of the custom payload packets being listened.- Returns:
true
if theCustomPayloadNetworkReceiver
was present before getting removed.
-
sendC2S
public static final void sendC2S(net.minecraft.util.Identifier packetId, io.netty.buffer.ByteBuf packetData) throws IllegalStateException, NullPointerException Sends a custom payload from the client to the server, using theTCDCommons
network protocol.- Parameters:
packetId
- The custom payload packetIdentifier
.packetData
- The custom payload.- Throws:
NullPointerException
- If an argument isnull
.IllegalStateException
- If (NOT_CLIENT) or (REF_CNT < 1).
-
sendS2C
public static final void sendS2C(net.minecraft.server.network.ServerPlayerEntity player, net.minecraft.util.Identifier packetId, io.netty.buffer.ByteBuf packetData) throws IllegalStateException, NullPointerException Sends a custom payload from the server to the client, using theTCDCommons
network protocol.- Parameters:
player
- TheServerPlayerEntity
to send the packet to.packetId
- The custom payload packetIdentifier
.packetData
- The custom payload.- Throws:
NullPointerException
- If an argument isnull
.IllegalStateException
- If (REF_CNT < 1).
-