Class CompositeHolderSet<T>

java.lang.Object
net.minecraftforge.registries.holdersets.CompositeHolderSet<T>
All Implemented Interfaces:
Iterable<Holder<T>>, HolderSet<T>, IForgeHolderSet<T>, ICustomHolderSet<T>
Direct Known Subclasses:
AndHolderSet, OrHolderSet

public abstract class CompositeHolderSet<T> extends Object implements ICustomHolderSet<T>
Composite holdersets have component holdersets and possibly owner holdersets (which have this holderset as a component). When their component holderset(s) invalidate, they clear any cached data and then invalidate their owner holdersets.
  • Field Details

  • Constructor Details

    • CompositeHolderSet

      public CompositeHolderSet(List<HolderSet<T>> components)
  • Method Details

    • createSet

      protected abstract Set<Holder<T>> createSet()
      Returns immutable Set of Holders given this composite holderset's component holdersets.
      Returns:
      immutable Set of Holders given this composite holderset's component holdersets
    • getComponents

      public List<HolderSet<T>> getComponents()
    • getSet

      public Set<Holder<T>> getSet()
    • getList

      public List<Holder<T>> getList()
    • addInvalidationListener

      public void addInvalidationListener(Runnable runnable)
      Description copied from interface: IForgeHolderSet

      Adds a callback to run when this holderset's contents invalidate (i.e. because tags were rebound).

      The intended usage and use case is with composite holdersets that need to cache sets/list based on other holdersets, which may be mutable (because they are tag-based or themselves composite holdersets). Composite holdersets should use this to add callbacks to each of their component holdersets when constructed.

      Specified by:
      addInvalidationListener in interface IForgeHolderSet<T>
      Parameters:
      runnable - Runnable to invoke when this component holderset's contents are no longer valid. This runnable should only clear caches and allow them to be lazily reevaluated later, as not all tag holdersets may have been rebound when this is called. This runnable should also invalidate all of the caller's listeners.
    • invalidate

      private void invalidate()
    • stream

      public Stream<Holder<T>> stream()
      Specified by:
      stream in interface HolderSet<T>
    • size

      public int size()
      Specified by:
      size in interface HolderSet<T>
    • unwrap

      public com.mojang.datafixers.util.Either<TagKey<T>,List<Holder<T>>> unwrap()
      Specified by:
      unwrap in interface HolderSet<T>
    • getRandomElement

      public Optional<Holder<T>> getRandomElement(RandomSource rand)
      Specified by:
      getRandomElement in interface HolderSet<T>
    • get

      public Holder<T> get(int i)
      Specified by:
      get in interface HolderSet<T>
    • contains

      public boolean contains(Holder<T> holder)
      Specified by:
      contains in interface HolderSet<T>
    • canSerializeIn

      public boolean canSerializeIn(HolderOwner<T> holderOwner)
      Specified by:
      canSerializeIn in interface HolderSet<T>
    • unwrapKey

      public Optional<TagKey<T>> unwrapKey()
      Specified by:
      unwrapKey in interface HolderSet<T>
    • iterator

      public Iterator<Holder<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>