类 ItemCapability<T,C extends @Nullable Object>
java.lang.Object
net.neoforged.neoforge.capabilities.BaseCapability<T,C>
net.neoforged.neoforge.capabilities.ItemCapability<T,C>
- 类型参数:
T
- type of queried objectsC
- type of the additional context
An
ItemCapability
gives flexible access to objects of type T
from item stacks.
Querying an item capability
To get an object of type T
, use IItemStackExtension.getCapability(ItemCapability)
.
For example, to query an item handler from an item stack:
ItemStack stack = ...;
IItemHandler maybeHandler = stack.getCapability(Capabilities.ItemHandler.ITEM);
if (maybeHandler != null) {
// Use maybeHandler
}
Providing an item capability
To provide objects of type T
, register providers to RegisterCapabilitiesEvent
. For example:
modBus.addListener((RegisterCapabilitiesEvent event) -> {
event.registerItem(
Capabilities.ItemHandler.ITEM, // capability to register for
(itemStack, context) -> <return the IItemHandler for the itemStack>,
MY_ITEM);
});
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <T,
C extends @Nullable Object>
ItemCapability<T, C> create
(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) Creates a new item capability, or gets it if it already exists.static <T> ItemCapability
<T, @Nullable Void> createVoid
(ResourceLocation name, Class<T> typeClass) Creates a new item capability withVoid
context, or gets it if it already exists.static List
<ItemCapability<?, ?>> getAll()
返回 a new immutable copy of all the currently known item capabilities。getCapability
(ItemStack stack, C context) 从类继承的方法 net.neoforged.neoforge.capabilities.BaseCapability
contextClass, name, typeClass
-
字段详细资料
-
registry
-
providers
-
-
构造器详细资料
-
ItemCapability
-
-
方法详细资料
-
create
public static <T,C extends @Nullable Object> ItemCapability<T,C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) Creates a new item 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> ItemCapability<T,@Nullable Void> createVoid(ResourceLocation name, Class<T> typeClass) Creates a new item capability withVoid
context, or gets it if it already exists. This should be used for capabilities that do not require any additional context.- 另请参阅:
-
getAll
返回 a new immutable copy of all the currently known item capabilities。- 返回:
- a new immutable copy of all the currently known item capabilities
-
getCapability
-