接口 ItemFactory
Server.getItemFactory()
来获得.
ItemFactory类用于创建物品元数据以应用在物品上.
译者注: 本类中的元数据意为ItemMeta
原文: An instance of the ItemFactory can be obtained with Server.getItemFactory()
.
The ItemFactory is solely responsible for creating item meta containers to apply on item stacks.
-
方法概要
修饰符和类型方法说明返回一个适用于给定的ItemStack的ItemMeta返回一个适用于给定的Material的ItemMetacreateItemStack
(@NotNull String input) Create a newItemStack
given the supplied input.enchantItem
(@NotNull Entity entity, @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.enchantItem
(@NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.enchantItem
(@NotNull World world, @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.boolean
该方法用于比较两个ItemStack的元数据对象.返回所有皮甲的默认颜色.getItemMeta
(@NotNull Material material) 该方法能够为给定的Material
创建一个新的元数据。getSpawnEgg
(@NotNull EntityType type) Gets aMaterial
representing the spawn egg for the providedEntityType
.boolean
isApplicable
(@Nullable ItemMeta meta, @Nullable ItemStack stack) 该方法用于检查元数据是否能够适用于指定的ItemStack上(如果适用则物品不会丢失之前的数据).boolean
isApplicable
(@Nullable ItemMeta meta, @Nullable Material material) 该方法用于检查元数据是否能够适用于指定的Material
上(如果适用则不会丢失数据).
-
方法详细资料
-
getItemMeta
该方法能够为给定的Material
创建一个新的元数据。原文: This creates a new item meta for the material.
-
isApplicable
boolean isApplicable(@Nullable @Nullable ItemMeta meta, @Nullable @Nullable ItemStack stack) throws IllegalArgumentException 该方法用于检查元数据是否能够适用于指定的ItemStack上(如果适用则物品不会丢失之前的数据).一个
SkullMeta
对于一把剑来说是无效的, 但是一个普通的附魔泥土块的ItemMeta
会有效。 原文: This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack.A
SkullMeta
would not be valid for a sword, but a normalItemMeta
from an enchanted dirt block would.- 参数:
meta
- 需要检查的元数据stack
- 元数据将应用于的ItemStack- 返回:
- 如果ItemStack可以应用元数据并且不丢失数据, 则返回true, 否则返回false
- 抛出:
IllegalArgumentException
- 如果元数据不是由ItemFactory创建出来的则抛出此异常
-
isApplicable
boolean isApplicable(@Nullable @Nullable ItemMeta meta, @Nullable @Nullable Material material) throws IllegalArgumentException 该方法用于检查元数据是否能够适用于指定的Material
上(如果适用则不会丢失数据).一个
SkullMeta
对于一把剑来说是无效的, 但是一个普通的附魔泥土块的ItemMeta
会有效。原文: This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified Material.
A
SkullMeta
would not be valid for a sword, but a normalItemMeta
from an enchanted dirt block would.- 参数:
meta
- 需要检查的元数据material
- 元数据将应用于的Material- 返回:
- 如果可以应用元数据并且不丢失数据,则返回true,否则返回false
- 抛出:
IllegalArgumentException
- 如果元数据不是由ItemFactory创建出来的则抛出此异常
-
equals
boolean equals(@Nullable @Nullable ItemMeta meta1, @Nullable @Nullable ItemMeta meta2) throws IllegalArgumentException 该方法用于比较两个ItemStack的元数据对象.原文: This method is used to compare two item meta data objects.
- 参数:
meta1
- 第一个要比较的元数据, 元数据为null则表明没有数据meta2
- 第二个要比较的元数据, 元数据为null则表明没有数据- 返回:
- 如果其中一个元数据有数据而另一个没有, 则返回false, 否则返回true
- 抛出:
IllegalArgumentException
- 如果两个元数据都不是由ItemFactory创建出来的则抛出此异常
-
asMetaFor
@Nullable @Nullable ItemMeta asMetaFor(@NotNull @NotNull ItemMeta meta, @NotNull @NotNull ItemStack stack) throws IllegalArgumentException 返回一个适用于给定的ItemStack的ItemMeta返回的元数据将始终是指定材质的给定ItemStack的有效元数据. 它可能是一个或多或少的特定元数据,也可以是与参数相同的元数据或元类型. 返回的ItemMeta始终是最适用的Meta
例子: 如果将
SkullMeta
作应用于书本, 此方法将返回包含指定Meta的所有数据的BookMeta
, 该数据适用于最高公共接口ItemMeta
. 原文: Returns an appropriate item meta for the specified stack.The item meta returned will always be a valid meta for a given ItemStack of the specified material. It may be a more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned will also always be the most appropriate meta.
Example, if a
SkullMeta
is being applied to a book, this method would return aBookMeta
containing all information in the specified meta that is applicable to anItemMeta
, the highest common interface.- 参数:
meta
- 需要转换的元数据stack
- 给定的ItemStack- 返回:
- 返回一个适用于给定的ItemStack的ItemMeta. 不保证返回的ItemMeta是一个拷贝. 当ItemStack为AIR时, 此方法将会返回null
- 抛出:
IllegalArgumentException
- 如果元数据不是由ItemFactory创建出来的则抛出此异常
-
asMetaFor
@Nullable @Nullable ItemMeta asMetaFor(@NotNull @NotNull ItemMeta meta, @NotNull @NotNull Material material) throws IllegalArgumentException 返回一个适用于给定的Material的ItemMeta返回的元数据将始终是指定材质的给定
Material
的有效元数据. 它可能是一个或多或少的特定元数据,也可以是与参数相同的元数据或元类型. 返回的ItemMeta始终是最适用的Meta例子: 如果将
SkullMeta
作应用于书本, 此方法将返回包含指定Meta的所有数据的BookMeta
, 该数据适用于最高公共接口ItemMeta
. 原文: Returns an appropriate item meta for the specified material.The item meta returned will always be a valid meta for a given ItemStack of the specified material. It may be a more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned will also always be the most appropriate meta.
Example, if a
SkullMeta
is being applied to a book, this method would return aBookMeta
containing all information in the specified meta that is applicable to anItemMeta
, the highest common interface.- 参数:
meta
- 需要转换的ItemMetamaterial
- 给定的Material- 返回:
- 返回一个适用于给定的Material的ItemMeta. 不保证返回的ItemMeta是一个拷贝. 当ItemStack为AIR时, 此方法将会返回null
- 抛出:
IllegalArgumentException
- 如果元数据不是由ItemFactory创建出来的则抛出此异常
-
getDefaultLeatherColor
返回所有皮甲的默认颜色.原文: Returns the default color for all leather armor.
- 返回:
- 所有皮甲的默认颜色.
-
createItemStack
@NotNull @NotNull ItemStack createItemStack(@NotNull @NotNull String input) throws IllegalArgumentException Create a newItemStack
given the supplied input.The input should match the same input as expected by Minecraft's
/give
command. For example,"minecraft:diamond_sword[minecraft:enchantments={levels:{"minecraft:sharpness": 3}}]"
would yield an ItemStack ofMaterial.DIAMOND_SWORD
with anItemMeta
containing a level 3Enchantment.SHARPNESS
enchantment.- 参数:
input
- the item input string- 返回:
- the created ItemStack
- 抛出:
IllegalArgumentException
- if the input string was provided in an invalid or unsupported format
-
getSpawnEgg
Gets aMaterial
representing the spawn egg for the providedEntityType
.
Will return null for EntityTypes that do not have a corresponding spawn egg.- 参数:
type
- the entity type- 返回:
- the Material of this EntityTypes spawn egg or null
-
enchantItem
@NotNull @NotNull ItemStack enchantItem(@NotNull @NotNull Entity entity, @NotNull @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.
If an item that is air is passed through an error is thrown.- 参数:
entity
- the entity to use as a source of randomnessitem
- the item to enchantlevel
- the level to use, which is the level in the enchantment tableallowTreasures
- allows treasure enchants, e.g. mending, if true.- 返回:
- a new ItemStack containing the result of the Enchantment
-
enchantItem
@NotNull @NotNull ItemStack enchantItem(@NotNull @NotNull World world, @NotNull @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.
If an item that is air is passed through an error is thrown.- 参数:
world
- the world to use as a source of randomnessitem
- the item to enchantlevel
- the level to use, which is the level in the enchantment tableallowTreasures
- allow the treasure enchants, e.g. mending, if true.- 返回:
- a new ItemStack containing the result of the Enchantment
-
enchantItem
@NotNull @NotNull ItemStack enchantItem(@NotNull @NotNull ItemStack item, int level, boolean allowTreasures) Enchants the given item at the provided level.
If an item that is air is passed through an error is thrown.- 参数:
item
- the item to enchantlevel
- the level to use, which is the level in the enchantment tableallowTreasures
- allow treasure enchantments, e.g. mending, if true.- 返回:
- a new ItemStack containing the result of the Enchantment
-