Class PayloadCodecs
java.lang.Object
net.ixdarklord.coolcatcore.api.network.PayloadCodecs
Stream codecs found by type, so a record payload needs no hand-written
StreamCodec: each record component is
encoded in declaration order with the codec of its declared type.
Out of the box: primitives and their boxes, String, UUID, ResourceLocation, BlockPos,
ChunkPos, GlobalPos, Vec3, Vector3f(c), Quaternionf(c), Component,
ItemStack (may be empty), CompoundTag, Tag, BlockState, Item, Block,
EntityType, OptionalInt, byte[], long[], plus, built from their parts:
enums (by ordinal), records, arrays, Optional, List/Collection, Set, Map,
Either and ResourceKey.
Any other type must be registered before a payload using it is registered; registering such a
payload throws otherwise. Components may not be null: use Optional.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceBuilds the codec of a generic type from its type arguments.static interfaceResolves the codecs of type arguments inside aPayloadCodecs.Factory. -
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends Record>
net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, R> The codec of a record, derived from its components.static net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, ?> The codec of any supported type, such asString.classor aParameterizedTypefrom reflection.static booleanWhetherget(java.lang.reflect.Type)would find a codec for the type.static <V> voidregister(Class<V> type, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, V> codec) Makestypeusable in record payloads.static voidregisterFactory(Class<?> rawType, PayloadCodecs.Factory factory) Makes a generic type usable in record payloads, e.g.
-
Method Details
-
register
public static <V> void register(Class<V> type, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, V> codec) Makestypeusable in record payloads. A type can only be registered once. -
registerFactory
Makes a generic type usable in record payloads, e.g. a container whose codec depends on its type arguments. The factory receives the type arguments as declared (e.g.[String, Integer]forPair<String, Integer>) and resolves the codecs it needs through thePayloadCodecs.Lookup. -
forRecord
public static <R extends Record> net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,R> forRecord(Class<R> recordClass) The codec of a record, derived from its components.- Throws:
IllegalArgumentException- if a component's type (at any depth) has no codec
-
get
public static net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,?> get(Type type) The codec of any supported type, such asString.classor aParameterizedTypefrom reflection.- Throws:
IllegalArgumentException- if the type, or a type it's built from, has no codec
-
has
Whetherget(java.lang.reflect.Type)would find a codec for the type.
-