Class BookshelfCodecs
java.lang.Object
net.darkhax.bookshelf.api.data.codecs.BookshelfCodecs
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RegistryCodecHelper<net.minecraft.world.entity.schedule.Activity>static final RegistryCodecHelper<net.minecraft.commands.synchronization.ArgumentTypeInfo<?,?>> static final CodecHelper<net.minecraft.world.item.ArmorMaterials>static final RegistryCodecHelper<net.minecraft.world.entity.ai.attributes.Attribute>static final CodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier>static final CodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation>static final CodecHelper<net.minecraft.core.Direction.Axis>static final RegistryCodecHelper<net.minecraft.world.level.block.entity.BannerPattern>static final RegistryCodecHelper<net.minecraft.world.level.block.Block>static final RegistryCodecHelper<net.minecraft.world.level.block.entity.BlockEntityType<?>>static final CodecHelper<net.minecraft.core.BlockPos>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.blockpredicates.BlockPredicateType<?>>static final CodecHelper<net.minecraft.world.level.block.state.BlockState>static final com.mojang.serialization.MapCodec<net.minecraft.world.level.block.state.BlockState>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType<?>>static final CodecHelper<Boolean>static final CodecHelper<Byte>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.carver.WorldCarver<?>>static final RegistryCodecHelper<net.minecraft.world.entity.animal.CatVariant>static final RegistryCodecHelper<net.minecraft.world.level.chunk.ChunkStatus>static final CodecHelper<net.minecraft.nbt.CompoundTag>static final RegistryCodecHelper<net.minecraft.world.item.CreativeModeTab>static final RegistryCodecHelper<net.minecraft.resources.ResourceLocation>static final RegistryCodecHelper<String>static final CodecHelper<net.minecraft.world.Difficulty>static final CodecHelper<net.minecraft.core.Direction>static final CodecHelper<Double>static final CodecHelper<net.minecraft.world.item.DyeColor>static final CodecHelper<net.minecraft.world.effect.MobEffectInstance>static final CodecHelper<net.minecraft.world.effect.MobEffectInstance>static final RegistryCodecHelper<net.minecraft.world.item.enchantment.Enchantment>static final CodecHelper<net.minecraft.world.item.enchantment.EnchantmentCategory>static final CodecHelper<net.minecraft.world.item.enchantment.EnchantmentInstance>static final CodecHelper<net.minecraft.world.item.enchantment.Enchantment.Rarity>static final RegistryCodecHelper<net.minecraft.world.entity.EntityType<?>>static final CodecHelper<net.minecraft.world.entity.EquipmentSlot>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.Feature<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.featuresize.FeatureSizeType<?>>static final CodecHelper<Float>static final RegistryCodecHelper<net.minecraft.util.valueproviders.FloatProviderType<?>>static final RegistryCodecHelper<net.minecraft.world.level.material.Fluid>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType<?>>static final RegistryCodecHelper<net.minecraft.world.entity.animal.FrogVariant>static final RegistryCodecHelper<net.minecraft.world.level.gameevent.GameEvent>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.heightproviders.HeightProviderType<?>>static final CodecHelper<net.minecraft.world.item.crafting.Ingredient>static final CodecHelper<net.minecraft.world.item.crafting.Ingredient>static final RegistryCodecHelper<net.minecraft.world.item.Instrument>static final CodecHelper<Integer>static final RegistryCodecHelper<net.minecraft.util.valueproviders.IntProviderType<?>>static final RegistryCodecHelper<net.minecraft.world.item.Item>static final CodecHelper<net.minecraft.world.item.Rarity>static final CodecHelper<net.minecraft.world.item.ItemStack>static final CodecHelper<net.minecraft.world.item.ItemStack>static CodecHelper<ILoadCondition>static final CodecHelper<Long>static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.predicates.LootItemConditionType>static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.functions.LootItemFunctionType>static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.providers.nbt.LootNbtProviderType>static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.providers.number.LootNumberProviderType>static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.entries.LootPoolEntryType>static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.providers.score.LootScoreProviderType>static final RegistryCodecHelper<net.minecraft.world.entity.ai.memory.MemoryModuleType<?>>static final RegistryCodecHelper<net.minecraft.world.inventory.MenuType<?>>static final CodecHelper<net.minecraft.world.level.block.Mirror>static final CodecHelper<net.minecraft.world.entity.MobCategory>static final RegistryCodecHelper<net.minecraft.world.effect.MobEffect>static final RegistryCodecHelper<net.minecraft.world.entity.decoration.PaintingVariant>static final RegistryCodecHelper<net.minecraft.core.particles.ParticleType<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.placement.PlacementModifierType<?>>static final CodecHelper<net.minecraft.core.Direction.Plane>static final RegistryCodecHelper<net.minecraft.world.entity.ai.village.poi.PoiType>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.PosRuleTestType<?>>static final RegistryCodecHelper<net.minecraft.world.level.gameevent.PositionSourceType<?>>static final RegistryCodecHelper<net.minecraft.world.item.alchemy.Potion>static final RegistryCodecHelper<net.minecraft.world.item.crafting.RecipeSerializer<?>>static final RegistryCodecHelper<net.minecraft.world.item.crafting.RecipeType<?>>static final CodecHelper<net.minecraft.resources.ResourceLocation>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.rootplacers.RootPlacerType<?>>static final CodecHelper<net.minecraft.world.level.block.Rotation>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.rule.blockentity.RuleBlockEntityModifierType<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.RuleTestType<?>>static final RegistryCodecHelper<net.minecraft.world.entity.schedule.Schedule>static final RegistryCodecHelper<net.minecraft.world.entity.ai.sensing.SensorType<?>>static final CodecHelper<Short>static CodecHelper<Sound>static final RegistryCodecHelper<net.minecraft.sounds.SoundEvent>static final CodecHelper<net.minecraft.sounds.SoundSource>static final RegistryCodecHelper<net.minecraft.stats.StatType<?>>static final CodecHelper<String>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.placement.StructurePlacementType<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.pools.StructurePoolElementType<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.StructureType<?>>static final CodecHelper<net.minecraft.network.chat.Component>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType<?>>static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType<?>>static final CodecHelper<UUID>static CodecHelper<org.joml.Vector3f>static final RegistryCodecHelper<net.minecraft.world.entity.npc.VillagerProfession>static final RegistryCodecHelper<net.minecraft.world.entity.npc.VillagerType> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> com.mojang.serialization.Codec<T>alternatives(com.mojang.serialization.Codec<T> first, com.mojang.serialization.Codec<T> second, Function<T, com.mojang.datafixers.util.Either<T, T>> encodeLogic) static <T,V> com.mojang.serialization.Codec<V> dispatchFallback(com.mojang.serialization.Codec<T> typeCodec, Function<V, T> getSerializer, Function<T, com.mojang.serialization.Codec<V>> getCodec, Supplier<com.mojang.serialization.Codec<V>> fallbackCodec) Creates a dispatch codec that will deserialize a value based on the serializer type defined by an optional property.static <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.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>registry(net.minecraft.core.Registry<T> registry) Creates a codec for a registry that will error when no value can be found rather than passing a default value like air.
-
Field Details
-
BOOLEAN
-
BYTE
-
SHORT
-
INT
-
FLOAT
-
LONG
-
DOUBLE
-
STRING
-
UUID
-
GAME_EVENT
-
SOUND_EVENT
-
FLUID
-
MOB_EFFECT
-
BLOCK
-
ENCHANTMENT
public static final RegistryCodecHelper<net.minecraft.world.item.enchantment.Enchantment> ENCHANTMENT -
ENTITY_TYPE
-
ITEM
-
POTION
-
PARTICLE_TYPE
-
BLOCK_ENTITY_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.block.entity.BlockEntityType<?>> BLOCK_ENTITY_TYPE -
PAINTING_VARIANT
public static final RegistryCodecHelper<net.minecraft.world.entity.decoration.PaintingVariant> PAINTING_VARIANT -
CUSTOM_STAT
-
CHUNK_STATUS
-
RULE_TEST
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.RuleTestType<?>> RULE_TEST -
RULE_BLOCK_ENTITY_MODIFIER
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.rule.blockentity.RuleBlockEntityModifierType<?>> RULE_BLOCK_ENTITY_MODIFIER -
POS_RULE_TEST
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.PosRuleTestType<?>> POS_RULE_TEST -
MENU
-
RECIPE_TYPE
public static final RegistryCodecHelper<net.minecraft.world.item.crafting.RecipeType<?>> RECIPE_TYPE -
RECIPE_SERIALIZER
public static final RegistryCodecHelper<net.minecraft.world.item.crafting.RecipeSerializer<?>> RECIPE_SERIALIZER -
ATTRIBUTE
public static final RegistryCodecHelper<net.minecraft.world.entity.ai.attributes.Attribute> ATTRIBUTE -
POSITION_SOURCE_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.gameevent.PositionSourceType<?>> POSITION_SOURCE_TYPE -
ARGUMENT_TYPE_INFO_CODEC_HELPER
public static final RegistryCodecHelper<net.minecraft.commands.synchronization.ArgumentTypeInfo<?,?>> ARGUMENT_TYPE_INFO_CODEC_HELPER -
STAT_TYPE
-
VILLAGER_TYPE
-
VILLAGER_PROFESSION
public static final RegistryCodecHelper<net.minecraft.world.entity.npc.VillagerProfession> VILLAGER_PROFESSION -
POINT_OF_INTEREST_TYPE
public static final RegistryCodecHelper<net.minecraft.world.entity.ai.village.poi.PoiType> POINT_OF_INTEREST_TYPE -
MEMORY_MODULE_TYPE
public static final RegistryCodecHelper<net.minecraft.world.entity.ai.memory.MemoryModuleType<?>> MEMORY_MODULE_TYPE -
SENSOR_TYPE
public static final RegistryCodecHelper<net.minecraft.world.entity.ai.sensing.SensorType<?>> SENSOR_TYPE -
SCHEDULE
-
ACTIVITY
-
LOOT_POOL_ENTRY_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.entries.LootPoolEntryType> LOOT_POOL_ENTRY_TYPE -
LOOT_FUNCTION_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.functions.LootItemFunctionType> LOOT_FUNCTION_TYPE -
LOOT_CONDITION_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.predicates.LootItemConditionType> LOOT_CONDITION_TYPE -
LOOT_NUMBER_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.providers.number.LootNumberProviderType> LOOT_NUMBER_PROVIDER_TYPE -
LOOT_NBT_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.providers.nbt.LootNbtProviderType> LOOT_NBT_PROVIDER_TYPE -
LOOT_SCORE_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.storage.loot.providers.score.LootScoreProviderType> LOOT_SCORE_PROVIDER_TYPE -
FLOAT_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.util.valueproviders.FloatProviderType<?>> FLOAT_PROVIDER_TYPE -
INT_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.util.valueproviders.IntProviderType<?>> INT_PROVIDER_TYPE -
HEIGHT_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.heightproviders.HeightProviderType<?>> HEIGHT_PROVIDER_TYPE -
BLOCK_PREDICATE_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.blockpredicates.BlockPredicateType<?>> BLOCK_PREDICATE_TYPE -
CARVER
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.carver.WorldCarver<?>> CARVER -
FEATURE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.Feature<?>> FEATURE -
STRUCTURE_PLACEMENT
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.placement.StructurePlacementType<?>> STRUCTURE_PLACEMENT -
STRUCTURE_PIECE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType> STRUCTURE_PIECE -
STRUCTURE_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.StructureType<?>> STRUCTURE_TYPE -
PLACEMENT_MODIFIER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.placement.PlacementModifierType<?>> PLACEMENT_MODIFIER_TYPE -
BLOCKSTATE_PROVIDER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType<?>> BLOCKSTATE_PROVIDER_TYPE -
FOLIAGE_PLACER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType<?>> FOLIAGE_PLACER_TYPE -
TRUNK_PLACER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType<?>> TRUNK_PLACER_TYPE -
ROOT_PLACER_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.rootplacers.RootPlacerType<?>> ROOT_PLACER_TYPE -
TREE_DECORATOR_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType<?>> TREE_DECORATOR_TYPE -
FEATURE_SIZE_TYPE
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.feature.featuresize.FeatureSizeType<?>> FEATURE_SIZE_TYPE -
STRUCTURE_PROCESSOR
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType<?>> STRUCTURE_PROCESSOR -
STRUCTURE_POOL_ELEMENT
public static final RegistryCodecHelper<net.minecraft.world.level.levelgen.structure.pools.StructurePoolElementType<?>> STRUCTURE_POOL_ELEMENT -
CAT_VARIANT
-
FROG_VARIANT
-
BANNER_PATTERN
public static final RegistryCodecHelper<net.minecraft.world.level.block.entity.BannerPattern> BANNER_PATTERN -
INSTRUMENT
-
DECORATED_POT_PATTERNS
-
CREATIVE_MODE_TAB
-
ITEM_RARITY
-
ENCHANTMENT_RARITY
public static final CodecHelper<net.minecraft.world.item.enchantment.Enchantment.Rarity> ENCHANTMENT_RARITY -
ATTRIBUTE_OPERATION
public static final CodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation> ATTRIBUTE_OPERATION -
DIRECTION
-
AXIS
-
PLANE
-
MOB_CATEGORY
-
ENCHANTMENT_CATEGORY
public static final CodecHelper<net.minecraft.world.item.enchantment.EnchantmentCategory> ENCHANTMENT_CATEGORY -
DYE_COLOR
-
SOUND_SOURCE
-
ARMOR_MATERIAL
-
DIFFICULTY
-
EQUIPMENT_SLOT
-
MIRROR
-
ROTATION
-
RESOURCE_LOCATION
-
COMPOUND_TAG
-
ITEM_STACK
-
ITEM_STACK_FLEXIBLE
-
TEXT
-
BLOCK_POS
-
INGREDIENT
-
INGREDIENT_NONEMPTY
-
BLOCK_STATE_MAP_CODEC
public static final com.mojang.serialization.MapCodec<net.minecraft.world.level.block.state.BlockState> BLOCK_STATE_MAP_CODEC -
BLOCK_STATE
-
ATTRIBUTE_MODIFIER
public static final CodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier> ATTRIBUTE_MODIFIER -
EFFECT_INSTANCE
-
EFFECT_INSTANCE_WITH_HIDDEN
public static final CodecHelper<net.minecraft.world.effect.MobEffectInstance> EFFECT_INSTANCE_WITH_HIDDEN -
ENCHANTMENT_INSTANCE
public static final CodecHelper<net.minecraft.world.item.enchantment.EnchantmentInstance> ENCHANTMENT_INSTANCE -
VECTOR_3F
-
LOAD_CONDITION
-
SOUND
-
-
Constructor Details
-
BookshelfCodecs
public BookshelfCodecs()
-
-
Method Details
-
registry
public static <T> com.mojang.serialization.Codec<T> registry(net.minecraft.core.Registry<T> registry) Creates a codec for a registry that will error when no value can be found rather than passing a default value like air.- Type Parameters:
T- The registry type.- Parameters:
registry- The registry to read values from.- Returns:
- A Codec for finding registry values by name.
-
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.
-
dispatchFallback
public static <T,V> com.mojang.serialization.Codec<V> dispatchFallback(com.mojang.serialization.Codec<T> typeCodec, Function<V, T> getSerializer, Function<T, com.mojang.serialization.Codec<V>> getCodec, Supplier<com.mojang.serialization.Codec<V>> fallbackCodec) Creates a dispatch codec that will deserialize a value based on the serializer type defined by an optional property. If the type property is not provided the fallbackCodec will be used instead. This is similar to the recipe codec that can read crafting, smelting, stone cutting, and smithing table recipes.- Type Parameters:
T- The type of the type serializer.V- The type of value that is ultimately serialized using this dispatch codec.- Parameters:
typeCodec- A codec that can read the serializer type. Typically, this is a Codec that uses a map to go from ResourceLocation to the serializer type and back.getSerializer- A function that gets the serializer type from a value. This is used to allow the Codec to encode the type ID when writing the value.getCodec- A function that gets the codec responsible for a type. This is used to decode the resulting value.fallbackCodec- A fallback codec that is used when the type property is not specified.- Returns:
- A dispatch codec that has a fallback for when the type is not specified.
-
alternatives
public static <T> com.mojang.serialization.Codec<T> alternatives(com.mojang.serialization.Codec<T> first, com.mojang.serialization.Codec<T> second, Function<T, com.mojang.datafixers.util.Either<T, T>> encodeLogic)
-