BundlerInfo .java

net.minecraft.network.protocol.BundlerInfo (interface): members: startPacketBundling, BUNDLE_SIZE_LIMIT, createForPacket, unbundlePacket, Bundler.

net.minecraft.network.protocolinterface61 linescommon1.8 KB

API Surface (1)

void unbundlePacket(final Packet<?> packet, final Consumer<Packet<?>> output)

Fields & Constants (3)

BUNDLE_SIZE_LIMIT
PacketListener
constructor

String literals (1)

"Too many packets in a bundle"

Code Graph: Dependencies (4)

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

Full Source

BundlerInfo.java61 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.network.protocol;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.function.Consumer;
6
import java.util.function.Function;
7
import net.minecraft.network.PacketListener;
8
import org.jspecify.annotations.Nullable;
9
10
public interface BundlerInfo {
11
	int BUNDLE_SIZE_LIMIT = 4096;
12
13
	static <T extends PacketListener, P extends BundlePacket<? super T>> BundlerInfo createForPacket(
14
		final PacketType<P> bundlePacketType, final Function<Iterable<Packet<? super T>>, P> constructor, final BundleDelimiterPacket<? super T> delimiterPacket
15
	) {
16
		return new BundlerInfo() {
17
			@Override
18
			public void unbundlePacket(final Packet<?> packet, final Consumer<Packet<?>> output) {
19
				if (packet.type() == bundlePacketType) {
20
					P bundlerPacket = (P)packet;
21
					output.accept(delimiterPacket);
22
					bundlerPacket.subPackets().forEach(output);
23
					output.accept(delimiterPacket);
24
				} else {
25
					output.accept(packet);
26
				}
27
			}
28
29
			@Override
30
			public BundlerInfo.@Nullable Bundler startPacketBundling(final Packet<?> packet) {
31
				return packet == delimiterPacket ? new BundlerInfo.Bundler() {
32
					private final List<Packet<? super T>> bundlePackets = new ArrayList<>();
33
34
					@Override
35
					public @Nullable Packet<?> addPacket(final Packet<?> packet) {
36
						if (packet == delimiterPacket) {
37
							return constructor.apply(this.bundlePackets);
38
						}
39
40
						Packet<T> castPacket = (Packet<T>)packet;
41
						if (this.bundlePackets.size() >= 4096) {
42
							throw new IllegalStateException("Too many packets in a bundle");
43
						}
44
45
						this.bundlePackets.add(castPacket);
46
						return null;
47
					}
48
				} : null;
49
			}
50
		};
51
	}
52
53
	void unbundlePacket(Packet<?> packet, Consumer<Packet<?>> output);
54
55
	BundlerInfo.@Nullable Bundler startPacketBundling(Packet<?> packet);
56
57
	interface Bundler {
58
		@Nullable Packet<?> addPacket(Packet<?> packet);
59
	}
60
}
61

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