ByteBufCodecs.java
net.minecraft.network.codec.ByteBufCodecs
信息
- 全限定名:net.minecraft.network.codec.ByteBufCodecs
- 类型:public interface
- 包:net.minecraft.network.codec
- 源码路径:src/main/java/net/minecraft/network/codec/ByteBufCodecs.java
- 起始行号:L54
- 职责:
TODO
字段/常量
-
MAX_INITIAL_COLLECTION_SIZE- 类型:
int - 修饰符:
package-private - 源码定位:
L55 - 说明:
TODO
- 类型:
-
BOOL- 类型:
StreamCodec<ByteBuf,Boolean> - 修饰符:
public public - 源码定位:
L56 - 说明:
TODO
- 类型:
-
BYTE- 类型:
StreamCodec<ByteBuf,Byte> - 修饰符:
public public - 源码定位:
L65 - 说明:
TODO
- 类型:
-
ROTATION_BYTE- 类型:
StreamCodec<ByteBuf,Float> - 修饰符:
package-private - 源码定位:
L74 - 说明:
TODO
- 类型:
-
SHORT- 类型:
StreamCodec<ByteBuf,Short> - 修饰符:
public public - 源码定位:
L75 - 说明:
TODO
- 类型:
-
UNSIGNED_SHORT- 类型:
StreamCodec<ByteBuf,Integer> - 修饰符:
public public - 源码定位:
L84 - 说明:
TODO
- 类型:
-
INT- 类型:
StreamCodec<ByteBuf,Integer> - 修饰符:
public public - 源码定位:
L93 - 说明:
TODO
- 类型:
-
VAR_INT- 类型:
StreamCodec<ByteBuf,Integer> - 修饰符:
public public - 源码定位:
L102 - 说明:
TODO
- 类型:
-
OPTIONAL_VAR_INT- 类型:
StreamCodec<ByteBuf,OptionalInt> - 修饰符:
package-private - 源码定位:
L111 - 说明:
TODO
- 类型:
-
LONG- 类型:
StreamCodec<ByteBuf,Long> - 修饰符:
public public - 源码定位:
L114 - 说明:
TODO
- 类型:
-
VAR_LONG- 类型:
StreamCodec<ByteBuf,Long> - 修饰符:
public public - 源码定位:
L123 - 说明:
TODO
- 类型:
-
FLOAT- 类型:
StreamCodec<ByteBuf,Float> - 修饰符:
public public - 源码定位:
L132 - 说明:
TODO
- 类型:
-
DOUBLE- 类型:
StreamCodec<ByteBuf,Double> - 修饰符:
public public - 源码定位:
L141 - 说明:
TODO
- 类型:
-
BYTE_ARRAY- 类型:
StreamCodec<ByteBuf,byte[]> - 修饰符:
public public - 源码定位:
L150 - 说明:
TODO
- 类型:
-
LONG_ARRAY- 类型:
StreamCodec<ByteBuf,long[]> - 修饰符:
public public - 源码定位:
L159 - 说明:
TODO
- 类型:
-
STRING_UTF8- 类型:
StreamCodec<ByteBuf,String> - 修饰符:
package-private - 源码定位:
L168 - 说明:
TODO
- 类型:
-
TAG- 类型:
StreamCodec<ByteBuf,Tag> - 修饰符:
package-private - 源码定位:
L169 - 说明:
TODO
- 类型:
-
TRUSTED_TAG- 类型:
StreamCodec<ByteBuf,Tag> - 修饰符:
package-private - 源码定位:
L170 - 说明:
TODO
- 类型:
-
COMPOUND_TAG- 类型:
StreamCodec<ByteBuf,CompoundTag> - 修饰符:
package-private - 源码定位:
L171 - 说明:
TODO
- 类型:
-
TRUSTED_COMPOUND_TAG- 类型:
StreamCodec<ByteBuf,CompoundTag> - 修饰符:
package-private - 源码定位:
L172 - 说明:
TODO
- 类型:
-
OPTIONAL_COMPOUND_TAG- 类型:
StreamCodec<ByteBuf,Optional<CompoundTag>> - 修饰符:
public public - 源码定位:
L173 - 说明:
TODO
- 类型:
-
VECTOR3F- 类型:
StreamCodec<ByteBuf,Vector3fc> - 修饰符:
public public - 源码定位:
L182 - 说明:
TODO
- 类型:
-
QUATERNIONF- 类型:
StreamCodec<ByteBuf,Quaternionfc> - 修饰符:
public public - 源码定位:
L191 - 说明:
TODO
- 类型:
-
CONTAINER_ID- 类型:
StreamCodec<ByteBuf,Integer> - 修饰符:
public public - 源码定位:
L200 - 说明:
TODO
- 类型:
-
GAME_PROFILE_PROPERTIES- 类型:
StreamCodec<ByteBuf,PropertyMap> - 修饰符:
public public - 源码定位:
L209 - 说明:
TODO
- 类型:
-
PLAYER_NAME- 类型:
StreamCodec<ByteBuf,String> - 修饰符:
package-private - 源码定位:
L235 - 说明:
TODO
- 类型:
-
GAME_PROFILE- 类型:
StreamCodec<ByteBuf,GameProfile> - 修饰符:
package-private - 源码定位:
L236 - 说明:
TODO
- 类型:
-
RGB_COLOR- 类型:
StreamCodec<ByteBuf,Integer> - 修饰符:
public public - 源码定位:
L239 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
static StreamCodec<ByteBuf,byte[]> byteArray(int maxSize) @ L251
- 方法名:byteArray
- 源码定位:L251
- 返回类型:StreamCodec<ByteBuf,byte[]>
- 修饰符:static
参数:
- maxSize: int
说明:
TODO
static StreamCodec<ByteBuf,String> stringUtf8(int maxStringLength) @ L267
- 方法名:stringUtf8
- 源码定位:L267
- 返回类型:StreamCodec<ByteBuf,String>
- 修饰符:static
参数:
- maxStringLength: int
说明:
TODO
static StreamCodec<ByteBuf,Optional<Tag>> optionalTagCodec(Supplier<NbtAccounter> accounter) @ L279
- 方法名:optionalTagCodec
- 源码定位:L279
- 返回类型:StreamCodec<ByteBuf,Optional
> - 修饰符:static
参数:
- accounter: Supplier
说明:
TODO
static StreamCodec<ByteBuf,Tag> tagCodec(Supplier<NbtAccounter> accounter) @ L291
- 方法名:tagCodec
- 源码定位:L291
- 返回类型:StreamCodec<ByteBuf,Tag>
- 修饰符:static
参数:
- accounter: Supplier
说明:
TODO
static StreamCodec<ByteBuf,CompoundTag> compoundTagCodec(Supplier<NbtAccounter> accounter) @ L312
- 方法名:compoundTagCodec
- 源码定位:L312
- 返回类型:StreamCodec<ByteBuf,CompoundTag>
- 修饰符:static
参数:
- accounter: Supplier
说明:
TODO
static <T> StreamCodec<ByteBuf,T> fromCodecTrusted(Codec<T> codec) @ L322
- 方法名:fromCodecTrusted
- 源码定位:L322
- 返回类型:
StreamCodec<ByteBuf,T> - 修饰符:static
参数:
- codec: Codec
说明:
TODO
static <T> StreamCodec<ByteBuf,T> fromCodec(Codec<T> codec) @ L326
- 方法名:fromCodec
- 源码定位:L326
- 返回类型:
StreamCodec<ByteBuf,T> - 修饰符:static
参数:
- codec: Codec
说明:
TODO
static <T,B extends ByteBuf,V> StreamCodec.CodecOperation<B,T,V> fromCodec(DynamicOps<T> ops, Codec<V> codec) @ L330
- 方法名:fromCodec
- 源码定位:L330
- 返回类型:<T,B extends ByteBuf,V> StreamCodec.CodecOperation<B,T,V>
- 修饰符:static
参数:
- ops: DynamicOps
- codec: Codec
说明:
TODO
static <T> StreamCodec<ByteBuf,T> fromCodec(Codec<T> codec, Supplier<NbtAccounter> accounter) @ L344
- 方法名:fromCodec
- 源码定位:L344
- 返回类型:
StreamCodec<ByteBuf,T> - 修饰符:static
参数:
- codec: Codec
- accounter: Supplier
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,T> fromCodecWithRegistriesTrusted(Codec<T> codec) @ L348
- 方法名:fromCodecWithRegistriesTrusted
- 源码定位:L348
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,T> - 修饰符:static
参数:
- codec: Codec
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,T> fromCodecWithRegistries(Codec<T> codec) @ L352
- 方法名:fromCodecWithRegistries
- 源码定位:L352
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,T> - 修饰符:static
参数:
- codec: Codec
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,T> fromCodecWithRegistries(Codec<T> codec, Supplier<NbtAccounter> accounter) @ L356
- 方法名:fromCodecWithRegistries
- 源码定位:L356
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,T> - 修饰符:static
参数:
- codec: Codec
- accounter: Supplier
说明:
TODO
static <B extends ByteBuf,V> StreamCodec<B,Optional<V>> optional(StreamCodec<?super B,V> original) @ L373
- 方法名:optional
- 源码定位:L373
- 返回类型:<B extends ByteBuf,V> StreamCodec<B,Optional
> - 修饰符:static
参数:
- original: StreamCodec<?super B,V>
说明:
TODO
static int readCount(ByteBuf input, int maxSize) @ L390
- 方法名:readCount
- 源码定位:L390
- 返回类型:int
- 修饰符:static
参数:
- input: ByteBuf
- maxSize: int
说明:
TODO
static void writeCount(ByteBuf output, int count, int maxSize) @ L399
- 方法名:writeCount
- 源码定位:L399
- 返回类型:void
- 修饰符:static
参数:
- output: ByteBuf
- count: int
- maxSize: int
说明:
TODO
static <B extends ByteBuf,V,C extends Collection<V>> StreamCodec<B,C> collection(IntFunction<C> constructor, StreamCodec<?super B,V> elementCodec) @ L407
- 方法名:collection
- 源码定位:L407
- 返回类型:<B extends ByteBuf,V,C extends Collection
> StreamCodec<B,C> - 修饰符:static
参数:
- constructor: IntFunction
- elementCodec: StreamCodec<?super B,V>
说明:
TODO
static <B extends ByteBuf,V,C extends Collection<V>> StreamCodec<B,C> collection(IntFunction<C> constructor, StreamCodec<?super B,V> elementCodec, int maxSize) @ L411
- 方法名:collection
- 源码定位:L411
- 返回类型:<B extends ByteBuf,V,C extends Collection
> StreamCodec<B,C> - 修饰符:static
参数:
- constructor: IntFunction
- elementCodec: StreamCodec<?super B,V>
- maxSize: int
说明:
TODO
static <B extends ByteBuf,V,C extends Collection<V>> StreamCodec.CodecOperation<B,V,C> collection(IntFunction<C> constructor) @ L436
- 方法名:collection
- 源码定位:L436
- 返回类型:<B extends ByteBuf,V,C extends Collection
> StreamCodec.CodecOperation<B,V,C> - 修饰符:static
参数:
- constructor: IntFunction
说明:
TODO
static <B extends ByteBuf,V> StreamCodec.CodecOperation<B,V,List<V>> list() @ L440
- 方法名:list
- 源码定位:L440
- 返回类型:<B extends ByteBuf,V> StreamCodec.CodecOperation<B,V,List
> - 修饰符:static
参数:
- 无
说明:
TODO
static <B extends ByteBuf,V> StreamCodec.CodecOperation<B,V,List<V>> list(int maxSize) @ L444
- 方法名:list
- 源码定位:L444
- 返回类型:<B extends ByteBuf,V> StreamCodec.CodecOperation<B,V,List
> - 修饰符:static
参数:
- maxSize: int
说明:
TODO
static <B extends ByteBuf,K,V,M extends Map<K,V>> StreamCodec<B,M> map(IntFunction<?extends M> constructor, StreamCodec<?super B,K> keyCodec, StreamCodec<?super B,V> valueCodec) @ L448
- 方法名:map
- 源码定位:L448
- 返回类型:<B extends ByteBuf,K,V,M extends Map<K,V>> StreamCodec<B,M>
- 修饰符:static
参数:
- constructor: IntFunction<?extends M>
- keyCodec: StreamCodec<?super B,K>
- valueCodec: StreamCodec<?super B,V>
说明:
TODO
static <B extends ByteBuf,K,V,M extends Map<K,V>> StreamCodec<B,M> map(IntFunction<?extends M> constructor, StreamCodec<?super B,K> keyCodec, StreamCodec<?super B,V> valueCodec, int maxSize) @ L454
- 方法名:map
- 源码定位:L454
- 返回类型:<B extends ByteBuf,K,V,M extends Map<K,V>> StreamCodec<B,M>
- 修饰符:static
参数:
- constructor: IntFunction<?extends M>
- keyCodec: StreamCodec<?super B,K>
- valueCodec: StreamCodec<?super B,V>
- maxSize: int
说明:
TODO
static <B extends ByteBuf,L,R> StreamCodec<B,Either<L,R>> either(StreamCodec<?super B,L> leftCodec, StreamCodec<?super B,R> rightCodec) @ L481
- 方法名:either
- 源码定位:L481
- 返回类型:<B extends ByteBuf,L,R> StreamCodec<B,Either<L,R>>
- 修饰符:static
参数:
- leftCodec: StreamCodec<?super B,L>
- rightCodec: StreamCodec<?super B,R>
说明:
TODO
static <B extends ByteBuf,V> StreamCodec.CodecOperation<B,V,V> lengthPrefixed(int maxSize, BiFunction<B,ByteBuf,B> decorator) @ L499
- 方法名:lengthPrefixed
- 源码定位:L499
- 返回类型:<B extends ByteBuf,V> StreamCodec.CodecOperation<B,V,V>
- 修饰符:static
参数:
- maxSize: int
- decorator: BiFunction<B,ByteBuf,B>
说明:
TODO
static <V> StreamCodec.CodecOperation<ByteBuf,V,V> lengthPrefixed(int maxSize) @ L532
- 方法名:lengthPrefixed
- 源码定位:L532
- 返回类型:
StreamCodec.CodecOperation<ByteBuf,V,V> - 修饰符:static
参数:
- maxSize: int
说明:
TODO
static <V> StreamCodec.CodecOperation<RegistryFriendlyByteBuf,V,V> registryFriendlyLengthPrefixed(int maxSize) @ L536
- 方法名:registryFriendlyLengthPrefixed
- 源码定位:L536
- 返回类型:
StreamCodec.CodecOperation<RegistryFriendlyByteBuf,V,V> - 修饰符:static
参数:
- maxSize: int
说明:
TODO
static <T> StreamCodec<ByteBuf,T> idMapper(IntFunction<T> byId, ToIntFunction<T> toId) @ L540
- 方法名:idMapper
- 源码定位:L540
- 返回类型:
StreamCodec<ByteBuf,T> - 修饰符:static
参数:
- byId: IntFunction
- toId: ToIntFunction
说明:
TODO
static <T> StreamCodec<ByteBuf,T> idMapper(IdMap<T> mapper) @ L554
- 方法名:idMapper
- 源码定位:L554
- 返回类型:
StreamCodec<ByteBuf,T> - 修饰符:static
参数:
- mapper: IdMap
说明:
TODO
private static <T,R> StreamCodec<RegistryFriendlyByteBuf,R> registry(ResourceKey<?extends Registry<T>> registryKey, Function<Registry<T>,IdMap<R>> mapExtractor) @ L558
- 方法名:registry
- 源码定位:L558
- 返回类型:<T,R> StreamCodec<RegistryFriendlyByteBuf,R>
- 修饰符:private static
参数:
- registryKey: ResourceKey<?extends Registry
> - mapExtractor: Function<Registry
,IdMap >
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,T> registry(ResourceKey<?extends Registry<T>> registryKey) @ L578
- 方法名:registry
- 源码定位:L578
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,T> - 修饰符:static
参数:
- registryKey: ResourceKey<?extends Registry
>
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,Holder<T>> holderRegistry(ResourceKey<?extends Registry<T>> registryKey) @ L582
- 方法名:holderRegistry
- 源码定位:L582
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,Holder > - 修饰符:static
参数:
- registryKey: ResourceKey<?extends Registry
>
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,Holder<T>> holder(ResourceKey<?extends Registry<T>> registryKey, StreamCodec<?super RegistryFriendlyByteBuf,T> directCodec) @ L586
- 方法名:holder
- 源码定位:L586
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,Holder > - 修饰符:static
参数:
- registryKey: ResourceKey<?extends Registry
> - directCodec: StreamCodec<?super RegistryFriendlyByteBuf,T>
说明:
TODO
static <T> StreamCodec<RegistryFriendlyByteBuf,HolderSet<T>> holderSet(ResourceKey<?extends Registry<T>> registryKey) @ L615
- 方法名:holderSet
- 源码定位:L615
- 返回类型:
StreamCodec<RegistryFriendlyByteBuf,HolderSet > - 修饰符:static
参数:
- registryKey: ResourceKey<?extends Registry
>
说明:
TODO
static StreamCodec<ByteBuf,JsonElement> lenientJson(int maxStringLength) @ L652
- 方法名:lenientJson
- 源码定位:L652
- 返回类型:StreamCodec<ByteBuf,JsonElement>
- 修饰符:static
参数:
- maxStringLength: int
说明:
TODO
代码
public interface ByteBufCodecs {
int MAX_INITIAL_COLLECTION_SIZE = 65536;
StreamCodec<ByteBuf, Boolean> BOOL = new StreamCodec<ByteBuf, Boolean>() {
public Boolean decode(ByteBuf input) {
return input.readBoolean();
}
public void encode(ByteBuf output, Boolean value) {
output.writeBoolean(value);
}
};
StreamCodec<ByteBuf, Byte> BYTE = new StreamCodec<ByteBuf, Byte>() {
public Byte decode(ByteBuf input) {
return input.readByte();
}
public void encode(ByteBuf output, Byte value) {
output.writeByte(value);
}
};
StreamCodec<ByteBuf, Float> ROTATION_BYTE = BYTE.map(Mth::unpackDegrees, Mth::packDegrees);
StreamCodec<ByteBuf, Short> SHORT = new StreamCodec<ByteBuf, Short>() {
public Short decode(ByteBuf input) {
return input.readShort();
}
public void encode(ByteBuf output, Short value) {
output.writeShort(value);
}
};
StreamCodec<ByteBuf, Integer> UNSIGNED_SHORT = new StreamCodec<ByteBuf, Integer>() {
public Integer decode(ByteBuf input) {
return input.readUnsignedShort();
}
public void encode(ByteBuf output, Integer value) {
output.writeShort(value);
}
};
StreamCodec<ByteBuf, Integer> INT = new StreamCodec<ByteBuf, Integer>() {
public Integer decode(ByteBuf input) {
return input.readInt();
}
public void encode(ByteBuf output, Integer value) {
output.writeInt(value);
}
};
StreamCodec<ByteBuf, Integer> VAR_INT = new StreamCodec<ByteBuf, Integer>() {
public Integer decode(ByteBuf input) {
return VarInt.read(input);
}
public void encode(ByteBuf output, Integer value) {
VarInt.write(output, value);
}
};
StreamCodec<ByteBuf, OptionalInt> OPTIONAL_VAR_INT = VAR_INT.map(
i -> i == 0 ? OptionalInt.empty() : OptionalInt.of(i - 1), o -> o.isPresent() ? o.getAsInt() + 1 : 0
);
StreamCodec<ByteBuf, Long> LONG = new StreamCodec<ByteBuf, Long>() {
public Long decode(ByteBuf input) {
return input.readLong();
}
public void encode(ByteBuf output, Long value) {
output.writeLong(value);
}
};
StreamCodec<ByteBuf, Long> VAR_LONG = new StreamCodec<ByteBuf, Long>() {
public Long decode(ByteBuf input) {
return VarLong.read(input);
}
public void encode(ByteBuf output, Long value) {
VarLong.write(output, value);
}
};
StreamCodec<ByteBuf, Float> FLOAT = new StreamCodec<ByteBuf, Float>() {
public Float decode(ByteBuf input) {
return input.readFloat();
}
public void encode(ByteBuf output, Float value) {
output.writeFloat(value);
}
};
StreamCodec<ByteBuf, Double> DOUBLE = new StreamCodec<ByteBuf, Double>() {
public Double decode(ByteBuf input) {
return input.readDouble();
}
public void encode(ByteBuf output, Double value) {
output.writeDouble(value);
}
};
StreamCodec<ByteBuf, byte[]> BYTE_ARRAY = new StreamCodec<ByteBuf, byte[]>() {
public byte[] decode(ByteBuf input) {
return FriendlyByteBuf.readByteArray(input);
}
public void encode(ByteBuf output, byte[] value) {
FriendlyByteBuf.writeByteArray(output, value);
}
};
StreamCodec<ByteBuf, long[]> LONG_ARRAY = new StreamCodec<ByteBuf, long[]>() {
public long[] decode(ByteBuf input) {
return FriendlyByteBuf.readLongArray(input);
}
public void encode(ByteBuf output, long[] value) {
FriendlyByteBuf.writeLongArray(output, value);
}
};
StreamCodec<ByteBuf, String> STRING_UTF8 = stringUtf8(32767);
StreamCodec<ByteBuf, Tag> TAG = tagCodec(NbtAccounter::defaultQuota);
StreamCodec<ByteBuf, Tag> TRUSTED_TAG = tagCodec(NbtAccounter::unlimitedHeap);
StreamCodec<ByteBuf, CompoundTag> COMPOUND_TAG = compoundTagCodec(NbtAccounter::defaultQuota);
StreamCodec<ByteBuf, CompoundTag> TRUSTED_COMPOUND_TAG = compoundTagCodec(NbtAccounter::unlimitedHeap);
StreamCodec<ByteBuf, Optional<CompoundTag>> OPTIONAL_COMPOUND_TAG = new StreamCodec<ByteBuf, Optional<CompoundTag>>() {
public Optional<CompoundTag> decode(ByteBuf input) {
return Optional.ofNullable(FriendlyByteBuf.readNbt(input));
}
public void encode(ByteBuf output, Optional<CompoundTag> value) {
FriendlyByteBuf.writeNbt(output, value.orElse(null));
}
};
StreamCodec<ByteBuf, Vector3fc> VECTOR3F = new StreamCodec<ByteBuf, Vector3fc>() {
public Vector3fc decode(ByteBuf input) {
return FriendlyByteBuf.readVector3f(input);
}
public void encode(ByteBuf output, Vector3fc value) {
FriendlyByteBuf.writeVector3f(output, value);
}
};
StreamCodec<ByteBuf, Quaternionfc> QUATERNIONF = new StreamCodec<ByteBuf, Quaternionfc>() {
public Quaternionfc decode(ByteBuf input) {
return FriendlyByteBuf.readQuaternion(input);
}
public void encode(ByteBuf output, Quaternionfc value) {
FriendlyByteBuf.writeQuaternion(output, value);
}
};
StreamCodec<ByteBuf, Integer> CONTAINER_ID = new StreamCodec<ByteBuf, Integer>() {
public Integer decode(ByteBuf input) {
return FriendlyByteBuf.readContainerId(input);
}
public void encode(ByteBuf output, Integer value) {
FriendlyByteBuf.writeContainerId(output, value);
}
};
StreamCodec<ByteBuf, PropertyMap> GAME_PROFILE_PROPERTIES = new StreamCodec<ByteBuf, PropertyMap>() {
public PropertyMap decode(ByteBuf input) {
int propertyCount = ByteBufCodecs.readCount(input, 16);
Builder<String, Property> result = ImmutableMultimap.builder();
for (int i = 0; i < propertyCount; i++) {
String name = Utf8String.read(input, 64);
String value = Utf8String.read(input, 32767);
String signature = FriendlyByteBuf.readNullable(input, in -> Utf8String.read(in, 1024));
Property property = new Property(name, value, signature);
result.put(property.name(), property);
}
return new PropertyMap(result.build());
}
public void encode(ByteBuf output, PropertyMap properties) {
ByteBufCodecs.writeCount(output, properties.size(), 16);
for (Property property : properties.values()) {
Utf8String.write(output, property.name(), 64);
Utf8String.write(output, property.value(), 32767);
FriendlyByteBuf.writeNullable(output, property.signature(), (out, signature) -> Utf8String.write(out, signature, 1024));
}
}
};
StreamCodec<ByteBuf, String> PLAYER_NAME = stringUtf8(16);
StreamCodec<ByteBuf, GameProfile> GAME_PROFILE = StreamCodec.composite(
UUIDUtil.STREAM_CODEC, GameProfile::id, PLAYER_NAME, GameProfile::name, GAME_PROFILE_PROPERTIES, GameProfile::properties, GameProfile::new
);
StreamCodec<ByteBuf, Integer> RGB_COLOR = new StreamCodec<ByteBuf, Integer>() {
public Integer decode(ByteBuf input) {
return ARGB.color(input.readByte() & 0xFF, input.readByte() & 0xFF, input.readByte() & 0xFF);
}
public void encode(ByteBuf output, Integer value) {
output.writeByte(ARGB.red(value));
output.writeByte(ARGB.green(value));
output.writeByte(ARGB.blue(value));
}
};
static StreamCodec<ByteBuf, byte[]> byteArray(int maxSize) {
return new StreamCodec<ByteBuf, byte[]>() {
public byte[] decode(ByteBuf input) {
return FriendlyByteBuf.readByteArray(input, maxSize);
}
public void encode(ByteBuf output, byte[] value) {
if (value.length > maxSize) {
throw new EncoderException("ByteArray with size " + value.length + " is bigger than allowed " + maxSize);
} else {
FriendlyByteBuf.writeByteArray(output, value);
}
}
};
}
static StreamCodec<ByteBuf, String> stringUtf8(int maxStringLength) {
return new StreamCodec<ByteBuf, String>() {
public String decode(ByteBuf input) {
return Utf8String.read(input, maxStringLength);
}
public void encode(ByteBuf output, String value) {
Utf8String.write(output, value, maxStringLength);
}
};
}
static StreamCodec<ByteBuf, Optional<Tag>> optionalTagCodec(Supplier<NbtAccounter> accounter) {
return new StreamCodec<ByteBuf, Optional<Tag>>() {
public Optional<Tag> decode(ByteBuf input) {
return Optional.ofNullable(FriendlyByteBuf.readNbt(input, accounter.get()));
}
public void encode(ByteBuf output, Optional<Tag> value) {
FriendlyByteBuf.writeNbt(output, value.orElse(null));
}
};
}
static StreamCodec<ByteBuf, Tag> tagCodec(Supplier<NbtAccounter> accounter) {
return new StreamCodec<ByteBuf, Tag>() {
public Tag decode(ByteBuf input) {
Tag result = FriendlyByteBuf.readNbt(input, accounter.get());
if (result == null) {
throw new DecoderException("Expected non-null compound tag");
} else {
return result;
}
}
public void encode(ByteBuf output, Tag value) {
if (value == EndTag.INSTANCE) {
throw new EncoderException("Expected non-null compound tag");
} else {
FriendlyByteBuf.writeNbt(output, value);
}
}
};
}
static StreamCodec<ByteBuf, CompoundTag> compoundTagCodec(Supplier<NbtAccounter> accounter) {
return tagCodec(accounter).map(tag -> {
if (tag instanceof CompoundTag compoundTag) {
return compoundTag;
} else {
throw new DecoderException("Not a compound tag: " + tag);
}
}, compoundTag -> (Tag)compoundTag);
}
static <T> StreamCodec<ByteBuf, T> fromCodecTrusted(Codec<T> codec) {
return fromCodec(codec, NbtAccounter::unlimitedHeap);
}
static <T> StreamCodec<ByteBuf, T> fromCodec(Codec<T> codec) {
return fromCodec(codec, NbtAccounter::defaultQuota);
}
static <T, B extends ByteBuf, V> StreamCodec.CodecOperation<B, T, V> fromCodec(DynamicOps<T> ops, Codec<V> codec) {
return original -> new StreamCodec<B, V>() {
public V decode(B input) {
T payload = (T)original.decode(input);
return (V)codec.parse(ops, payload).getOrThrow(msg -> new DecoderException("Failed to decode: " + msg + " " + payload));
}
public void encode(B output, V value) {
T payload = (T)codec.encodeStart(ops, value).getOrThrow(msg -> new EncoderException("Failed to encode: " + msg + " " + value));
original.encode(output, payload);
}
};
}
static <T> StreamCodec<ByteBuf, T> fromCodec(Codec<T> codec, Supplier<NbtAccounter> accounter) {
return tagCodec(accounter).apply(fromCodec(NbtOps.INSTANCE, codec));
}
static <T> StreamCodec<RegistryFriendlyByteBuf, T> fromCodecWithRegistriesTrusted(Codec<T> codec) {
return fromCodecWithRegistries(codec, NbtAccounter::unlimitedHeap);
}
static <T> StreamCodec<RegistryFriendlyByteBuf, T> fromCodecWithRegistries(Codec<T> codec) {
return fromCodecWithRegistries(codec, NbtAccounter::defaultQuota);
}
static <T> StreamCodec<RegistryFriendlyByteBuf, T> fromCodecWithRegistries(Codec<T> codec, Supplier<NbtAccounter> accounter) {
final StreamCodec<ByteBuf, Tag> tagCodec = tagCodec(accounter);
return new StreamCodec<RegistryFriendlyByteBuf, T>() {
public T decode(RegistryFriendlyByteBuf input) {
Tag tag = tagCodec.decode(input);
RegistryOps<Tag> ops = input.registryAccess().createSerializationContext(NbtOps.INSTANCE);
return codec.parse(ops, tag).getOrThrow(msg -> new DecoderException("Failed to decode: " + msg + " " + tag));
}
public void encode(RegistryFriendlyByteBuf output, T value) {
RegistryOps<Tag> ops = output.registryAccess().createSerializationContext(NbtOps.INSTANCE);
Tag tag = codec.encodeStart(ops, value).getOrThrow(msg -> new EncoderException("Failed to encode: " + msg + " " + value));
tagCodec.encode(output, tag);
}
};
}
static <B extends ByteBuf, V> StreamCodec<B, Optional<V>> optional(StreamCodec<? super B, V> original) {
return new StreamCodec<B, Optional<V>>() {
public Optional<V> decode(B input) {
return input.readBoolean() ? Optional.of(original.decode(input)) : Optional.empty();
}
public void encode(B output, Optional<V> value) {
if (value.isPresent()) {
output.writeBoolean(true);
original.encode(output, value.get());
} else {
output.writeBoolean(false);
}
}
};
}
static int readCount(ByteBuf input, int maxSize) {
int count = VarInt.read(input);
if (count > maxSize) {
throw new DecoderException(count + " elements exceeded max size of: " + maxSize);
} else {
return count;
}
}
static void writeCount(ByteBuf output, int count, int maxSize) {
if (count > maxSize) {
throw new EncoderException(count + " elements exceeded max size of: " + maxSize);
} else {
VarInt.write(output, count);
}
}
static <B extends ByteBuf, V, C extends Collection<V>> StreamCodec<B, C> collection(IntFunction<C> constructor, StreamCodec<? super B, V> elementCodec) {
return collection(constructor, elementCodec, Integer.MAX_VALUE);
}
static <B extends ByteBuf, V, C extends Collection<V>> StreamCodec<B, C> collection(
IntFunction<C> constructor, StreamCodec<? super B, V> elementCodec, int maxSize
) {
return new StreamCodec<B, C>() {
public C decode(B input) {
int count = ByteBufCodecs.readCount(input, maxSize);
C result = constructor.apply(Math.min(count, 65536));
for (int i = 0; i < count; i++) {
result.add(elementCodec.decode(input));
}
return result;
}
public void encode(B output, C value) {
ByteBufCodecs.writeCount(output, value.size(), maxSize);
for (V element : value) {
elementCodec.encode(output, element);
}
}
};
}
static <B extends ByteBuf, V, C extends Collection<V>> StreamCodec.CodecOperation<B, V, C> collection(IntFunction<C> constructor) {
return original -> collection(constructor, original);
}
static <B extends ByteBuf, V> StreamCodec.CodecOperation<B, V, List<V>> list() {
return original -> collection(ArrayList::new, original);
}
static <B extends ByteBuf, V> StreamCodec.CodecOperation<B, V, List<V>> list(int maxSize) {
return original -> collection(ArrayList::new, original, maxSize);
}
static <B extends ByteBuf, K, V, M extends Map<K, V>> StreamCodec<B, M> map(
IntFunction<? extends M> constructor, StreamCodec<? super B, K> keyCodec, StreamCodec<? super B, V> valueCodec
) {
return map(constructor, keyCodec, valueCodec, Integer.MAX_VALUE);
}
static <B extends ByteBuf, K, V, M extends Map<K, V>> StreamCodec<B, M> map(
IntFunction<? extends M> constructor, StreamCodec<? super B, K> keyCodec, StreamCodec<? super B, V> valueCodec, int maxSize
) {
return new StreamCodec<B, M>() {
public void encode(B output, M map) {
ByteBufCodecs.writeCount(output, map.size(), maxSize);
map.forEach((k, v) -> {
keyCodec.encode(output, (K)k);
valueCodec.encode(output, (V)v);
});
}
public M decode(B input) {
int count = ByteBufCodecs.readCount(input, maxSize);
M result = (M)constructor.apply(Math.min(count, 65536));
for (int i = 0; i < count; i++) {
K key = keyCodec.decode(input);
V value = valueCodec.decode(input);
result.put(key, value);
}
return result;
}
};
}
static <B extends ByteBuf, L, R> StreamCodec<B, Either<L, R>> either(StreamCodec<? super B, L> leftCodec, StreamCodec<? super B, R> rightCodec) {
return new StreamCodec<B, Either<L, R>>() {
public Either<L, R> decode(B input) {
return input.readBoolean() ? Either.left(leftCodec.decode(input)) : Either.right(rightCodec.decode(input));
}
public void encode(B output, Either<L, R> value) {
value.ifLeft(left -> {
output.writeBoolean(true);
leftCodec.encode(output, (L)left);
}).ifRight(right -> {
output.writeBoolean(false);
rightCodec.encode(output, (R)right);
});
}
};
}
static <B extends ByteBuf, V> StreamCodec.CodecOperation<B, V, V> lengthPrefixed(int maxSize, BiFunction<B, ByteBuf, B> decorator) {
return original -> new StreamCodec<B, V>() {
public V decode(B input) {
int size = VarInt.read(input);
if (size > maxSize) {
throw new DecoderException("Buffer size " + size + " is larger than allowed limit of " + maxSize);
} else {
int index = input.readerIndex();
B limitedSlice = (B)((ByteBuf)decorator.apply(input, input.slice(index, size)));
input.readerIndex(index + size);
return (V)original.decode(limitedSlice);
}
}
public void encode(B output, V value) {
B scratchBuffer = (B)((ByteBuf)decorator.apply(output, output.alloc().buffer()));
try {
original.encode(scratchBuffer, value);
int size = scratchBuffer.readableBytes();
if (size > maxSize) {
throw new EncoderException("Buffer size " + size + " is larger than allowed limit of " + maxSize);
}
VarInt.write(output, size);
output.writeBytes(scratchBuffer);
} finally {
scratchBuffer.release();
}
}
};
}
static <V> StreamCodec.CodecOperation<ByteBuf, V, V> lengthPrefixed(int maxSize) {
return lengthPrefixed(maxSize, (parent, child) -> child);
}
static <V> StreamCodec.CodecOperation<RegistryFriendlyByteBuf, V, V> registryFriendlyLengthPrefixed(int maxSize) {
return lengthPrefixed(maxSize, (parent, child) -> new RegistryFriendlyByteBuf(child, parent.registryAccess()));
}
static <T> StreamCodec<ByteBuf, T> idMapper(IntFunction<T> byId, ToIntFunction<T> toId) {
return new StreamCodec<ByteBuf, T>() {
public T decode(ByteBuf input) {
int id = VarInt.read(input);
return byId.apply(id);
}
public void encode(ByteBuf output, T value) {
int id = toId.applyAsInt(value);
VarInt.write(output, id);
}
};
}
static <T> StreamCodec<ByteBuf, T> idMapper(IdMap<T> mapper) {
return idMapper(mapper::byIdOrThrow, mapper::getIdOrThrow);
}
private static <T, R> StreamCodec<RegistryFriendlyByteBuf, R> registry(
ResourceKey<? extends Registry<T>> registryKey, Function<Registry<T>, IdMap<R>> mapExtractor
) {
return new StreamCodec<RegistryFriendlyByteBuf, R>() {
private IdMap<R> getRegistryOrThrow(RegistryFriendlyByteBuf input) {
return mapExtractor.apply(input.registryAccess().lookupOrThrow(registryKey));
}
public R decode(RegistryFriendlyByteBuf input) {
int id = VarInt.read(input);
return (R)this.getRegistryOrThrow(input).byIdOrThrow(id);
}
public void encode(RegistryFriendlyByteBuf output, R value) {
int id = this.getRegistryOrThrow(output).getIdOrThrow(value);
VarInt.write(output, id);
}
};
}
static <T> StreamCodec<RegistryFriendlyByteBuf, T> registry(ResourceKey<? extends Registry<T>> registryKey) {
return registry(registryKey, r -> r);
}
static <T> StreamCodec<RegistryFriendlyByteBuf, Holder<T>> holderRegistry(ResourceKey<? extends Registry<T>> registryKey) {
return registry(registryKey, Registry::asHolderIdMap);
}
static <T> StreamCodec<RegistryFriendlyByteBuf, Holder<T>> holder(
ResourceKey<? extends Registry<T>> registryKey, StreamCodec<? super RegistryFriendlyByteBuf, T> directCodec
) {
return new StreamCodec<RegistryFriendlyByteBuf, Holder<T>>() {
private static final int DIRECT_HOLDER_ID = 0;
private IdMap<Holder<T>> getRegistryOrThrow(RegistryFriendlyByteBuf input) {
return input.registryAccess().lookupOrThrow(registryKey).asHolderIdMap();
}
public Holder<T> decode(RegistryFriendlyByteBuf input) {
int id = VarInt.read(input);
return id == 0 ? Holder.direct(directCodec.decode(input)) : (Holder)this.getRegistryOrThrow(input).byIdOrThrow(id - 1);
}
public void encode(RegistryFriendlyByteBuf output, Holder<T> holder) {
switch (holder.kind()) {
case REFERENCE:
int id = this.getRegistryOrThrow(output).getIdOrThrow(holder);
VarInt.write(output, id + 1);
break;
case DIRECT:
VarInt.write(output, 0);
directCodec.encode(output, holder.value());
}
}
};
}
static <T> StreamCodec<RegistryFriendlyByteBuf, HolderSet<T>> holderSet(ResourceKey<? extends Registry<T>> registryKey) {
return new StreamCodec<RegistryFriendlyByteBuf, HolderSet<T>>() {
private static final int NAMED_SET = -1;
private final StreamCodec<RegistryFriendlyByteBuf, Holder<T>> holderCodec = ByteBufCodecs.holderRegistry(registryKey);
public HolderSet<T> decode(RegistryFriendlyByteBuf input) {
int count = VarInt.read(input) - 1;
if (count == -1) {
Registry<T> registry = input.registryAccess().lookupOrThrow(registryKey);
return registry.get(TagKey.create(registryKey, Identifier.STREAM_CODEC.decode(input))).orElseThrow();
} else {
List<Holder<T>> holders = new ArrayList<>(Math.min(count, 65536));
for (int i = 0; i < count; i++) {
holders.add(this.holderCodec.decode(input));
}
return HolderSet.direct(holders);
}
}
public void encode(RegistryFriendlyByteBuf output, HolderSet<T> value) {
Optional<TagKey<T>> key = value.unwrapKey();
if (key.isPresent()) {
VarInt.write(output, 0);
Identifier.STREAM_CODEC.encode(output, key.get().location());
} else {
VarInt.write(output, value.size() + 1);
for (Holder<T> holder : value) {
this.holderCodec.encode(output, holder);
}
}
}
};
}
static StreamCodec<ByteBuf, JsonElement> lenientJson(int maxStringLength) {
return new StreamCodec<ByteBuf, JsonElement>() {
private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
public JsonElement decode(ByteBuf input) {
String payload = Utf8String.read(input, maxStringLength);
try {
return LenientJsonParser.parse(payload);
} catch (JsonSyntaxException var4) {
throw new DecoderException("Failed to parse JSON", var4);
}
}
public void encode(ByteBuf output, JsonElement value) {
String payload = GSON.toJson(value);
Utf8String.write(output, payload, maxStringLength);
}
};
}
}引用的其他类
-
- 引用位置:
方法调用/返回值 - 关联成员:
Holder.direct()
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
HolderSet.direct()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FriendlyByteBuf.readByteArray(), FriendlyByteBuf.readContainerId(), FriendlyByteBuf.readLongArray(), FriendlyByteBuf.readNbt(), FriendlyByteBuf.readNullable(), FriendlyByteBuf.readQuaternion(), FriendlyByteBuf.readVector3f(), FriendlyByteBuf.writeByteArray(), FriendlyByteBuf.writeContainerId(), FriendlyByteBuf.writeLongArray(), FriendlyByteBuf.writeNbt(), FriendlyByteBuf.writeNullable(), FriendlyByteBuf.writeQuaternion(), FriendlyByteBuf.writeVector3f()
- 引用位置:
-
- 引用位置:
参数/构造调用/返回值 - 关联成员:
RegistryFriendlyByteBuf()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Utf8String.read(), Utf8String.write()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
VarInt.read(), VarInt.write()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
VarLong.read(), VarLong.write()
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
StreamCodec.composite()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TagKey.create()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.blue(), ARGB.color(), ARGB.green(), ARGB.red()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LenientJsonParser.parse()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
Property()
- 引用位置: