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

    Constructors
    Constructor
    Description
    CodecHolder(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.PacketCodec<io.netty.buffer.ByteBuf,T> packetCodec)
    Creates an instance of a CodecHolder record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.mojang.serialization.Codec<T>
    Returns the value of the codec record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    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 the packetCodec record component.
    final String
    Returns a string representation of this record class.
    <U> CodecHolder<U>
    xmap(Function<? super T,? extends U> to, Function<? super U,? extends T> from)
    Transforms this CodecHolder<T> into a CodecHolder<U> by applying mapping functions to both the Codec and the PacketCodec.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 a CodecHolder record class.
      Parameters:
      codec - the value for the codec record component
      packetCodec - the value for the packetCodec record 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 this CodecHolder<T> into a CodecHolder<U> by applying mapping functions to both the Codec and the PacketCodec.

      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 type T to the new type U.
      from - A function that maps from the new type U back to the original type T.
      Returns:
      A new CodecHolder<U> with transformed codecs.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • codec

      public com.mojang.serialization.Codec<T> codec()
      Returns the value of the codec record component.
      Returns:
      the value of the codec record component
    • packetCodec

      public net.minecraft.network.codec.PacketCodec<io.netty.buffer.ByteBuf,T> packetCodec()
      Returns the value of the packetCodec record component.
      Returns:
      the value of the packetCodec record component