ProtocolInfoBuilder.java
net.minecraft.network.protocol.ProtocolInfoBuilder
信息
- 全限定名:net.minecraft.network.protocol.ProtocolInfoBuilder
- 类型:public class
- 包:net.minecraft.network.protocol
- 源码路径:src/main/java/net/minecraft/network/protocol/ProtocolInfoBuilder.java
- 起始行号:L18
- 职责:
TODO
字段/常量
-
protocol- 类型:
ConnectionProtocol - 修饰符:
private final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
flow- 类型:
PacketFlow - 修饰符:
private final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
codecs- 类型:
List<ProtocolInfoBuilder.CodecEntry<T,?,B,C>> - 修饰符:
private final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
bundlerInfo- 类型:
BundlerInfo - 修饰符:
private - 源码定位:
L22 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.network.protocol.ProtocolInfoBuilder.CodecEntry- 类型:
record - 修饰符:
private - 源码定位:
L179 - 说明:
TODO
- 类型:
-
net.minecraft.network.protocol.ProtocolInfoBuilder.Implementation- 类型:
record - 修饰符:
private - 源码定位:
L195 - 说明:
TODO
- 类型:
构造器
public ProtocolInfoBuilder(ConnectionProtocol protocol, PacketFlow flow) @ L24
- 构造器名:ProtocolInfoBuilder
- 源码定位:L24
- 修饰符:public
参数:
- protocol: ConnectionProtocol
- flow: PacketFlow
说明:
TODO
方法
下面的方法块按源码顺序生成。
public <P extends Packet<?super T>> ProtocolInfoBuilder<T,B,C> addPacket(PacketType<P> type, StreamCodec<?super B,P> serializer) @ L29
- 方法名:addPacket
- 源码定位:L29
- 返回类型:<P extends Packet<?super T>> ProtocolInfoBuilder<T,B,C>
- 修饰符:public
参数:
- type: PacketType
- serializer: StreamCodec<?super B,P>
说明:
TODO
public <P extends Packet<?super T>> ProtocolInfoBuilder<T,B,C> addPacket(PacketType<P> type, StreamCodec<?super B,P> serializer, CodecModifier<B,P,C> modifier) @ L34
- 方法名:addPacket
- 源码定位:L34
- 返回类型:<P extends Packet<?super T>> ProtocolInfoBuilder<T,B,C>
- 修饰符:public
参数:
- type: PacketType
- serializer: StreamCodec<?super B,P>
- modifier: CodecModifier<B,P,C>
说明:
TODO
public <P extends BundlePacket<?super T>,D extends BundleDelimiterPacket<?super T>> ProtocolInfoBuilder<T,B,C> withBundlePacket(PacketType<P> bundlerPacket, Function<Iterable<Packet<?super T>>,P> constructor, D delimiterPacket) @ L41
- 方法名:withBundlePacket
- 源码定位:L41
- 返回类型:<P extends BundlePacket<?super T>,D extends BundleDelimiterPacket<?super T>> ProtocolInfoBuilder<T,B,C>
- 修饰符:public
参数:
- bundlerPacket: PacketType
- constructor: Function<Iterable<Packet<?super T>>,P>
- delimiterPacket: D
说明:
TODO
private StreamCodec<ByteBuf,Packet<?super T>> buildPacketCodec(Function<ByteBuf,B> contextWrapper, List<ProtocolInfoBuilder.CodecEntry<T,?,B,C>> codecs, C context) @ L51
- 方法名:buildPacketCodec
- 源码定位:L51
- 返回类型:StreamCodec<ByteBuf,Packet<?super T>>
- 修饰符:private
参数:
- contextWrapper: Function<ByteBuf,B>
- codecs: List<ProtocolInfoBuilder.CodecEntry<T,?,B,C>>
- context: C
说明:
TODO
private static ProtocolInfo.Details buildDetails(ConnectionProtocol protocol, PacketFlow flow, List<?extends ProtocolInfoBuilder.CodecEntry<?,?,?,?>> codecs) @ L63
- 方法名:buildDetails
- 源码定位:L63
- 返回类型:ProtocolInfo.Details
- 修饰符:private static
参数:
- protocol: ConnectionProtocol
- flow: PacketFlow
- codecs: List>
说明:
TODO
public SimpleUnboundProtocol<T,B> buildUnbound(C context) @ L87
- 方法名:buildUnbound
- 源码定位:L87
- 返回类型:SimpleUnboundProtocol<T,B>
- 修饰符:public
参数:
- context: C
说明:
TODO
public UnboundProtocol<T,B,C> buildUnbound() @ L113
- 方法名:buildUnbound
- 源码定位:L113
- 返回类型:UnboundProtocol<T,B,C>
- 修饰符:public
参数:
- 无
说明:
TODO
private static <L extends PacketListener,B extends ByteBuf> SimpleUnboundProtocol<L,B> protocol(ConnectionProtocol id, PacketFlow flow, Consumer<ProtocolInfoBuilder<L,B,Unit>> config) @ L139
- 方法名:protocol
- 源码定位:L139
- 返回类型:<L extends PacketListener,B extends ByteBuf> SimpleUnboundProtocol<L,B>
- 修饰符:private static
参数:
- id: ConnectionProtocol
- flow: PacketFlow
- config: Consumer<ProtocolInfoBuilder<L,B,Unit>>
说明:
TODO
public static <T extends ServerboundPacketListener,B extends ByteBuf> SimpleUnboundProtocol<T,B> serverboundProtocol(ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T,B,Unit>> config) @ L147
- 方法名:serverboundProtocol
- 源码定位:L147
- 返回类型:<T extends ServerboundPacketListener,B extends ByteBuf> SimpleUnboundProtocol<T,B>
- 修饰符:public static
参数:
- id: ConnectionProtocol
- config: Consumer<ProtocolInfoBuilder<T,B,Unit>>
说明:
TODO
public static <T extends ClientboundPacketListener,B extends ByteBuf> SimpleUnboundProtocol<T,B> clientboundProtocol(ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T,B,Unit>> config) @ L153
- 方法名:clientboundProtocol
- 源码定位:L153
- 返回类型:<T extends ClientboundPacketListener,B extends ByteBuf> SimpleUnboundProtocol<T,B>
- 修饰符:public static
参数:
- id: ConnectionProtocol
- config: Consumer<ProtocolInfoBuilder<T,B,Unit>>
说明:
TODO
private static <L extends PacketListener,B extends ByteBuf,C> UnboundProtocol<L,B,C> contextProtocol(ConnectionProtocol id, PacketFlow flow, Consumer<ProtocolInfoBuilder<L,B,C>> config) @ L159
- 方法名:contextProtocol
- 源码定位:L159
- 返回类型:<L extends PacketListener,B extends ByteBuf,C> UnboundProtocol<L,B,C>
- 修饰符:private static
参数:
- id: ConnectionProtocol
- flow: PacketFlow
- config: Consumer<ProtocolInfoBuilder<L,B,C>>
说明:
TODO
public static <T extends ServerboundPacketListener,B extends ByteBuf,C> UnboundProtocol<T,B,C> contextServerboundProtocol(ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T,B,C>> config) @ L167
- 方法名:contextServerboundProtocol
- 源码定位:L167
- 返回类型:<T extends ServerboundPacketListener,B extends ByteBuf,C> UnboundProtocol<T,B,C>
- 修饰符:public static
参数:
- id: ConnectionProtocol
- config: Consumer<ProtocolInfoBuilder<T,B,C>>
说明:
TODO
public static <T extends ClientboundPacketListener,B extends ByteBuf,C> UnboundProtocol<T,B,C> contextClientboundProtocol(ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T,B,C>> config) @ L173
- 方法名:contextClientboundProtocol
- 源码定位:L173
- 返回类型:<T extends ClientboundPacketListener,B extends ByteBuf,C> UnboundProtocol<T,B,C>
- 修饰符:public static
参数:
- id: ConnectionProtocol
- config: Consumer<ProtocolInfoBuilder<T,B,C>>
说明:
TODO
代码
public class ProtocolInfoBuilder<T extends PacketListener, B extends ByteBuf, C> {
private final ConnectionProtocol protocol;
private final PacketFlow flow;
private final List<ProtocolInfoBuilder.CodecEntry<T, ?, B, C>> codecs = new ArrayList<>();
private @Nullable BundlerInfo bundlerInfo;
public ProtocolInfoBuilder(ConnectionProtocol protocol, PacketFlow flow) {
this.protocol = protocol;
this.flow = flow;
}
public <P extends Packet<? super T>> ProtocolInfoBuilder<T, B, C> addPacket(PacketType<P> type, StreamCodec<? super B, P> serializer) {
this.codecs.add(new ProtocolInfoBuilder.CodecEntry<>(type, serializer, null));
return this;
}
public <P extends Packet<? super T>> ProtocolInfoBuilder<T, B, C> addPacket(
PacketType<P> type, StreamCodec<? super B, P> serializer, CodecModifier<B, P, C> modifier
) {
this.codecs.add(new ProtocolInfoBuilder.CodecEntry<>(type, serializer, modifier));
return this;
}
public <P extends BundlePacket<? super T>, D extends BundleDelimiterPacket<? super T>> ProtocolInfoBuilder<T, B, C> withBundlePacket(
PacketType<P> bundlerPacket, Function<Iterable<Packet<? super T>>, P> constructor, D delimiterPacket
) {
StreamCodec<ByteBuf, D> delimitedCodec = StreamCodec.unit(delimiterPacket);
PacketType<D> delimiterType = (PacketType<D>)(PacketType<?>)delimiterPacket.type();
this.codecs.add(new ProtocolInfoBuilder.CodecEntry<>(delimiterType, delimitedCodec, null));
this.bundlerInfo = BundlerInfo.createForPacket(bundlerPacket, constructor, delimiterPacket);
return this;
}
private StreamCodec<ByteBuf, Packet<? super T>> buildPacketCodec(
Function<ByteBuf, B> contextWrapper, List<ProtocolInfoBuilder.CodecEntry<T, ?, B, C>> codecs, C context
) {
ProtocolCodecBuilder<ByteBuf, T> codecBuilder = new ProtocolCodecBuilder<>(this.flow);
for (ProtocolInfoBuilder.CodecEntry<T, ?, B, C> codec : codecs) {
codec.addToBuilder(codecBuilder, contextWrapper, context);
}
return codecBuilder.build();
}
private static ProtocolInfo.Details buildDetails(
ConnectionProtocol protocol, PacketFlow flow, List<? extends ProtocolInfoBuilder.CodecEntry<?, ?, ?, ?>> codecs
) {
return new ProtocolInfo.Details() {
@Override
public ConnectionProtocol id() {
return protocol;
}
@Override
public PacketFlow flow() {
return flow;
}
@Override
public void listPackets(ProtocolInfo.Details.PacketVisitor output) {
for (int i = 0; i < codecs.size(); i++) {
ProtocolInfoBuilder.CodecEntry<?, ?, ?, ?> entry = (ProtocolInfoBuilder.CodecEntry<?, ?, ?, ?>)codecs.get(i);
output.accept(entry.type, i);
}
}
};
}
public SimpleUnboundProtocol<T, B> buildUnbound(C context) {
final List<ProtocolInfoBuilder.CodecEntry<T, ?, B, C>> codecs = List.copyOf(this.codecs);
final BundlerInfo bundlerInfo = this.bundlerInfo;
final ProtocolInfo.Details details = buildDetails(this.protocol, this.flow, codecs);
return new SimpleUnboundProtocol<T, B>() {
{
Objects.requireNonNull(ProtocolInfoBuilder.this);
}
@Override
public ProtocolInfo<T> bind(Function<ByteBuf, B> contextWrapper) {
return new ProtocolInfoBuilder.Implementation<>(
ProtocolInfoBuilder.this.protocol,
ProtocolInfoBuilder.this.flow,
ProtocolInfoBuilder.this.buildPacketCodec(contextWrapper, codecs, context),
bundlerInfo
);
}
@Override
public ProtocolInfo.Details details() {
return details;
}
};
}
public UnboundProtocol<T, B, C> buildUnbound() {
final List<ProtocolInfoBuilder.CodecEntry<T, ?, B, C>> codecs = List.copyOf(this.codecs);
final BundlerInfo bundlerInfo = this.bundlerInfo;
final ProtocolInfo.Details details = buildDetails(this.protocol, this.flow, codecs);
return new UnboundProtocol<T, B, C>() {
{
Objects.requireNonNull(ProtocolInfoBuilder.this);
}
@Override
public ProtocolInfo<T> bind(Function<ByteBuf, B> contextWrapper, C context) {
return new ProtocolInfoBuilder.Implementation<>(
ProtocolInfoBuilder.this.protocol,
ProtocolInfoBuilder.this.flow,
ProtocolInfoBuilder.this.buildPacketCodec(contextWrapper, codecs, context),
bundlerInfo
);
}
@Override
public ProtocolInfo.Details details() {
return details;
}
};
}
private static <L extends PacketListener, B extends ByteBuf> SimpleUnboundProtocol<L, B> protocol(
ConnectionProtocol id, PacketFlow flow, Consumer<ProtocolInfoBuilder<L, B, Unit>> config
) {
ProtocolInfoBuilder<L, B, Unit> builder = new ProtocolInfoBuilder<>(id, flow);
config.accept(builder);
return builder.buildUnbound(Unit.INSTANCE);
}
public static <T extends ServerboundPacketListener, B extends ByteBuf> SimpleUnboundProtocol<T, B> serverboundProtocol(
ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T, B, Unit>> config
) {
return protocol(id, PacketFlow.SERVERBOUND, config);
}
public static <T extends ClientboundPacketListener, B extends ByteBuf> SimpleUnboundProtocol<T, B> clientboundProtocol(
ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T, B, Unit>> config
) {
return protocol(id, PacketFlow.CLIENTBOUND, config);
}
private static <L extends PacketListener, B extends ByteBuf, C> UnboundProtocol<L, B, C> contextProtocol(
ConnectionProtocol id, PacketFlow flow, Consumer<ProtocolInfoBuilder<L, B, C>> config
) {
ProtocolInfoBuilder<L, B, C> builder = new ProtocolInfoBuilder<>(id, flow);
config.accept(builder);
return builder.buildUnbound();
}
public static <T extends ServerboundPacketListener, B extends ByteBuf, C> UnboundProtocol<T, B, C> contextServerboundProtocol(
ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T, B, C>> config
) {
return contextProtocol(id, PacketFlow.SERVERBOUND, config);
}
public static <T extends ClientboundPacketListener, B extends ByteBuf, C> UnboundProtocol<T, B, C> contextClientboundProtocol(
ConnectionProtocol id, Consumer<ProtocolInfoBuilder<T, B, C>> config
) {
return contextProtocol(id, PacketFlow.CLIENTBOUND, config);
}
private record CodecEntry<T extends PacketListener, P extends Packet<? super T>, B extends ByteBuf, C>(
PacketType<P> type, StreamCodec<? super B, P> serializer, @Nullable CodecModifier<B, P, C> modifier
) {
public void addToBuilder(ProtocolCodecBuilder<ByteBuf, T> codecBuilder, Function<ByteBuf, B> contextWrapper, C context) {
StreamCodec<? super B, P> finalSerializer;
if (this.modifier != null) {
finalSerializer = this.modifier.apply(this.serializer, context);
} else {
finalSerializer = this.serializer;
}
StreamCodec<ByteBuf, P> baseCodec = finalSerializer.mapStream(contextWrapper);
codecBuilder.add(this.type, baseCodec);
}
}
private record Implementation<L extends PacketListener>(
ConnectionProtocol id, PacketFlow flow, StreamCodec<ByteBuf, Packet<? super L>> codec, @Nullable BundlerInfo bundlerInfo
) implements ProtocolInfo<L> {
}
}引用的其他类
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用/构造调用/返回值 - 关联成员:
Details(), ProtocolInfo.Details()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/方法调用/返回值 - 关联成员:
StreamCodec.unit()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
BundlerInfo.createForPacket()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置: