Class MapCodecs

java.lang.Object
net.darkhax.bookshelf.common.api.data.codecs.map.MapCodecs

public class MapCodecs extends Object
  • Field Details

    • BOOLEAN

      public static final MapCodecHelper<Boolean> BOOLEAN
    • BYTE

      public static final MapCodecHelper<Byte> BYTE
    • SHORT

      public static final MapCodecHelper<Short> SHORT
    • INT

      public static final MapCodecHelper<Integer> INT
    • FLOAT

      public static final MapCodecHelper<Float> FLOAT
    • LONG

      public static final MapCodecHelper<Long> LONG
    • DOUBLE

      public static final MapCodecHelper<Double> DOUBLE
    • STRING

      public static final MapCodecHelper<String> STRING
    • UUID

      public static final MapCodecHelper<UUID> UUID
    • ITEM_RARITY

      public static final MapCodecHelper<net.minecraft.world.item.Rarity> ITEM_RARITY
    • ATTRIBUTE_OPERATION

      public static final MapCodecHelper<net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation> ATTRIBUTE_OPERATION
    • DIRECTION

      public static final MapCodecHelper<net.minecraft.core.Direction> DIRECTION
    • AXIS

      public static final MapCodecHelper<net.minecraft.core.Direction.Axis> AXIS
    • PLANE

      public static final MapCodecHelper<net.minecraft.core.Direction.Plane> PLANE
    • MOB_CATEGORY

      public static final MapCodecHelper<net.minecraft.world.entity.MobCategory> MOB_CATEGORY
    • DYE_COLOR

      public static final MapCodecHelper<net.minecraft.world.item.DyeColor> DYE_COLOR
    • SOUND_SOURCE

      public static final MapCodecHelper<net.minecraft.sounds.SoundSource> SOUND_SOURCE
    • DIFFICULTY

      public static final MapCodecHelper<net.minecraft.world.Difficulty> DIFFICULTY
    • EQUIPMENT_SLOT

      public static final MapCodecHelper<net.minecraft.world.entity.EquipmentSlot> EQUIPMENT_SLOT
    • MIRROR

      public static final MapCodecHelper<net.minecraft.world.level.block.Mirror> MIRROR
    • ROTATION

      public static final MapCodecHelper<net.minecraft.world.level.block.Rotation> ROTATION
    • RESOURCE_LOCATION

      public static final MapCodecHelper<net.minecraft.resources.Identifier> RESOURCE_LOCATION
    • COMPOUND_TAG

      public static final MapCodecHelper<net.minecraft.nbt.CompoundTag> COMPOUND_TAG
    • ITEM_STACK

      public static final MapCodecHelper<net.minecraft.world.item.ItemStack> ITEM_STACK
    • TEXT

      public static final MapCodecHelper<net.minecraft.network.chat.Component> TEXT
    • BLOCK_POS

      public static final MapCodecHelper<net.minecraft.core.BlockPos> BLOCK_POS
    • INGREDIENT

      public static final MapCodecHelper<net.minecraft.world.item.crafting.Ingredient> 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

      public static final MapCodecHelper<net.minecraft.world.effect.MobEffectInstance> EFFECT_INSTANCE
    • VECTOR_3F

      public static final MapCodecHelper<org.joml.Vector3fc> VECTOR_3F
    • LOAD_CONDITION

      public static final MapCodecHelper<ILoadCondition> 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 from Codec.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 from Codec.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 from Codec.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

      public 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.
      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.