Class MapCodecs
java.lang.Object
net.darkhax.bookshelf.common.api.data.codecs.map.MapCodecs
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MapCodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier> static final MapCodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation> static final MapCodecHelper<net.minecraft.core.Direction.Axis> static final MapCodecHelper<net.minecraft.core.BlockPos> static final MapCodecHelper<net.minecraft.world.level.block.state.BlockState> static final MapCodecHelper<Boolean> static final MapCodecHelper<Byte> static final MapCodecHelper<net.minecraft.nbt.CompoundTag> static final MapCodecHelper<net.minecraft.world.Difficulty> static final MapCodecHelper<net.minecraft.core.Direction> static final MapCodecHelper<Double> static final MapCodecHelper<net.minecraft.world.item.DyeColor> static final MapCodecHelper<net.minecraft.world.effect.MobEffectInstance> static final MapCodecHelper<net.minecraft.world.entity.EquipmentSlot> static final MapCodecHelper<Float> static final MapCodecHelper<net.minecraft.world.item.crafting.Ingredient> static final MapCodecHelper<Integer> static final MapCodecHelper<net.minecraft.world.item.Rarity> static final MapCodecHelper<net.minecraft.world.item.ItemStack> static final MapCodecHelper<ILoadCondition> static final MapCodecHelper<Long> static final MapCodecHelper<net.minecraft.world.level.block.Mirror> static final MapCodecHelper<net.minecraft.world.entity.MobCategory> static final MapCodecHelper<net.minecraft.core.Direction.Plane> static final MapCodecHelper<net.minecraft.resources.Identifier> static final MapCodecHelper<net.minecraft.world.level.block.Rotation> static final MapCodecHelper<Short> static final MapCodecHelper<net.minecraft.sounds.SoundSource> static final MapCodecHelper<String> static final MapCodecHelper<net.minecraft.network.chat.Component> static final MapCodecHelper<UUID> static final MapCodecHelper<org.joml.Vector3fc> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Enum<T>>
com.mojang.serialization.Codec<T> enumerable(Class<T> enumClass) Creates a Codec that handles enum values by using their enum constant names.Creates a codec that will produce a set of enum values from an array of String values.static <T> com.mojang.serialization.MapCodec<T> Creates a Codec that will use a fallback value if no other value is specified.static <T> com.mojang.serialization.MapCodec<T> fallback(com.mojang.serialization.Codec<T> codec, String name, Supplier<T> fallbackSupplier, boolean writesDefault) Creates a Codec that will use a fallback value if no other value is specified.static <T> com.mojang.serialization.Codec<T[]> flexibleArray(com.mojang.serialization.Codec<T> codec, IntFunction<T[]> arrayBuilder) Creates a Codec that can flexibly read both individual values and arrays of values as an array.static <T> com.mojang.serialization.Codec<List<T>> flexibleList(com.mojang.serialization.Codec<T> codec) Creates a Codec that can flexibly read individual values as a list in addition to traditional lists.static <T> com.mojang.serialization.Codec<Set<T>> flexibleSet(com.mojang.serialization.Codec<T> codec) Creates a Codec that can flexibly read both individual values and arrays of values as a set.static <T> com.mojang.serialization.MapCodec<T> Creates a Codec that can handle nullable values.static <T> com.mojang.serialization.MapCodec<Optional<T>> optional(com.mojang.serialization.Codec<T> codec, String name, Optional<T> fallback, boolean writesDefault) Creates a Codec that handles optional values.static <T> com.mojang.serialization.Codec<T> xor(com.mojang.serialization.Codec<T> first, com.mojang.serialization.Codec<T> second) Creates a codec that will try two different codecs, using the first valid codec.
-
Field Details
-
BOOLEAN
-
BYTE
-
SHORT
-
INT
-
FLOAT
-
LONG
-
DOUBLE
-
STRING
-
UUID
-
ITEM_RARITY
-
ATTRIBUTE_OPERATION
public static final MapCodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation> ATTRIBUTE_OPERATION -
DIRECTION
-
AXIS
-
PLANE
-
MOB_CATEGORY
-
DYE_COLOR
-
SOUND_SOURCE
-
DIFFICULTY
-
EQUIPMENT_SLOT
-
MIRROR
-
ROTATION
-
RESOURCE_LOCATION
-
COMPOUND_TAG
-
ITEM_STACK
-
TEXT
-
BLOCK_POS
-
INGREDIENT
-
BLOCK_STATE_MAP_CODEC
public static final MapCodecHelper<net.minecraft.world.level.block.state.BlockState> BLOCK_STATE_MAP_CODEC -
ATTRIBUTE_MODIFIER
public static final MapCodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier> ATTRIBUTE_MODIFIER -
EFFECT_INSTANCE
-
VECTOR_3F
-
LOAD_CONDITION
-
-
Constructor Details
-
MapCodecs
public MapCodecs()
-
-
Method Details
-
flexibleList
public static <T> com.mojang.serialization.Codec<List<T>> flexibleList(com.mojang.serialization.Codec<T> codec) Creates a Codec that can flexibly read individual values as a list in addition to traditional lists.- Type Parameters:
T- The type of value handled by the codec.- Parameters:
codec- The codec for reading an individual value.- Returns:
- A Codec that can flexibly read individual values as a list in addition to traditional lists.
-
flexibleSet
public static <T> com.mojang.serialization.Codec<Set<T>> flexibleSet(com.mojang.serialization.Codec<T> codec) Creates a Codec that can flexibly read both individual values and arrays of values as a set.- Type Parameters:
T- The type of value handled by the codec.- Parameters:
codec- The Codec for reading an individual value.- Returns:
- A Codec that can flexibly read both individual values and arrays of values as a set.
-
flexibleArray
public static <T> com.mojang.serialization.Codec<T[]> flexibleArray(com.mojang.serialization.Codec<T> codec, IntFunction<T[]> arrayBuilder) Creates a Codec that can flexibly read both individual values and arrays of values as an array.- Type Parameters:
T- The type of value handled by the codec.- Parameters:
codec- The Codec for reading an individual value.arrayBuilder- A function that creates new arrays of the required type. The function is given the size of the list.- Returns:
- A Codec that can flexibly read both individual values and arrays of values as an array.
-
fallback
public static <T> com.mojang.serialization.MapCodec<T> fallback(com.mojang.serialization.Codec<T> codec, String name, Supplier<T> fallbackSupplier) Creates a Codec that will use a fallback value if no other value is specified. This is different fromCodec.optionalFieldOf(String, Object)in that the fallback value is provided by a supplier.- Type Parameters:
T- The type of value handled by the codec.- Parameters:
codec- The base Codec to use.name- The name of the field to read from.fallbackSupplier- A supplier that produces the default value. You should probably memoize this.- Returns:
- A Codec that will use a fallback value if the field is not specified.
-
optional
public static <T> com.mojang.serialization.MapCodec<Optional<T>> optional(com.mojang.serialization.Codec<T> codec, String name, Optional<T> fallback, boolean writesDefault) Creates a Codec that handles optional values. This is different fromCodec.optionalFieldOf(String, Object)in that it keeps the type as an Optional.- Type Parameters:
T- The type of the optional value handled by the coded.- Parameters:
codec- The base Codec to use.name- The name of the field to read from.fallback- The fallback optional value.writesDefault- Should the default value be written or left blank?- Returns:
- A Codec that handles optional values.
-
nullable
public static <T> com.mojang.serialization.MapCodec<T> nullable(com.mojang.serialization.Codec<T> codec, String fieldName) Creates a Codec that can handle nullable values.- Type Parameters:
T- The type of value handled by the codec.- Parameters:
codec- The base Codec to use.fieldName- The name of the field to read from.- Returns:
- A Codec that handles nullable values.
-
fallback
public static <T> com.mojang.serialization.MapCodec<T> fallback(com.mojang.serialization.Codec<T> codec, String name, Supplier<T> fallbackSupplier, boolean writesDefault) Creates a Codec that will use a fallback value if no other value is specified. This is different fromCodec.optionalFieldOf(String, Object)in that the fallback value is provided by a supplier. It also allows you to control if the default value should be written when or left blank.- Type Parameters:
T- The type of value handled by the codec.- Parameters:
codec- The base Codec to use.name- The name of the field to read from.fallbackSupplier- A supplier that produces the default value. You should probably memoize this.writesDefault- Should the default value be written or left blank?- Returns:
- A Codec that will use a fallback value if the field is not specified.
-
enumerable
Creates a Codec that handles enum values by using their enum constant names.
If the codec can not read an enum value from the provided name it will try again using an all uppercase version of the input. This allows users to write values in all lowercase which may feel more natural for some users and adds extra flexibility.
If the codec can not read any enum value from the provided name it will create an error. The error message will try to help the user by recommending a nearby match and including all possible values.- Type Parameters:
T- The type of the enum.- Parameters:
enumClass- The class of the enum to get values for.- Returns:
- A codec that can read and write enum values using their enum constant name.
-
enumSet
public static <T extends Enum<T>> com.mojang.serialization.Codec<EnumSet<T>> enumSet(Class<T> enumClass) Creates a codec that will produce a set of enum values from an array of String values.- Type Parameters:
T- The type of the enum.- Parameters:
enumClass- The type of enum to create a codec for.- Returns:
- The EnumSet codec.
-
xor
public static <T> com.mojang.serialization.Codec<T> xor(com.mojang.serialization.Codec<T> first, com.mojang.serialization.Codec<T> second) Creates a codec that will try two different codecs, using the first valid codec. Encoding will always use the first codec.- Type Parameters:
T- The type of codec to create.- Parameters:
first- The first codec to try when decoding. This will be the only codec used in encoding.second- The second codec to try when decoding.- Returns:
- A codec that will try two different codecs.
-