Class MapCodecHelper<T>

java.lang.Object
net.darkhax.bookshelf.common.api.data.codecs.map.MapCodecHelper<T>
Type Parameters:
T - The type handled by the codec helper.
Direct Known Subclasses:
RegistryMapCodecHelper

public class MapCodecHelper<T> extends Object
A CodecHelper wraps a Codec to provide a large amount of helpers and utilities to make working with the Codec easier and more flexible.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MapCodecHelper(com.mojang.serialization.Codec<T> elementCodec, T... vargs)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.mojang.serialization.Codec<T>
    get()
    Gets a codec that can read and write single instances of the element.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T>
    get(String fieldName, Function<O,T> getter)
    A helper for defining a field of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T>
    get(String fieldName, Function<O,T> getter, T fallback)
    A helper for defining a field of this type in a RecordCodecBuilder.
    com.mojang.serialization.Codec<T[]>
    Gets a codec that can read and write an array.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T[]>
    getArray(String fieldName, Function<O,T[]> getter)
    A helper for defining a field for an array of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T[]>
    getArray(String fieldName, Function<O,T[]> getter, T... fallback)
    A helper for defining a field for an array of this type in a RecordCodecBuilder.
    com.mojang.serialization.Codec<List<T>>
    Gets a codec that can read and write a list.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>>
    getList(String fieldName, Function<O,List<T>> getter)
    A helper for defining a field for a list of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>>
    getList(String fieldName, Function<O,List<T>> getter, List<T> fallback)
    A helper for defining a field for a list of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>>
    getList(String fieldName, Function<O,List<T>> getter, T... fallback)
    A helper for defining a field for a list of this type in a RecordCodecBuilder.
    com.mojang.serialization.MapCodec<T>
    getNullable(String fieldName)
    Gets a codec that can read and write nullable values.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T>
    getNullable(String fieldName, Function<O,T> getter)
    A helper for defining a field for a nullable value of this type in a RecordCodecBuilder.
    com.mojang.serialization.MapCodec<Optional<T>>
    getOptional(String fieldName)
    Gets a codec that can read and write an optional value.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Optional<T>>
    getOptional(String fieldName, Function<O,Optional<T>> getter)
    A helper for defining a field for an optional value of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Optional<T>>
    getOptional(String fieldName, Function<O,Optional<T>> getter, Optional<T> fallback)
    A helper for defining a field for an optional value of this type in a RecordCodecBuilder.
    com.mojang.serialization.Codec<Set<T>>
    Gets a codec that can read and write a set.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>>
    getSet(String fieldName, Function<O,Set<T>> getter)
    A helper for defining a field for a set of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>>
    getSet(String fieldName, Function<O,Set<T>> getter, Set<T> fallback)
    A helper for defining a field for a set of this type in a RecordCodecBuilder.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>>
    getSet(String fieldName, Function<O,Set<T>> getter, T... fallback)
    A helper for defining a field for a set of this type in a RecordCodecBuilder.
    com.mojang.serialization.Codec<net.minecraft.util.random.WeightedEntry.Wrapper<T>>
    Gets a codec that can read and write a weighted entry.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,net.minecraft.util.random.WeightedEntry.Wrapper<T>>
    getWeighted(String fieldName, Function<O,net.minecraft.util.random.WeightedEntry.Wrapper<T>> getter)
    A helper for defining a field for a weighted entry of this type in a RecordCodecBuilder.
    com.mojang.serialization.Codec<net.minecraft.util.random.SimpleWeightedRandomList<T>>
    Gets a codec that can read and write a weighted list.
    <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,net.minecraft.util.random.SimpleWeightedRandomList<T>>
    getWeightedList(String fieldName, Function<O,net.minecraft.util.random.SimpleWeightedRandomList<T>> getter)
    A helper for defining a field for a weighted list of this type in a RecordCodecBuilder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MapCodecHelper

      @SafeVarargs public MapCodecHelper(com.mojang.serialization.Codec<T> elementCodec, T... vargs)
  • Method Details

    • get

      public com.mojang.serialization.Codec<T> get()
      Gets a codec that can read and write single instances of the element.
      Returns:
      A Codec that can read and write single instances of the element.
    • get

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T> get(String fieldName, Function<O,T> getter)
      A helper for defining a field of this type in a RecordCodecBuilder.
      Type Parameters:
      O - The type of the RecordCodecBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field.
    • get

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T> get(String fieldName, Function<O,T> getter, T fallback)
      A helper for defining a field of this type in a RecordCodecBuilder. If the field is not present the fallback value will be used.
      Type Parameters:
      O - The type of the RecordCodecBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field of the helpers type with a fallback value.
    • getArray

      public com.mojang.serialization.Codec<T[]> getArray()
      Gets a codec that can read and write an array. For the sake of convenience single elements are treated as an array of one.
      Returns:
      A Codec that can read and write an array.
    • getArray

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T[]> getArray(String fieldName, Function<O,T[]> getter)
      A helper for defining a field for an array of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as an array of one.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for an array.
    • getArray

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T[]> getArray(String fieldName, Function<O,T[]> getter, T... fallback)
      A helper for defining a field for an array of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as an array of one. If the field is not present the fallback will be used.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field for an array.
    • getList

      public com.mojang.serialization.Codec<List<T>> getList()
      Gets a codec that can read and write a list. For the sake of convenience single elements are treated as a list of one.
      Returns:
      A Codec that can read and write a list.
    • getList

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>> getList(String fieldName, Function<O,List<T>> getter)
      A helper for defining a field for a list of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as a list of one.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for a list.
    • getList

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>> getList(String fieldName, Function<O,List<T>> getter, List<T> fallback)
      A helper for defining a field for a list of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as a list of one. If the field is not present the fallback will be used.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field for a list.
    • getList

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>> getList(String fieldName, Function<O,List<T>> getter, T... fallback)
      A helper for defining a field for a list of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as a list of one. If the field is not present the fallback will be used.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field for a list.
    • getSet

      public com.mojang.serialization.Codec<Set<T>> getSet()
      Gets a codec that can read and write a set. For the sake of convenience single elements are treated as a list of one.
      Returns:
      A Codec that can read and write a set.
    • getSet

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>> getSet(String fieldName, Function<O,Set<T>> getter)
      A helper for defining a field for a set of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as a set of one.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for a set.
    • getSet

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>> getSet(String fieldName, Function<O,Set<T>> getter, Set<T> fallback)
      A helper for defining a field for a set of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as a set of one. If the field is not present the fallback will be used.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field for a set.
    • getSet

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>> getSet(String fieldName, Function<O,Set<T>> getter, T... fallback)
      A helper for defining a field for a set of this type in a RecordCodecBuilder. For the sake of convenience single elements are treated as a set of one. If the field is not present the fallback will be used.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field for a set.
    • getOptional

      public com.mojang.serialization.MapCodec<Optional<T>> getOptional(String fieldName)
      Gets a codec that can read and write an optional value.
      Parameters:
      fieldName - The name of the field to read the value from.
      Returns:
      A Codec that can read and write an optional value.
    • getOptional

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Optional<T>> getOptional(String fieldName, Function<O,Optional<T>> getter)
      A helper for defining a field for an optional value of this type in a RecordCodecBuilder.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for an optional value.
    • getOptional

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Optional<T>> getOptional(String fieldName, Function<O,Optional<T>> getter, Optional<T> fallback)
      A helper for defining a field for an optional value of this type in a RecordCodecBuilder. If the field is not present the fallback will be used.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      fallback - The fallback value to use when the field is not present.
      Returns:
      A RecordCodecBuilder that represents a field for an optional value.
    • getNullable

      public com.mojang.serialization.MapCodec<T> getNullable(String fieldName)
      Gets a codec that can read and write nullable values.
      Parameters:
      fieldName - The name of the field to read the value from.
      Returns:
      A Codec that can read and write nullable values.
    • getNullable

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T> getNullable(String fieldName, Function<O,T> getter)
      A helper for defining a field for a nullable value of this type in a RecordCodecBuilder.
      Type Parameters:
      O - The type of the RecordCodedBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for a nullable value.
    • getWeighted

      public com.mojang.serialization.Codec<net.minecraft.util.random.WeightedEntry.Wrapper<T>> getWeighted()
      Gets a codec that can read and write a weighted entry.
      Returns:
      A Codec that can read and write a weighted entry.
    • getWeighted

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,net.minecraft.util.random.WeightedEntry.Wrapper<T>> getWeighted(String fieldName, Function<O,net.minecraft.util.random.WeightedEntry.Wrapper<T>> getter)
      A helper for defining a field for a weighted entry of this type in a RecordCodecBuilder.
      Type Parameters:
      O - The type of the RecordCodecBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for a weighted entry.
    • getWeightedList

      public com.mojang.serialization.Codec<net.minecraft.util.random.SimpleWeightedRandomList<T>> getWeightedList()
      Gets a codec that can read and write a weighted list.
      Returns:
      A Codec that can read and write a weighted list.
    • getWeightedList

      public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,net.minecraft.util.random.SimpleWeightedRandomList<T>> getWeightedList(String fieldName, Function<O,net.minecraft.util.random.SimpleWeightedRandomList<T>> getter)
      A helper for defining a field for a weighted list of this type in a RecordCodecBuilder.
      Type Parameters:
      O - The type of the RecordCodecBuilder.
      Parameters:
      fieldName - The name of the field to read the value from.
      getter - A getter that will read the value from an object of the RecordCodecBuilders type.
      Returns:
      A RecordCodecBuilder that represents a field for a weighted list.