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[]> Gets a codec that can read and write an array.<O> com.mojang.serialization.codecs.RecordCodecBuilder<O, T[]> arrayCodec(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[]> arrayCodec(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<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.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> nullableCodec(String fieldName) Gets a codec that can read and write nullable values.<O> com.mojang.serialization.codecs.RecordCodecBuilder<O, T> nullableCodec(String fieldName, Function<O, T> getter) A helper for defining a field for a nullable value of this type in a RecordCodecBuilder.optionalCodec(String fieldName) Gets a codec that can read and write an optional value.optionalCodec(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.setCodec()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.
-
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.
-
arrayCodec
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.
-
arrayCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T[]> arrayCodec(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.
-
arrayCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T[]> arrayCodec(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.
-
listCodec
-
listCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>> listCodec(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.
-
listCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>> listCodec(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.
-
listCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,List<T>> listCodec(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.
-
setCodec
-
setCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>> setCodec(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.
-
setCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>> setCodec(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.
-
setCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,Set<T>> setCodec(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.
-
optionalCodec
-
optionalCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O, Optional<T>> optionalCodec(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.
-
optionalCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O, Optional<T>> optionalCodec(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.
-
nullableCodec
-
nullableCodec
public <O> com.mojang.serialization.codecs.RecordCodecBuilder<O,T> nullableCodec(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.
-