Class OptionalFieldCodec<A>

All Implemented Interfaces:
Compressable, Keyable, MapDecoder<Optional<A>>, MapEncoder<Optional<A>>

public class OptionalFieldCodec<A> extends MapCodec<Optional<A>>
Mojang-Added Docs:

Optimization of `Codec.either(someCodec.field(name), Codec.EMPTY)`

  • Constructor Details

    • OptionalFieldCodec

      public OptionalFieldCodec(String name, Codec<A> elementCodec)
  • Method Details

    • decode

      public <T> DataResult<Optional<A>> decode(DynamicOps<T> ops, MapLike<T> input)
    • encode

      public <T> RecordBuilder<T> encode(Optional<A> input, DynamicOps<T> ops, RecordBuilder<T> prefix)
    • keys

      public <T> Stream<T> keys(DynamicOps<T> ops)
      Description copied from class: MapCodec
      Returns a stream of keys this map codec may write or read. This stream should contain any key that may be written or read, even ones that are optional. The codec need not read or write all of these keys on any given occasion, but all keys that might be read or written should be included, as this stream is used to form the number-based indexing used with DynamicOps.compressMaps().

      Note: if a map codec writes a key that is not returned by this method, it will not work correctly with a DynamicOps that has DynamicOps.compressMaps().

      Specified by:
      keys in interface Keyable
      Specified by:
      keys in class MapCodec<Optional<A>>
      Type Parameters:
      T - the data type to encode keys to or decode keys from
      Parameters:
      ops - the dynamic ops instance
      Returns:
      a stream of keys this map codec may write or read
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object