Class SimpleRegistry<T>

All Implemented Interfaces:
com.mojang.serialization.Codec<T>, com.mojang.serialization.Decoder<T>, com.mojang.serialization.Encoder<T>, com.mojang.serialization.Keyable, Iterable<T>, IndexedIterable<T>
Direct Known Subclasses:
DefaultedRegistry

public class SimpleRegistry<T>
extends MutableRegistry<T>
  • Field Details

    • LOGGER

      protected static final Logger LOGGER
    • rawIdToEntry

      private final ObjectList<T> rawIdToEntry
    • entryToRawId

      private final Object2IntMap<T> entryToRawId
    • idToEntry

      private final BiMap<Identifier,​T> idToEntry
    • keyToEntry

      private final BiMap<RegistryKey<T>,​T> keyToEntry
    • entryToLifecycle

      private final Map<T,​com.mojang.serialization.Lifecycle> entryToLifecycle
    • lifecycle

      private com.mojang.serialization.Lifecycle lifecycle
    • randomEntries

      protected Object[] randomEntries
    • nextId

      private int nextId
  • Constructor Details

    • SimpleRegistry

      public SimpleRegistry​(RegistryKey<? extends Registry<T>> key, com.mojang.serialization.Lifecycle lifecycle)
  • Method Details

    • createRegistryManagerEntryCodec

      public static <T> com.mojang.serialization.MapCodec<SimpleRegistry.RegistryManagerEntry<T>> createRegistryManagerEntryCodec​(RegistryKey<? extends Registry<T>> registryKey, com.mojang.serialization.MapCodec<T> entryCodec)
    • set

      public <V extends T> V set​(int rawId, RegistryKey<T> key, V entry, com.mojang.serialization.Lifecycle lifecycle)
      Specified by:
      set in class MutableRegistry<T>
    • set

      private <V extends T> V set​(int rawId, RegistryKey<T> key, V entry, com.mojang.serialization.Lifecycle lifecycle, boolean checkDuplicateKeys)
    • add

      public <V extends T> V add​(RegistryKey<T> key, V entry, com.mojang.serialization.Lifecycle lifecycle)
      Specified by:
      add in class MutableRegistry<T>
    • replace

      public <V extends T> V replace​(OptionalInt rawId, RegistryKey<T> key, V newEntry, com.mojang.serialization.Lifecycle lifecycle)
      If the given key is already present in the registry, replaces the entry associated with the given key with the new entry. This method asserts that the raw ID is equal to the value already in the registry. The raw ID not being present may lead to buggy behavior.

      If the given key is not already present in the registry, adds the entry to the registry. If rawId is present, then this method gives the entry this raw ID. Otherwise, uses the next available ID.

      Specified by:
      replace in class MutableRegistry<T>
    • getId

      @Nullable public Identifier getId​(T entry)
      Specified by:
      getId in class Registry<T>
    • getKey

      public Optional<RegistryKey<T>> getKey​(T entry)
      Specified by:
      getKey in class Registry<T>
    • getRawId

      public int getRawId​(@Nullable T entry)
      Specified by:
      getRawId in interface IndexedIterable<T>
      Specified by:
      getRawId in class Registry<T>
    • get

      @Nullable public T get​(@Nullable RegistryKey<T> key)
      Specified by:
      get in class Registry<T>
    • get

      @Nullable public T get​(int index)
    • getEntryLifecycle

      public com.mojang.serialization.Lifecycle getEntryLifecycle​(T t)
      Gets the lifecycle of a registry entry.
      Specified by:
      getEntryLifecycle in class Registry<T>
    • getLifecycle

      public com.mojang.serialization.Lifecycle getLifecycle()
      Specified by:
      getLifecycle in class Registry<T>
    • iterator

      public Iterator<T> iterator()
    • get

      @Nullable public T get​(@Nullable Identifier id)
      Specified by:
      get in class Registry<T>
    • getIds

      public Set<Identifier> getIds()
      Specified by:
      getIds in class Registry<T>
    • getEntries

      public Set<Map.Entry<RegistryKey<T>,​T>> getEntries()
      Specified by:
      getEntries in class Registry<T>
    • getRandom

      @Nullable public T getRandom​(Random random)
    • containsId

      @Environment(CLIENT) public boolean containsId​(Identifier id)
      Specified by:
      containsId in class Registry<T>
    • createRegistryManagerCodec

      public static <T> com.mojang.serialization.Codec<SimpleRegistry<T>> createRegistryManagerCodec​(RegistryKey<? extends Registry<T>> registryKey, com.mojang.serialization.Lifecycle lifecycle, com.mojang.serialization.Codec<T> entryCodec)
    • createRegistryCodec

      public static <T> com.mojang.serialization.Codec<SimpleRegistry<T>> createRegistryCodec​(RegistryKey<? extends Registry<T>> registryRef, com.mojang.serialization.Lifecycle lifecycle, com.mojang.serialization.Codec<T> entryCodec)
    • createCodec

      public static <T> com.mojang.serialization.Codec<SimpleRegistry<T>> createCodec​(RegistryKey<? extends Registry<T>> registryKey, com.mojang.serialization.Lifecycle lifecycle, com.mojang.serialization.Codec<T> entryCodec)