Class RegisterCapabilitiesEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent
All Implemented Interfaces:
net.neoforged.fml.event.IModBusEvent

public class RegisterCapabilitiesEvent extends net.neoforged.bus.api.Event implements net.neoforged.fml.event.IModBusEvent
Fired to register capability providers at an appropriate time.
  • Constructor Details

    • RegisterCapabilitiesEvent

      RegisterCapabilitiesEvent()
  • Method Details

    • registerBlock

      public <T, C extends @Nullable Object> void registerBlock(BlockCapability<T,C> capability, IBlockCapabilityProvider<T,C> provider, Block... blocks)
      Register a capability provider for some blocks.

      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 IBlockCapabilityProvider for details.

    • registerBlockEntity

      public <T, C extends @Nullable Object, BE extends BlockEntity> void registerBlockEntity(BlockCapability<T,C> capability, BlockEntityType<BE> blockEntityType, ICapabilityProvider<? super BE,C,T> provider)
      Register a capability provider for a block entity type.

      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 IBlockCapabilityProvider for details.

    • isBlockRegistered

      public boolean isBlockRegistered(BlockCapability<?,?> capability, Block block)
      Return true if a provider is registered for the given block and capability.
    • setProxyable

      public void setProxyable(BlockCapability<?,?> capability)
      Makes a block capability proxyable, indicating that it is always safe to forward a request for this capability to another block. (e.g. for "remote access" blocks)

      This method should only be called by the mod that defines the capability, in the EventPriority.HIGH or EventPriority.HIGHEST phase.

      Throws:
      IllegalStateException - if the capability was already marked as non-proxyable
      See Also:
    • setNonProxyable

      public void setNonProxyable(BlockCapability<?,?> capability)
      Makes a block capability non-proxyable. This should typically be called when unexpectedly proxying the capability (e.g. to a different block position) would cause crashes, for example because the returned capability is tied to the query position.

      This method should only be called by the mod that defines the capability, in the EventPriority.HIGH or EventPriority.HIGHEST phase.

      Throws:
      IllegalStateException - if the capability was already marked as proxyable
      See Also:
    • registerEntity

      public <T, C extends @Nullable Object, E extends Entity> void registerEntity(EntityCapability<T,C> capability, EntityType<E> entityType, ICapabilityProvider<? super E,C,T> provider)
      Register a capability provider for some entity type.
    • isEntityRegistered

      public boolean isEntityRegistered(EntityCapability<?,?> capability, EntityType<?> entityType)
      Return true if a provider is registered for the given entity type and capability.
    • registerItem

      public <T, C extends @Nullable Object> void registerItem(ItemCapability<T,C> capability, ICapabilityProvider<ItemStack,C,T> provider, ItemLike... items)
      Register a capability provider for some items.
    • isItemRegistered

      public boolean isItemRegistered(ItemCapability<?,?> capability, Item item)
      Return true if a provider is registered for the given item and capability.