Class MapCodec.MapCodecCodec<A>

java.lang.Object
com.mojang.serialization.MapCodec.MapCodecCodec<A>
Type Parameters:
A - the type to encode and decode
All Implemented Interfaces:
Codec<A>, Decoder<A>, Encoder<A>
Enclosing class:
MapCodec<A>

public static final class MapCodec.MapCodecCodec<A> extends Object implements Codec<A>
A Codec that encodes and decodes a MapCodec. These codecs are occasionally treated specially by other codec constructions - notably, KeyDispatchCodec will delegate to a MapCodec.MapCodecCodec differently than Additionally, this codec returns a remainder when decoding instead of consuming the entire input - this means that the codec can be used more easily alongside Codec.pair(Codec, Codec) than a "normal" codec, where the first codec would consume the entire input.

Note: when further modifying a MapCodec.MapCodecCodec, if you wish the "map-ness" of the codec to be maintained (which you may to retain special behaviour with KeyDispatchCodec or the like) you will want to use Codec.mapPair(MapCodec, MapCodec), MapCodec.flatXmap(Function, Function), and company. in place of Codec.pair(Codec, Codec), Codec.flatXmap(Function, Function) (Function, Function)}, and company.

  • Constructor Details

    • MapCodecCodec

      public MapCodecCodec(MapCodec<A> codec)
  • Method Details

    • codec

      public MapCodec<A> codec()
    • decode

      public <T> DataResult<Pair<A,T>> decode(DynamicOps<T> ops, T input)
      Description copied from interface: Decoder
      Decodes an object from a serialized form, returning any remaining serialized data.
      Specified by:
      decode in interface Decoder<A>
      Type Parameters:
      T - the type of the serialized form
      Parameters:
      ops - a DynamicOps for the serialized form
      input - the serialized form to decode
      Returns:
      a DataResult containing the decoded object and any remaining serialized data, or an error if the object could not be decoded
    • encode

      public <T> DataResult<T> encode(A input, DynamicOps<T> ops, T prefix)
      Description copied from interface: Encoder
      Encodes an object to a serialized form, adding to an existing prefix.
      Specified by:
      encode in interface Encoder<A>
      Type Parameters:
      T - the type to serialize to
      Parameters:
      input - the object to encode
      ops - a DynamicOps for the target serialized format
      prefix - existing data that the encoded object should be added to
      Returns:
      a DataResult containing the serialized form of the object, or an error if the object could not be serialized
    • toString

      public String toString()
      Overrides:
      toString in class Object