Class NotHolderSet<T>

java.lang.Object
net.neoforged.neoforge.registries.holdersets.NotHolderSet<T>
All Implemented Interfaces:
Iterable<Holder<T>>, HolderSet<T>, IHolderSetExtension<T>, ICustomHolderSet<T>

public class NotHolderSet<T> extends Object implements ICustomHolderSet<T>

Holderset that represents all elements of a registry not present in another holderset. neoforge:exclusion is preferable when the number of allowed elements is small relative to the size of the registry. Json format:

 {
   "type": "neoforge:not",
   "value": "not_this_holderset" // string, list, or object
 }
 
  • Field Details

  • Constructor Details

  • Method Details

    • codec

      public static <T> com.mojang.serialization.MapCodec<? extends ICustomHolderSet<T>> codec(ResourceKey<? extends Registry<T>> registryKey, com.mojang.serialization.Codec<Holder<T>> holderCodec, boolean forceList)
    • registryLookup

      public HolderLookup.RegistryLookup<T> registryLookup()
    • value

      public HolderSet<T> value()
    • type

      public HolderSetType type()
      Description copied from interface: ICustomHolderSet
      Returns HolderSetType registered to
      invalid reference
      ForgeRegistries.HOLDER_SET_TYPES
      .
      Specified by:
      type in interface ICustomHolderSet<T>
      Returns:
      HolderSetType registered to
      invalid reference
      ForgeRegistries.HOLDER_SET_TYPES
    • addInvalidationListener

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

      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 IHolderSetExtension<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.
    • iterator

      public Iterator<Holder<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • 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 random)
      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>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getList

      private List<Holder<T>> getList()
    • invalidate

      private void invalidate()