Record Class DataType<T>

java.lang.Object
java.lang.Record
dev.latvian.mods.klib.data.DataType<T>
All Implemented Interfaces:
ArgumentGetter<T>, CustomRegistryOwnTypeProvider<io.netty.buffer.ByteBuf, DataType<?>>, CustomRegistryValue<io.netty.buffer.ByteBuf, DataType<?>>, RefOptimizer<DataType<?>>, WithKey

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 CustomRegistryValue<io.netty.buffer.ByteBuf, DataType<?>>, ArgumentGetter<T>
  • Field Details

    • REGISTRY

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

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

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

      public static final DataType<Ref<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)
    • getRegistry

      public CustomRegistry<io.netty.buffer.ByteBuf, DataType<?>> getRegistry()
      Specified by:
      getRegistry in interface CustomRegistryValue<io.netty.buffer.ByteBuf, DataType<?>>
    • 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
    • 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