Class CompositeHolderSet<T>
java.lang.Object
net.neoforged.neoforge.registries.holdersets.CompositeHolderSet<T>
- All Implemented Interfaces:
Iterable<Holder<T>>
,HolderSet<T>
,IHolderSetExtension<T>
,ICustomHolderSet<T>
- Direct Known Subclasses:
AndHolderSet
,OrHolderSet
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.core.HolderSet
HolderSet.Direct<T>, HolderSet.ListBacked<T>, HolderSet.Named<T>
Nested classes/interfaces inherited from interface net.neoforged.neoforge.common.extensions.IHolderSetExtension
IHolderSetExtension.SerializationType
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addInvalidationListener
(Runnable runnable) Adds a callback to run when this holderset's contents invalidate (i.e.boolean
canSerializeIn
(HolderOwner<T> holderOwner) boolean
Returns immutable Set of Holders given this composite holderset's component holdersets.get
(int i) getList()
getRandomElement
(RandomSource rand) getSet()
Maps the sub-holdersets of this composite such that, if the list contains more than one element, and is non-homogenous, each element of the list will serialize as an object.private void
boolean
iterator()
int
size()
stream()
unwrap()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.neoforge.registries.holdersets.ICustomHolderSet
serializationType, type
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
owners
-
components
-
set
-
list
-
-
Constructor Details
-
CompositeHolderSet
-
-
Method Details
-
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
-
getSet
-
getList
-
addInvalidationListener
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 interfaceIHolderSetExtension<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
-
size
public int size() -
unwrap
-
getRandomElement
- Specified by:
getRandomElement
in interfaceHolderSet<T>
-
get
-
contains
-
canSerializeIn
- Specified by:
canSerializeIn
in interfaceHolderSet<T>
-
unwrapKey
-
iterator
-
homogenize
Maps the sub-holdersets of this composite such that, if the list contains more than one element, and is non-homogenous, each element of the list will serialize as an object. Prevents crashes from trying to serialize non-homogenous lists to NBT. Lists are considered non-homogenous if it contains more than one serialization type of holderset. Holdersets may be serialized as strings, lists, or maps.- Returns:
- List of holdersets with homogenous serialization behavior. Returns a new List if size > 1 and serialization would be non-homogenous, otherwise returns the composite's existing List.
-
isHomogenous
public boolean isHomogenous()- Returns:
- True if all of our sub-holdersets have the same
IHolderSetExtension.SerializationType
(string, list, or object). False if we have more than one holderset AND if either we have more than one serialization type among them, or any holderset isinvalid reference
SerializationType.UNKNOWN
-