Class RegistryElementCodec<E>

java.lang.Object
net.minecraft.registry.entry.RegistryElementCodec<E>
Type Parameters:
E - the element type
All Implemented Interfaces:
com.mojang.serialization.Codec<RegistryEntry<E>>, com.mojang.serialization.Decoder<RegistryEntry<E>>, com.mojang.serialization.Encoder<RegistryEntry<E>>

public final class RegistryElementCodec<E> extends Object implements com.mojang.serialization.Codec<RegistryEntry<E>>
A codec for registry elements. Will prefer to encode/decode objects as identifiers if they exist in a registry and falls back to full encoding/ decoding behavior if it cannot do so.

The codec's saves and loads Supplier<E> in order to avoid early loading from registry before a registry is fully loaded from a codec.

See Also:
Mappings:
Namespace Name
named net/minecraft/registry/entry/RegistryElementCodec
intermediary net/minecraft/class_5381
official alb
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.mojang.serialization.Codec

    com.mojang.serialization.Codec.RecursiveCodec<T>, com.mojang.serialization.Codec.ResultFunction<A>

    Nested classes/interfaces inherited from interface com.mojang.serialization.Decoder

    com.mojang.serialization.Decoder.Boxed<A>, com.mojang.serialization.Decoder.Simple<A>, com.mojang.serialization.Decoder.Terminal<A>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
     
    private final com.mojang.serialization.Codec<E>
     
    private final RegistryKey<? extends Registry<E>>
     

    Fields inherited from interface com.mojang.serialization.Codec

    BOOL, BYTE, BYTE_BUFFER, DOUBLE, EMPTY, FLOAT, INT, INT_STREAM, LONG, LONG_STREAM, PASSTHROUGH, SHORT, STRING
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    RegistryElementCodec(RegistryKey<? extends Registry<E>> registryRef, com.mojang.serialization.Codec<E> elementCodec, boolean allowInlineDefinitions)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> com.mojang.serialization.DataResult<com.mojang.datafixers.util.Pair<RegistryEntry<E>,T>>
    decode(com.mojang.serialization.DynamicOps<T> ops, T input)
     
    <T> com.mojang.serialization.DataResult<T>
    encode(RegistryEntry<E> registryEntry, com.mojang.serialization.DynamicOps<T> dynamicOps, T t)
     
    static <E> RegistryElementCodec<E>
    of(RegistryKey<? extends Registry<E>> registryRef, com.mojang.serialization.Codec<E> elementCodec)
     
    static <E> RegistryElementCodec<E>
    of(RegistryKey<? extends Registry<E>> registryRef, com.mojang.serialization.Codec<E> elementCodec, boolean allowInlineDefinitions)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.mojang.serialization.Codec

    comapFlatMap, deprecated, dispatch, dispatch, dispatchMap, dispatchMap, dispatchStable, fieldOf, flatComapMap, flatXmap, lenientOptionalFieldOf, lenientOptionalFieldOf, lenientOptionalFieldOf, lenientOptionalFieldOf, listOf, listOf, mapResult, optionalFieldOf, optionalFieldOf, optionalFieldOf, optionalFieldOf, orElse, orElse, orElse, orElseGet, orElseGet, orElseGet, partialDispatch, promotePartial, sizeLimitedListOf, stable, validate, withLifecycle, xmap

    Methods inherited from interface com.mojang.serialization.Decoder

    boxed, decode, flatMap, map, parse, parse, simple, terminal

    Methods inherited from interface com.mojang.serialization.Encoder

    comap, encodeStart, flatComap
  • Field Details

    • registryRef

      private final RegistryKey<? extends Registry<E>> registryRef
      Mappings:
      Namespace Name Mixin selector
      named registryRef Lnet/minecraft/registry/entry/RegistryElementCodec;registryRef:Lnet/minecraft/registry/RegistryKey;
      intermediary field_25507 Lnet/minecraft/class_5381;field_25507:Lnet/minecraft/class_5321;
      official a Lalb;a:Lale;
    • elementCodec

      private final com.mojang.serialization.Codec<E> elementCodec
      Mappings:
      Namespace Name Mixin selector
      named elementCodec Lnet/minecraft/registry/entry/RegistryElementCodec;elementCodec:Lcom/mojang/serialization/Codec;
      intermediary field_25508 Lnet/minecraft/class_5381;field_25508:Lcom/mojang/serialization/Codec;
      official b Lalb;b:Lcom/mojang/serialization/Codec;
    • allowInlineDefinitions

      private final boolean allowInlineDefinitions
      Mappings:
      Namespace Name Mixin selector
      named allowInlineDefinitions Lnet/minecraft/registry/entry/RegistryElementCodec;allowInlineDefinitions:Z
      intermediary field_26758 Lnet/minecraft/class_5381;field_26758:Z
      official c Lalb;c:Z
  • Constructor Details

    • RegistryElementCodec

      private RegistryElementCodec(RegistryKey<? extends Registry<E>> registryRef, com.mojang.serialization.Codec<E> elementCodec, boolean allowInlineDefinitions)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/registry/entry/RegistryElementCodec;<init>(Lnet/minecraft/registry/RegistryKey;Lcom/mojang/serialization/Codec;Z)V
      intermediary <init> Lnet/minecraft/class_5381;<init>(Lnet/minecraft/class_5321;Lcom/mojang/serialization/Codec;Z)V
      official <init> Lalb;<init>(Lale;Lcom/mojang/serialization/Codec;Z)V
  • Method Details

    • of

      public static <E> RegistryElementCodec<E> of(RegistryKey<? extends Registry<E>> registryRef, com.mojang.serialization.Codec<E> elementCodec)
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/registry/entry/RegistryElementCodec;of(Lnet/minecraft/registry/RegistryKey;Lcom/mojang/serialization/Codec;)Lnet/minecraft/registry/entry/RegistryElementCodec;
      intermediary method_29749 Lnet/minecraft/class_5381;method_29749(Lnet/minecraft/class_5321;Lcom/mojang/serialization/Codec;)Lnet/minecraft/class_5381;
      official a Lalb;a(Lale;Lcom/mojang/serialization/Codec;)Lalb;
    • of

      public static <E> RegistryElementCodec<E> of(RegistryKey<? extends Registry<E>> registryRef, com.mojang.serialization.Codec<E> elementCodec, boolean allowInlineDefinitions)
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/registry/entry/RegistryElementCodec;of(Lnet/minecraft/registry/RegistryKey;Lcom/mojang/serialization/Codec;Z)Lnet/minecraft/registry/entry/RegistryElementCodec;
      intermediary method_31192 Lnet/minecraft/class_5381;method_31192(Lnet/minecraft/class_5321;Lcom/mojang/serialization/Codec;Z)Lnet/minecraft/class_5381;
      official a Lalb;a(Lale;Lcom/mojang/serialization/Codec;Z)Lalb;
    • encode

      public <T> com.mojang.serialization.DataResult<T> encode(RegistryEntry<E> registryEntry, com.mojang.serialization.DynamicOps<T> dynamicOps, T t)
      Specified by:
      encode in interface com.mojang.serialization.Encoder<E>
      Mappings:
      Namespace Name Mixin selector
      named encode Lnet/minecraft/registry/entry/RegistryElementCodec;encode(Lnet/minecraft/registry/entry/RegistryEntry;Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;
      intermediary method_29748 Lnet/minecraft/class_5381;method_29748(Lnet/minecraft/class_6880;Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;
      official a Lalb;a(Lji;Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;
    • decode

      public <T> com.mojang.serialization.DataResult<com.mojang.datafixers.util.Pair<RegistryEntry<E>,T>> decode(com.mojang.serialization.DynamicOps<T> ops, T input)
      Specified by:
      decode in interface com.mojang.serialization.Decoder<E>
      Mappings:
      Namespace Name Mixin selector
      named decode Lnet/minecraft/registry/entry/RegistryElementCodec;decode(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;
      intermediary decode Lnet/minecraft/class_5381;decode(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;
      official decode Lalb;decode(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;
    • toString

      public String toString()
      Overrides:
      toString in class Object