ClientboundCommandSuggestionsPacket.java
net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket
信息
- 全限定名:net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket
- 类型:public record
- 包:net.minecraft.network.protocol.game
- 源码路径:src/main/java/net/minecraft/network/protocol/game/ClientboundCommandSuggestionsPacket.java
- 起始行号:L17
- 实现:Packet
- 职责:
TODO
字段/常量
STREAM_CODEC- 类型:
StreamCodec<RegistryFriendlyByteBuf,ClientboundCommandSuggestionsPacket> - 修饰符:
public static final - 源码定位:
L19 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket.Entry- 类型:
record - 修饰符:
public - 源码定位:
L61 - 说明:
TODO
- 类型:
构造器
public ClientboundCommandSuggestionsPacket(int id, Suggestions suggestions) @ L31
- 构造器名:ClientboundCommandSuggestionsPacket
- 源码定位:L31
- 修饰符:public
参数:
- id: int
- suggestions: Suggestions
说明:
TODO
方法
下面的方法块按源码顺序生成。
public PacketType<ClientboundCommandSuggestionsPacket> type() @ L47
- 方法名:type
- 源码定位:L47
- 返回类型:PacketType
- 修饰符:public
参数:
- 无
说明:
TODO
public void handle(ClientGamePacketListener listener) @ L52
- 方法名:handle
- 源码定位:L52
- 返回类型:void
- 修饰符:public
参数:
- listener: ClientGamePacketListener
说明:
TODO
public Suggestions toSuggestions() @ L56
- 方法名:toSuggestions
- 源码定位:L56
- 返回类型:Suggestions
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public record ClientboundCommandSuggestionsPacket(int id, int start, int length, List<ClientboundCommandSuggestionsPacket.Entry> suggestions)
implements Packet<ClientGamePacketListener> {
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundCommandSuggestionsPacket> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.VAR_INT,
ClientboundCommandSuggestionsPacket::id,
ByteBufCodecs.VAR_INT,
ClientboundCommandSuggestionsPacket::start,
ByteBufCodecs.VAR_INT,
ClientboundCommandSuggestionsPacket::length,
ClientboundCommandSuggestionsPacket.Entry.STREAM_CODEC.apply(ByteBufCodecs.list()),
ClientboundCommandSuggestionsPacket::suggestions,
ClientboundCommandSuggestionsPacket::new
);
public ClientboundCommandSuggestionsPacket(int id, Suggestions suggestions) {
this(
id,
suggestions.getRange().getStart(),
suggestions.getRange().getLength(),
suggestions.getList()
.stream()
.map(
suggestion -> new ClientboundCommandSuggestionsPacket.Entry(
suggestion.getText(), Optional.ofNullable(suggestion.getTooltip()).map(ComponentUtils::fromMessage)
)
)
.toList()
);
}
@Override
public PacketType<ClientboundCommandSuggestionsPacket> type() {
return GamePacketTypes.CLIENTBOUND_COMMAND_SUGGESTIONS;
}
public void handle(ClientGamePacketListener listener) {
listener.handleCommandSuggestions(this);
}
public Suggestions toSuggestions() {
StringRange range = StringRange.between(this.start, this.start + this.length);
return new Suggestions(range, this.suggestions.stream().map(entry -> new Suggestion(range, entry.text(), entry.tooltip().orElse(null))).toList());
}
public record Entry(String text, Optional<Component> tooltip) {
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundCommandSuggestionsPacket.Entry> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.STRING_UTF8,
ClientboundCommandSuggestionsPacket.Entry::text,
ComponentSerialization.TRUSTED_OPTIONAL_STREAM_CODEC,
ClientboundCommandSuggestionsPacket.Entry::tooltip,
ClientboundCommandSuggestionsPacket.Entry::new
);
}
}引用的其他类
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ByteBufCodecs.list()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
StreamCodec.composite()
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置: