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
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 -
Method Summary
Modifier and TypeMethodDescriptioncom.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> A helper for defining a field of this type in a RecordCodecBuilder.<O> com.mojang.serialization.codecs.RecordCodecBuilder<O, T> A helper for defining a field of this type in a RecordCodecBuilder.com.mojang.serialization.Codec<T[]> getArray()Gets a codec that can read and write an array.<O> com.mojang.serialization.codecs.RecordCodecBuilder<O, T[]> A helper for defining a field for an array of this type in a RecordCodecBuilder.<O> com.mojang.serialization.codecs.RecordCodecBuilder<O, T[]> A helper for defining a field for an array of this type in a RecordCodecBuilder.getList()Gets a codec that can read and write a list.A helper for defining a field for a list of this type in a RecordCodecBuilder.A helper for defining a field for a list of this type in a RecordCodecBuilder.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.getOptional(String fieldName) Gets a codec that can read and write an optional value.getOptional(String fieldName, Function<O, Optional<T>> getter) A helper for defining a field for an optional value of this type in a RecordCodecBuilder.A helper for defining a field for an optional value of this type in a RecordCodecBuilder.getSet()Gets a codec that can read and write a set.A helper for defining a field for a set of this type in a RecordCodecBuilder.A helper for defining a field for a set of this type in a RecordCodecBuilder.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.
-
Constructor Details
-
MapCodecHelper
-
-
Method Details
-
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
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
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
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
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
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.
-