Package com.mojang.serialization
Class MapCodec<A>
java.lang.Object
com.mojang.serialization.CompressorHolder
com.mojang.serialization.MapCodec<A>
- Type Parameters:
A
- The type to convert
- All Implemented Interfaces:
Compressable
,Keyable
,MapDecoder<A>
,MapEncoder<A>
- Direct Known Subclasses:
EitherMapCodec
,KeyDispatchCodec
,OptionalFieldCodec
,PairMapCodec
,SimpleMapCodec
A combined
MapEncoder
and MapDecoder
which can convert objects to and from a series of fields.
A MapCodec
consists of a fixed set of optional fields, can read those fields from a MapLike
object,
and can write those fields to a RecordBuilder
object. A MapCodec
can be used to create a Codec
by calling codec()
; this codec will encode the map's fields to a map created by a DynamicOps
instance.
unless the ops have DynamicOps.compressMaps()
, in which case the map will be encoded in a "compressed" map - in
other words, as a list of values, where the index of the value in the list corresponds to the index of the (potentially
optional) key in the stream returned by keys(DynamicOps)
. Codecs created by codec()
are occasionally
treated specially by other codec constructions.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static interface
Nested classes/interfaces inherited from interface com.mojang.serialization.MapDecoder
MapDecoder.Implementation<A>
Nested classes/interfaces inherited from interface com.mojang.serialization.MapEncoder
MapEncoder.Implementation<A>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncodec()
dependent
(MapCodec<E> initialInstance, Function<A, Pair<E, MapCodec<E>>> splitter, BiFunction<A, E, A> combiner) deprecated
(int since) <S> MapCodec<S>
flatXmap
(Function<? super A, ? extends DataResult<? extends S>> to, Function<? super S, ? extends DataResult<? extends A>> from) final <O> RecordCodecBuilder<O,
A> abstract <T> Stream<T>
keys
(DynamicOps<T> ops) Returns a stream of keys this map codec may write or read.mapResult
(MapCodec.ResultFunction<A> function) static <A> MapCodec<A>
of
(MapEncoder<A> encoder, MapDecoder<A> decoder) static <A> MapCodec<A>
of
(MapEncoder<A> encoder, MapDecoder<A> decoder, Supplier<String> name) orElse
(UnaryOperator<String> onError, A value) orElseGet
(UnaryOperator<String> onError, Supplier<? extends A> value) setPartial
(Supplier<A> value) stable()
static <A> MapCodec<A>
unit
(A defaultValue) static <A> MapCodec<A>
withLifecycle
(Lifecycle lifecycle) <S> MapCodec<S>
Methods inherited from class com.mojang.serialization.CompressorHolder
compressor
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.mojang.serialization.MapDecoder
ap, compressedDecode, compressor, decode, decoder, flatMap, map
Methods inherited from interface com.mojang.serialization.MapEncoder
comap, compressedBuilder, compressor, encode, encoder, flatComap
-
Constructor Details
-
MapCodec
public MapCodec()
-
-
Method Details
-
forGetter
-
of
-
of
public static <A> MapCodec<A> of(MapEncoder<A> encoder, MapDecoder<A> decoder, Supplier<String> name) -
fieldOf
-
withLifecycle
- Specified by:
withLifecycle
in interfaceMapDecoder<A>
- Specified by:
withLifecycle
in interfaceMapEncoder<A>
-
codec
-
stable
-
deprecated
-
xmap
-
flatXmap
public <S> MapCodec<S> flatXmap(Function<? super A, ? extends DataResult<? extends S>> to, Function<? super S, ? extends DataResult<? extends A>> from) -
dependent
-
keys
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 withDynamicOps.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 hasDynamicOps.compressMaps()
. -
mapResult
-
orElse
-
orElse
-
orElseGet
-
orElseGet
-
orElse
-
orElseGet
-
setPartial
-
unit
-
unit
-