Class BlockCapabilities

java.lang.Object
org.cyclops.commoncapabilities.api.capability.block.BlockCapabilities
All Implemented Interfaces:
IBlockCapabilityProvider

public class BlockCapabilities extends Object implements 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 Type
    Method
    Description
    void
    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.
     
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static BlockCapabilities 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

      public void register(@Nonnull IBlockCapabilityConstructor capabilityConstructor)
      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 interface IBlockCapabilityProvider
      Type Parameters:
      T - The capability type.
      Parameters:
      blockState - The blockstate to retrieve the capability from
      capability - The capability to check
      world - The world in which the given block exists
      pos - The position at which the given block exists
      facing - The Side to check from: CAN BE NULL. Null is defined to represent 'internal' or 'self'
      Returns:
      The requested capability.