类 EntityCapability<T,C extends @Nullable Object>
java.lang.Object
net.neoforged.neoforge.capabilities.BaseCapability<T,C>
net.neoforged.neoforge.capabilities.EntityCapability<T,C>
- 类型参数:
T
- type of queried objectsC
- 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>);
});
-
字段概要
字段修饰符和类型字段说明(专用程序包) final Map
<EntityType<?>, List<ICapabilityProvider<Entity, C, T>>> private static final CapabilityRegistry
<EntityCapability<?, ?>> -
构造器概要
构造器限定符构造器说明private
EntityCapability
(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) -
方法概要
修饰符和类型方法说明static <T,
C extends @Nullable Object>
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 nullableDirection
context, or gets it if it already exists.static <T> EntityCapability
<T, @Nullable Void> createVoid
(ResourceLocation name, Class<T> typeClass) Creates a new entity capability withVoid
context, or gets it if it already exists.static List
<EntityCapability<?, ?>> getAll()
返回 a new immutable copy of all the currently known entity capabilities。getCapability
(Entity entity, C context) 从类继承的方法 net.neoforged.neoforge.capabilities.BaseCapability
contextClass, name, typeClass
-
字段详细资料
-
registry
-
providers
-
-
构造器详细资料
-
EntityCapability
-
-
方法详细资料
-
create
public static <T,C extends @Nullable Object> EntityCapability<T,C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) Creates a new entity capability, or gets it if it already exists.- 参数:
name
- name of the capabilitytypeClass
- type of the queried APIcontextClass
- type of the additional context
-
createVoid
public static <T> EntityCapability<T,@Nullable Void> createVoid(ResourceLocation name, Class<T> typeClass) Creates a new entity capability withVoid
context, or gets it if it already exists. This should be used for capabilities that do not require any additional context.- 另请参阅:
-
createSided
public static <T> EntityCapability<T,@Nullable Direction> createSided(ResourceLocation name, Class<T> typeClass) Creates a new entity capability with nullableDirection
context, or gets it if it already exists. The side is generally the side from which the entity is being accessed, ornull
if it is not known or not a specific side. -
getAll
返回 a new immutable copy of all the currently known entity capabilities。- 返回:
- a new immutable copy of all the currently known entity capabilities
-
getCapability
-