Class DecoderRegistry<W,M>

java.lang.Object
dev.wyck.wrapper.decode.DecoderRegistry<W,M>
Type Parameters:
W - the family this registry decodes
M - the Minecraft type dispatched by this registry
All Implemented Interfaces:
Decodable<W,M>

@NullMarked @AsOf("3.3.0") @Internal public abstract class DecoderRegistry<W,M> extends Object implements Decodable<W,M>
Collects the decoders of one wrapper family and dispatches to them by type key.
Since:
3.3.0
  • Constructor Details

    • DecoderRegistry

      protected DecoderRegistry()
  • Method Details

    • discriminate

      protected abstract ResourceKey discriminate(M minecraftObject)
      Gets the key that identifies the concrete type of a Minecraft object.
      Parameters:
      minecraftObject - the Minecraft object to discriminate
      Returns:
      the object's decoder type key
    • normalize

      protected M normalize(M minecraftObject)
      Rewrites an object into the form this registry's decoders expect.
      Parameters:
      minecraftObject - the Minecraft object supplied to the registry
      Returns:
      the normalized decoding target
    • register

      protected final void register(String minecraftType, Function<M,W> decoder)
      Registers a decoder for a single vanilla type. Use this for types whose reading is a few field reads; a type needing real logic gets its own Decodable class instead.
    • register

      protected final void register(ResourceKey key, Function<M,W> decoder)
      Registers an inline decoder under an explicit key, including family-defined pseudo-types.
      Parameters:
      key - the type key handled by the decoder
      decoder - the decoder function
    • register

      protected final void register(Decodable<W,M> decoder)
    • decode

      public final W decode(M minecraftObject)
      Description copied from interface: Decodable
      Decodes a Minecraft value into the Wyck type owned by this decoder.
      Specified by:
      decode in interface Decodable<W,M>
      Parameters:
      minecraftObject - the Minecraft object to read
      Returns:
      the wrapper for that object
    • typeOf

      public final ResourceKey typeOf(M minecraftObject)
    • handles

      public final boolean handles(ResourceKey type)
    • handled

      public final Set<ResourceKey> handled()
      Gets every type key claimed by this registry.
      Returns:
      the handled type keys
    • family

      protected String family()