Class BlockCapabilities
java.lang.Object
org.cyclops.commoncapabilities.api.capability.block.BlockCapabilities
- All Implemented Interfaces:
IBlockCapabilityProvider
The general registry for capabilities of blocks.
This is used to register capabilities to blocks AND to lookup capabilities of blocks.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterBlocksRegistered
(net.minecraftforge.registries.RegisterEvent event) <T> net.minecraftforge.common.util.LazyOptional<T>
getCapability
(net.minecraft.world.level.block.state.BlockState blockState, net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction facing) Retrieves the handler for the capability of the given block requested at the given position.static BlockCapabilities
protected void
register
(net.minecraft.world.level.block.Block block, IBlockCapabilityProvider capabilityProvider) Register a capability provider for the given block or for all blocks.void
register
(IBlockCapabilityConstructor capabilityConstructor) Register a block capability provider constructor.
-
Method Details
-
getInstance
-
register
protected void register(@Nullable net.minecraft.world.level.block.Block block, @Nonnull IBlockCapabilityProvider capabilityProvider) Register a capability provider for the given block or for all blocks. This MUST be called after the given block is registered, otherwise the block instance may be null.- Parameters:
block
- The block the capability provider applies to, null if it applies to all blocks. Only use null if absolutely necessary, as this will reduce performance during lookup.capabilityProvider
- The capability provider
-
register
Register a block capability provider constructor. This will make sure that the constructor is only called AFTER all blocks have been registered. So this method can be called at any time.- Parameters:
capabilityConstructor
- A constructor for a block capability provider.
-
afterBlocksRegistered
public void afterBlocksRegistered(net.minecraftforge.registries.RegisterEvent event) -
getCapability
public <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(@Nonnull net.minecraft.world.level.block.state.BlockState blockState, @Nonnull net.minecraftforge.common.capabilities.Capability<T> capability, @Nonnull net.minecraft.world.level.BlockGetter world, @Nonnull net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction facing) Description copied from interface:IBlockCapabilityProvider
Retrieves the handler for the capability of the given block requested at the given position. The position is identified by the World, BlockPos and EnumFacing. The return value CAN be null if the block does not support the capability. The return value CAN be the same for multiple faces.- Specified by:
getCapability
in interfaceIBlockCapabilityProvider
- Type Parameters:
T
- The capability type.- Parameters:
blockState
- The blockstate to retrieve the capability fromcapability
- The capability to checkworld
- The world in which the given block existspos
- The position at which the given block existsfacing
- The Side to check from: CAN BE NULL. Null is defined to represent 'internal' or 'self'- Returns:
- The requested capability.
-