Class BlockCapabilityCache<T,C> 
java.lang.Object
net.neoforged.neoforge.capabilities.BlockCapabilityCache<T,C> 
A cache for block capabilities, to be used to track capabilities at a specific position, with a specific context.
 
The cache is invalidated when the level is notified of a change via ILevelExtension.invalidateCapabilities(BlockPos).
 
Instances are automatically cleared by the garbage collector when they are no longer in use.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate Tprivate booleantrueif notifications received by the cache will be forwarded tolistener.private booleanprivate final BlockCapability<T,C> private final Cprivate final ServerLevelprivate final ICapabilityInvalidationListenerprivate final BlockPos
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprivateBlockCapabilityCache(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) 
- 
Method SummaryModifier and TypeMethodDescriptioncontext()static <T,C> BlockCapabilityCache<T, C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context) Creates a new cache instance and registers it to the level.static <T,C> BlockCapabilityCache<T, C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) Creates a new cache instance with an invalidation listener, and registers it to the level.Gets the capability instance, ornullif the capability is not present.level()pos()
- 
Field Details- 
capability
- 
level
- 
pos
- 
context
- 
cacheValidprivate boolean cacheValidtrueif notifications received by the cache will be forwarded tolistener. By default and after each invalidation, this is set tofalse. CallinggetCapability()sets it totrue.
- 
cachedCap
- 
canQueryprivate boolean canQuery
- 
listener
 
- 
- 
Constructor Details- 
BlockCapabilityCacheprivate BlockCapabilityCache(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) 
 
- 
- 
Method Details- 
createpublic static <T,C> BlockCapabilityCache<T,C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context) Creates a new cache instance and registers it to the level.- Parameters:
- capability- the capability
- level- the level
- pos- the position
- context- extra context for the query
 
- 
createpublic static <T,C> BlockCapabilityCache<T,C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) Creates a new cache instance with an invalidation listener, and registers it to the level.A few details regarding the system: - Calling getCapability()from the invalidation listener is not supported, as the block being invalidated might not be ready to be queried again yet. If you receive an invalidation notification, you should wait for some time (e.g. until your own tick) before checkinggetCapability()again.
- In general, do not perform any level access for the listener. The listener itself might be in a chunk that is being unloaded, for example.
- The listener does not receive notifications before getCapability()is called. After each invalidation,getCapability()must be called again to enable further notifications.
 - Parameters:
- capability- the capability
- level- the level
- pos- the position
- context- extra context for the query
- isValid- a function to check if the listener still wants to receive notifications. A typical example would be- () -> !this.isRemoved()for a block entity that should not receive invalidation notifications anymore once it is removed.
- invalidationListener- the invalidation listener. Will be called whenever the capability of the cache might have changed.
 
- Calling 
- 
level
- 
pos
- 
context
- 
getCapabilityGets the capability instance, ornullif the capability is not present.If the target position is not loaded, this method will return null.
 
-