Record Class CodecHolder<T>
java.lang.Object
java.lang.Record
dev.scsupercraft.mc.libraries.corelib.api.serialization.CodecHolder<T>
- Type Parameters:
T- The class that the codecs are for.- Record Components:
codec- A codec for serializing data.packetCodec- A packet codec for serializing data.
@AvailableSince("1.0.0")
public record CodecHolder<T>(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.PacketCodec<io.netty.buffer.ByteBuf,T> packetCodec)
extends Record
A record containing both a codec and a packet codec.
-
Constructor Summary
ConstructorsConstructorDescriptionCodecHolder(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.PacketCodec<io.netty.buffer.ByteBuf, T> packetCodec) Creates an instance of aCodecHolderrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncom.mojang.serialization.Codec<T> codec()Returns the value of thecodecrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static <T> CodecHolder<T> of(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.PacketCodec<? extends io.netty.buffer.ByteBuf, T> packetCodec) Creates a new codec holder.net.minecraft.network.codec.PacketCodec<io.netty.buffer.ByteBuf, T> Returns the value of thepacketCodecrecord component.final StringtoString()Returns a string representation of this record class.<U> CodecHolder<U> Transforms thisCodecHolder<T>into aCodecHolder<U>by applying mapping functions to both theCodecand thePacketCodec.
-
Constructor Details
-
CodecHolder
public CodecHolder(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.PacketCodec<io.netty.buffer.ByteBuf, T> packetCodec) Creates an instance of aCodecHolderrecord class.- Parameters:
codec- the value for thecodecrecord componentpacketCodec- the value for thepacketCodecrecord component
-
-
Method Details
-
of
@AvailableSince("1.0.0") public static <T> CodecHolder<T> of(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.PacketCodec<? extends io.netty.buffer.ByteBuf, T> packetCodec) Creates a new codec holder.- Type Parameters:
T- The class that the codecs are for.- Parameters:
codec- A codec for serializing data.packetCodec- A packet codec for serializing data.- Returns:
- A new codec holder.
-
xmap
@AvailableSince("1.0.0") public <U> CodecHolder<U> xmap(Function<? super T, ? extends U> to, Function<? super U, ? extends T> from) Transforms thisCodecHolder<T>into aCodecHolder<U>by applying mapping functions to both theCodecand thePacketCodec.This is useful when you want to adapt the underlying serialization logic to a different type without creating new codecs from scratch.
- Type Parameters:
U- The target type to transform the codecs to.- Parameters:
to- A function that maps from the original typeTto the new typeU.from- A function that maps from the new typeUback to the original typeT.- Returns:
- A new
CodecHolder<U>with transformed codecs.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
codec
Returns the value of thecodecrecord component.- Returns:
- the value of the
codecrecord component
-
packetCodec
Returns the value of thepacketCodecrecord component.- Returns:
- the value of the
packetCodecrecord component
-