Class EntityCapability<T,C> 
java.lang.Object
net.neoforged.neoforge.capabilities.BaseCapability<T,C>
 
net.neoforged.neoforge.capabilities.EntityCapability<T,C> 
- Type Parameters:
- T- type of queried objects
- C- type of the additional context
An 
EntityCapability gives flexible access to objects of type T from entities.
 Querying an entity capability
To get an object of type T, use Entity.getCapability(EntityCapability).
 For example, to query an item handler from an entity:
 
 
 Entity entity = ...;
 IItemHandler maybeHandler = entity.getCapability(Capabilities.ItemHandler.ENTITY);
 if (maybeHandler != null) {
     // Use maybeHandler
 }
 Providing an entity capability
To provide objects of type T, register providers to RegisterCapabilitiesEvent. For example:
 
 
 modBus.addListener((RegisterCapabilitiesEvent event) -> {
     event.registerEntity(
         Capabilities.ItemHandler.ENTITY, // capability to register for
         MY_ENTITY_TYPE,
         (myEntity, context) -> <return the IItemHandler for myEntity>);
 });
 - 
Field SummaryFieldsModifier and TypeFieldDescription(package private) final Map<EntityType<?>, List<ICapabilityProvider<Entity, C, T>>> private static final CapabilityRegistry<EntityCapability<?, ?>> 
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprivateEntityCapability(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) 
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T,C> EntityCapability <T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) Creates a new entity capability, or gets it if it already exists.static <T> EntityCapability<T, @Nullable Direction> createSided(ResourceLocation name, Class<T> typeClass) Creates a new entity capability with nullableDirectioncontext, or gets it if it already exists.static <T> EntityCapability<T, Void> createVoid(ResourceLocation name, Class<T> typeClass) Creates a new entity capability withVoidcontext, or gets it if it already exists.static List<EntityCapability<?, ?>> getAll()Returns a new immutable copy of all the currently known entity capabilities.getCapability(Entity entity, C context) Methods inherited from class net.neoforged.neoforge.capabilities.BaseCapabilitycontextClass, name, typeClass
- 
Field Details- 
registry
- 
providers
 
- 
- 
Constructor Details- 
EntityCapability
 
- 
- 
Method Details- 
createpublic static <T,C> EntityCapability<T,C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) Creates a new entity capability, or gets it if it already exists.- Parameters:
- name- name of the capability
- typeClass- type of the queried API
- contextClass- type of the additional context
 
- 
createVoidCreates a new entity capability withVoidcontext, or gets it if it already exists. This should be used for capabilities that do not require any additional context.- See Also:
 
- 
createSidedpublic static <T> EntityCapability<T,@Nullable Direction> createSided(ResourceLocation name, Class<T> typeClass) Creates a new entity capability with nullableDirectioncontext, or gets it if it already exists. The side is generally the side from which the entity is being accessed, ornullif it is not known or not a specific side.
- 
getAllReturns a new immutable copy of all the currently known entity capabilities.- Returns:
- a new immutable copy of all the currently known entity capabilities
 
- 
getCapability
 
-