Skip to content

Commit

Permalink
Payload Splitter Interface / IClientPayloadData
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Jun 11, 2024
1 parent 38edde8 commit 211b0d2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/fi/dy/masa/malilib/network/PayloadSplitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;
import io.netty.buffer.Unpooled;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.listener.PacketListener;
Expand Down Expand Up @@ -86,6 +87,18 @@ public static PacketByteBuf readPayload(PacketByteBuf byteBuf)
return newBuf;
}

/**
* Sends a packet type ID as a VarInt, and then the given Compound tag.
*/
public static <T extends CustomPayload> void sendPacketTypeAndCompound(IPluginClientPlayHandler<T> handler, int packetType, NbtCompound data, ClientPlayNetworkHandler networkHandler)
{
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeVarInt(packetType);
buf.writeNbt(data);

send(handler, buf, networkHandler);
}

private static class ReadingSession
{
private final Pair<PacketListener, Identifier> key;
Expand Down

0 comments on commit 211b0d2

Please sign in to comment.