类 BlockCapabilityCache<T,C extends @Nullable Object>
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.
-
字段概要
字段修饰符和类型字段说明private T
private boolean
true
if notifications received by the cache will be forwarded tolistener
.private boolean
private final BlockCapability
<T, C> private final C
private final ServerLevel
private final ICapabilityInvalidationListener
private final BlockPos
-
构造器概要
构造器限定符构造器说明private
BlockCapabilityCache
(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) -
方法概要
修饰符和类型方法说明context()
static <T,
C extends @Nullable Object>
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 extends @Nullable Object>
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, ornull
if the capability is not present.level()
pos()
-
字段详细资料
-
capability
-
level
-
pos
-
context
-
cacheValid
private boolean cacheValidtrue
if notifications received by the cache will be forwarded tolistener
. By default and after each invalidation, this is set tofalse
. CallinggetCapability()
sets it totrue
. -
cachedCap
-
canQuery
private boolean canQuery -
listener
-
-
构造器详细资料
-
BlockCapabilityCache
private BlockCapabilityCache(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener)
-
-
方法详细资料
-
create
public static <T,C extends @Nullable Object> 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.- 参数:
capability
- the capabilitylevel
- the levelpos
- the positioncontext
- extra context for the query
-
create
public static <T,C extends @Nullable Object> 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.
- 参数:
capability
- the capabilitylevel
- the levelpos
- the positioncontext
- extra context for the queryisValid
- 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
-
getCapability
Gets the capability instance, ornull
if the capability is not present.If the target position is not loaded, this method will return
null
.
-