PacketBundlePacker .java

net.minecraft.network.PacketBundlePacker (class, 47 lines): extends MessageToMessageDecoder. members: currentBundler, bundlerInfo, decode. imports: Packet.

net.minecraft.networkclass47 linescommonextends MessageToMessageDecoder<Packet<1.4 KB

API Surface (1)

void decode(final ChannelHandlerContext ctx, final Packet<?> msg, final List<Object> out)

Fields & Constants (2)

bundlerInfo
currentBundler

String literals (1)

"Terminal message received in bundle"

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

PacketBundlePacker.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.network;
2
3
import io.netty.channel.ChannelHandlerContext;
4
import io.netty.handler.codec.DecoderException;
5
import io.netty.handler.codec.MessageToMessageDecoder;
6
import java.util.List;
7
import net.minecraft.network.protocol.BundlerInfo;
8
import net.minecraft.network.protocol.Packet;
9
import org.jspecify.annotations.Nullable;
10
11
public class PacketBundlePacker extends MessageToMessageDecoder<Packet<?>> {
12
	private final BundlerInfo bundlerInfo;
13
	private BundlerInfo.@Nullable Bundler currentBundler;
14
15
	public PacketBundlePacker(final BundlerInfo bundlerInfo) {
16
		this.bundlerInfo = bundlerInfo;
17
	}
18
19
	protected void decode(final ChannelHandlerContext ctx, final Packet<?> msg, final List<Object> out) throws Exception {
20
		if (this.currentBundler != null) {
21
			verifyNonTerminalPacket(msg);
22
			Packet<?> bundlePacket = this.currentBundler.addPacket(msg);
23
			if (bundlePacket != null) {
24
				this.currentBundler = null;
25
				out.add(bundlePacket);
26
			}
27
		} else {
28
			BundlerInfo.Bundler bundler = this.bundlerInfo.startPacketBundling(msg);
29
			if (bundler != null) {
30
				verifyNonTerminalPacket(msg);
31
				this.currentBundler = bundler;
32
			} else {
33
				out.add(msg);
34
				if (msg.isTerminal()) {
35
					ctx.pipeline().remove(ctx.name());
36
				}
37
			}
38
		}
39
	}
40
41
	private static void verifyNonTerminalPacket(final Packet<?> msg) {
42
		if (msg.isTerminal()) {
43
			throw new DecoderException("Terminal message received in bundle");
44
		}
45
	}
46
}
47

Decompiled Minecraft 26.3 source of PacketBundlePacker (net/minecraft/network/PacketBundlePacker.java) with Mojang official mappings, stored verbatim on the site.