ClientboundChunksBiomesPacket.java
net.minecraft.network.protocol.game.ClientboundChunksBiomesPacket
信息
- 全限定名:net.minecraft.network.protocol.game.ClientboundChunksBiomesPacket
- 类型:public record
- 包:net.minecraft.network.protocol.game
- 源码路径:src/main/java/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
- 起始行号:L14
- 实现:Packet
- 职责:
TODO
字段/常量
-
STREAM_CODEC- 类型:
StreamCodec<FriendlyByteBuf,ClientboundChunksBiomesPacket> - 修饰符:
public static final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
TWO_MEGABYTES- 类型:
int - 修饰符:
private static final - 源码定位:
L18 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.network.protocol.game.ClientboundChunksBiomesPacket.ChunkBiomeData- 类型:
record - 修饰符:
public - 源码定位:
L41 - 说明:
TODO
- 类型:
构造器
private ClientboundChunksBiomesPacket(FriendlyByteBuf input) @ L20
- 构造器名:ClientboundChunksBiomesPacket
- 源码定位:L20
- 修饰符:private
参数:
- input: FriendlyByteBuf
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static ClientboundChunksBiomesPacket forChunks(List<LevelChunk> chunks) @ L24
- 方法名:forChunks
- 源码定位:L24
- 返回类型:ClientboundChunksBiomesPacket
- 修饰符:public static
参数:
- chunks: List
说明:
TODO
private void write(FriendlyByteBuf output) @ L28
- 方法名:write
- 源码定位:L28
- 返回类型:void
- 修饰符:private
参数:
- output: FriendlyByteBuf
说明:
TODO
public PacketType<ClientboundChunksBiomesPacket> type() @ L32
- 方法名:type
- 源码定位:L32
- 返回类型:PacketType
- 修饰符:public
参数:
- 无
说明:
TODO
public void handle(ClientGamePacketListener listener) @ L37
- 方法名:handle
- 源码定位:L37
- 返回类型:void
- 修饰符:public
参数:
- listener: ClientGamePacketListener
说明:
TODO
代码
public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.ChunkBiomeData> chunkBiomeData) implements Packet<ClientGamePacketListener> {
public static final StreamCodec<FriendlyByteBuf, ClientboundChunksBiomesPacket> STREAM_CODEC = Packet.codec(
ClientboundChunksBiomesPacket::write, ClientboundChunksBiomesPacket::new
);
private static final int TWO_MEGABYTES = 2097152;
private ClientboundChunksBiomesPacket(FriendlyByteBuf input) {
this(input.readList(ClientboundChunksBiomesPacket.ChunkBiomeData::new));
}
public static ClientboundChunksBiomesPacket forChunks(List<LevelChunk> chunks) {
return new ClientboundChunksBiomesPacket(chunks.stream().map(ClientboundChunksBiomesPacket.ChunkBiomeData::new).toList());
}
private void write(FriendlyByteBuf output) {
output.writeCollection(this.chunkBiomeData, (o, c) -> c.write(o));
}
@Override
public PacketType<ClientboundChunksBiomesPacket> type() {
return GamePacketTypes.CLIENTBOUND_CHUNKS_BIOMES;
}
public void handle(ClientGamePacketListener listener) {
listener.handleChunksBiomes(this);
}
public record ChunkBiomeData(ChunkPos pos, byte[] buffer) {
public ChunkBiomeData(LevelChunk chunk) {
this(chunk.getPos(), new byte[calculateChunkSize(chunk)]);
extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), chunk);
}
public ChunkBiomeData(FriendlyByteBuf input) {
this(input.readChunkPos(), input.readByteArray(2097152));
}
private static int calculateChunkSize(LevelChunk chunk) {
int total = 0;
for (LevelChunkSection section : chunk.getSections()) {
total += section.getBiomes().getSerializedSize();
}
return total;
}
public FriendlyByteBuf getReadBuffer() {
return new FriendlyByteBuf(Unpooled.wrappedBuffer(this.buffer));
}
private ByteBuf getWriteBuffer() {
ByteBuf buffer = Unpooled.wrappedBuffer(this.buffer);
buffer.writerIndex(0);
return buffer;
}
public static void extractChunkData(FriendlyByteBuf buffer, LevelChunk chunk) {
for (LevelChunkSection section : chunk.getSections()) {
section.getBiomes().write(buffer);
}
if (buffer.writerIndex() != buffer.capacity()) {
throw new IllegalStateException("Didn't fill biome buffer: expected " + buffer.capacity() + " bytes, got " + buffer.writerIndex());
}
}
public void write(FriendlyByteBuf output) {
output.writeChunkPos(this.pos);
output.writeByteArray(this.buffer);
}
}
}引用的其他类
-
- 引用位置:
参数/字段/构造调用 - 关联成员:
FriendlyByteBuf()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
实现/方法调用 - 关联成员:
Packet.codec()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: