Interface IBlockCapabilityProvider<T,C>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
-
Method Summary
Modifier and TypeMethodDescriptiongetCapability
(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, C context) Returns the capability, ornull
if not available.
-
Method Details
-
getCapability
@Nullable T getCapability(Level level, BlockPos pos, BlockState state, @Nullable @Nullable BlockEntity blockEntity, C context) Returns the capability, ornull
if not available.If a previously returned capability is not valid anymore, or if a new capability is available,
ILevelExtension.invalidateCapabilities(BlockPos)
MUST be called to notify the caches (see below).Capabilities are automatically invalidated by NeoForge in the following cases:
- Chunk loads and unloads.
- Block entity loads and unloads.
- Block entity placement and destruction.
ILevelExtension.invalidateCapabilities(BlockPos)
. For example:- If the configuration of a block entity changes.
- If a plain block is placed or changes state, by overriding
onPlace
. Be careful that if you don't invalidate for every state change, you should not capture thestate
parameter because the state might change! - If a plain block is removed, by overriding
onRemove
.
- Parameters:
level
- The level.pos
- The position.state
- The block state.blockEntity
- The block entity, if present.null
means that there is no block entity at the target position.context
- Extra context, capability-dependent.
-