Class GenericRegistry<K,V>

java.lang.Object
de.luckymcdev.foundryengine.common.registry.GenericRegistry<K,V>
Type Parameters:
K - Key Type.
V - Value Type.
All Implemented Interfaces:
Registry<K,V>

public class GenericRegistry<K,V> extends Object implements Registry<K,V>
A Registry for registering things.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the registry (only if not frozen).
    boolean
    contains(K key)
    Check if the registry contains a key.
    void
    forEach(BiConsumer<K,V> kvConsumer)
    Iterate over all key-value pairs.
    void
    forEach(Consumer<V> action)
    Iterate over all values.
    void
    Freeze the registry, making it immutable.
    get(K key)
    Get the value directly (legacy method, prefer getRef()).
    getKey(V value)
    Get the key for a given value (reverse lookup).
    getRandom(net.minecraft.util.RandomSource random)
    Get a random value from the registry.
    getRef(K key)
    Get a reference to the registry entry.
    boolean
    Check if the registry is empty.
    boolean
    Check if the registry is frozen (immutable).
    Get all keys in the registry.
    boolean
    onFreeze(Runnable callback)
    Register a callback to run when the registry is frozen.
    void
    register(K key, V value)
    Register a key-value pair in this registry.
    void
    remove(K key)
    Remove a key from this registry.
    void
    setDefaultValue(V defaultValue)
    Sets the default value returned when a key is not found.
    int
    Get the number of entries in the registry.
    Stream all values.
    tryGet(K key)
    Try to get a value, returning Optional.
    void
    Unfreeze the registry, allowing modifications again.
    Get all values in the registry.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GenericRegistry

      public GenericRegistry()
  • Method Details

    • register

      public void register(K key, V value)
      Description copied from interface: Registry
      Register a key-value pair in this registry.
      Specified by:
      register in interface Registry<K,V>
    • remove

      public void remove(K key)
      Description copied from interface: Registry
      Remove a key from this registry.
      Specified by:
      remove in interface Registry<K,V>
    • get

      public V get(K key)
      Description copied from interface: Registry
      Get the value directly (legacy method, prefer getRef()). Returns null or default value if not found.
      Specified by:
      get in interface Registry<K,V>
    • getRef

      public RegistryRef<K,V> getRef(K key)
      Description copied from interface: Registry
      Get a reference to the registry entry. This is the preferred way to access registry entries.
      Specified by:
      getRef in interface Registry<K,V>
      Returns:
      RegistryRef that can be cached and provides lazy loading
    • getKey

      public K getKey(V value)
      Description copied from interface: Registry
      Get the key for a given value (reverse lookup).
      Specified by:
      getKey in interface Registry<K,V>
    • getRandom

      public V getRandom(net.minecraft.util.RandomSource random)
      Description copied from interface: Registry
      Get a random value from the registry.
      Specified by:
      getRandom in interface Registry<K,V>
    • tryGet

      public Optional<V> tryGet(K key)
      Description copied from interface: Registry
      Try to get a value, returning Optional.
      Specified by:
      tryGet in interface Registry<K,V>
    • contains

      public boolean contains(K key)
      Description copied from interface: Registry
      Check if the registry contains a key.
      Specified by:
      contains in interface Registry<K,V>
    • values

      public Collection<V> values()
      Description copied from interface: Registry
      Get all values in the registry.
      Specified by:
      values in interface Registry<K,V>
    • keys

      public Collection<K> keys()
      Description copied from interface: Registry
      Get all keys in the registry.
      Specified by:
      keys in interface Registry<K,V>
    • isFrozen

      public boolean isFrozen()
      Description copied from interface: Registry
      Check if the registry is frozen (immutable).
      Specified by:
      isFrozen in interface Registry<K,V>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Registry
      Check if the registry is empty.
      Specified by:
      isEmpty in interface Registry<K,V>
    • freeze

      public void freeze()
      Description copied from interface: Registry
      Freeze the registry, making it immutable.
      Specified by:
      freeze in interface Registry<K,V>
    • unfreeze

      public void unfreeze()
      Description copied from interface: Registry
      Unfreeze the registry, allowing modifications again.
      Specified by:
      unfreeze in interface Registry<K,V>
    • onFreeze

      public boolean onFreeze(Runnable callback)
      Description copied from interface: Registry
      Register a callback to run when the registry is frozen.
      Specified by:
      onFreeze in interface Registry<K,V>
      Returns:
      true if callback was added, false if already frozen (callback ran immediately)
    • forEach

      public void forEach(BiConsumer<K,V> kvConsumer)
      Description copied from interface: Registry
      Iterate over all key-value pairs.
      Specified by:
      forEach in interface Registry<K,V>
    • forEach

      public void forEach(Consumer<V> action)
      Description copied from interface: Registry
      Iterate over all values.
      Specified by:
      forEach in interface Registry<K,V>
    • stream

      public Stream<V> stream()
      Description copied from interface: Registry
      Stream all values.
      Specified by:
      stream in interface Registry<K,V>
    • clear

      public void clear()
      Description copied from interface: Registry
      Clear the registry (only if not frozen).
      Specified by:
      clear in interface Registry<K,V>
    • size

      public int size()
      Description copied from interface: Registry
      Get the number of entries in the registry.
      Specified by:
      size in interface Registry<K,V>
    • setDefaultValue

      public void setDefaultValue(V defaultValue)
      Sets the default value returned when a key is not found.