Record Class DataType<T>

java.lang.Object
java.lang.Record
dev.latvian.mods.klib.data.DataType<T>
All Implemented Interfaces:
ArgumentGetter<T>

public record DataType<T>(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec, List<Map.Entry<String,T>> enumValues, @Nullable DataType<?> componentType) extends Record implements ArgumentGetter<T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<DataType<?>>
     
    static final DataType<DataType<?>>
     
    static final CustomRegistry<io.netty.buffer.ByteBuf, DataType<?>>
     
    static final net.minecraft.network.codec.StreamCodec<io.netty.buffer.ByteBuf, DataType<?>>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataType(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec, List<Map.Entry<String,T>> enumValues, @Nullable DataType<?> componentType)
    Creates an instance of a DataType record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.mojang.brigadier.arguments.ArgumentType<?>
    argument(net.minecraft.commands.CommandBuildContext ctx)
     
    com.mojang.serialization.Codec<T>
    Returns the value of the codec record component.
    @Nullable DataType<?>
    Returns the value of the componentType record component.
    static <L,R> DataType<com.mojang.datafixers.util.Either<L,R>>
    either(DataType<L> left, DataType<R> right)
     
    static <T,L,R> DataType<T>
    either(DataType<L> left, DataType<R> right, Function<L,T> leftTo, Function<R,T> rightTo, Function<T, com.mojang.datafixers.util.Either<L,R>> from)
     
    Returns the value of the enumValues record component.
    boolean
    Indicates whether some other object is "equal to" this one.
    get(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> ctx, String name)
     
    int
    Returns a hash code value for this object.
    @Nullable net.minecraft.resources.ResourceKey<DataType<?>>
    key()
     
     
    static <T> DataType<T>
    of(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec)
     
    static <T> DataType<T>
    of(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec, List<Map.Entry<String,T>> enumValues)
     
    static <E> DataType<E>
    of(E[] values)
     
    static <E> DataType<E>
    of(E[] values, @Nullable NameProvider<E> nameProvider)
     
    static <T> DataType<net.minecraft.resources.ResourceKey<T>>
    of(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registry)
     
    net.minecraft.resources.ResourceKey<DataType<?>>
     
     
    net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T>
    Returns the value of the streamCodec record component.
    @Nullable Number
    toNumber(T value)
     
    Returns a string representation of this record class.
    static <C, T extends C>
    DataType<C>
    unit(T value)
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • REGISTRY

      public static final CustomRegistry<io.netty.buffer.ByteBuf, DataType<?>> REGISTRY
    • CODEC

      public static final com.mojang.serialization.Codec<DataType<?>> CODEC
    • STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<io.netty.buffer.ByteBuf, DataType<?>> STREAM_CODEC
    • DATA_TYPE

      public static final DataType<DataType<?>> DATA_TYPE
  • Constructor Details

    • DataType

      public DataType(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec, List<Map.Entry<String,T>> enumValues, @Nullable @Nullable DataType<?> componentType)
      Creates an instance of a DataType record class.
      Parameters:
      codec - the value for the codec record component
      streamCodec - the value for the streamCodec record component
      enumValues - the value for the enumValues record component
      componentType - the value for the componentType record component
  • Method Details

    • of

      public static <T> DataType<T> of(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec, List<Map.Entry<String,T>> enumValues)
    • of

      public static <T> DataType<T> of(com.mojang.serialization.Codec<T> codec, net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec)
    • of

      public static <E> DataType<E> of(E[] values, @Nullable @Nullable NameProvider<E> nameProvider)
    • of

      public static <E> DataType<E> of(E[] values)
    • of

      public static <T> DataType<net.minecraft.resources.ResourceKey<T>> of(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registry)
    • unit

      public static <C, T extends C> DataType<C> unit(T value)
    • either

      public static <L,R> DataType<com.mojang.datafixers.util.Either<L,R>> either(DataType<L> left, DataType<R> right)
    • either

      public static <T,L,R> DataType<T> either(DataType<L> left, DataType<R> right, Function<L,T> leftTo, Function<R,T> rightTo, Function<T, com.mojang.datafixers.util.Either<L,R>> from)
    • hashCode

      public 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 boolean equals(Object obj)
      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:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      public 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
    • key

      @Nullable public @Nullable net.minecraft.resources.ResourceKey<DataType<?>> key()
    • requireKey

      public net.minecraft.resources.ResourceKey<DataType<?>> requireKey()
    • listOf

      public DataType<List<T>> listOf()
    • setOf

      public DataType<Set<T>> setOf()
    • argument

      public com.mojang.brigadier.arguments.ArgumentType<?> argument(net.minecraft.commands.CommandBuildContext ctx)
    • get

      public T get(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> ctx, String name) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Specified by:
      get in interface ArgumentGetter<T>
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
    • toNumber

      @Nullable public @Nullable Number toNumber(T value)
    • codec

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

      public net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T> streamCodec()
      Returns the value of the streamCodec record component.
      Returns:
      the value of the streamCodec record component
    • enumValues

      public List<Map.Entry<String,T>> enumValues()
      Returns the value of the enumValues record component.
      Returns:
      the value of the enumValues record component
    • componentType

      @Nullable public @Nullable DataType<?> componentType()
      Returns the value of the componentType record component.
      Returns:
      the value of the componentType record component