接口 ItemFactory


public interface ItemFactory
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.

  • 方法详细资料

    • getItemMeta

      该方法能够为给定的Material创建一个新的元数据。

      原文: This creates a new item meta for the material.

      参数:
      material - 给定的材质
      返回:
      利用给定的Material返回这个Material所对应的ItemMeta, 并且只能用于Type为给定的Material的ItemStack上
    • isApplicable

      该方法用于检查元数据是否能够适用于指定的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 normal ItemMeta 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 normal ItemMeta from an enchanted dirt block would.

      参数:
      meta - 需要检查的元数据
      material - 元数据将应用于的Material
      返回:
      如果可以应用元数据并且不丢失数据,则返回true,否则返回false
      抛出:
      IllegalArgumentException - 如果元数据不是由ItemFactory创建出来的则抛出此异常
    • equals

      该方法用于比较两个ItemStack的元数据对象.

      原文: This method is used to compare two item meta data objects.

      参数:
      meta1 - 第一个要比较的元数据, 元数据为null则表明没有数据
      meta2 - 第二个要比较的元数据, 元数据为null则表明没有数据
      返回:
      如果其中一个元数据有数据而另一个没有, 则返回false, 否则返回true
      抛出:
      IllegalArgumentException - 如果两个元数据都不是由ItemFactory创建出来的则抛出此异常
    • asMetaFor

      返回一个适用于给定的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 a BookMeta containing all information in the specified meta that is applicable to an ItemMeta, the highest common interface.

      参数:
      meta - 需要转换的元数据
      stack - 给定的ItemStack
      返回:
      返回一个适用于给定的ItemStack的ItemMeta. 不保证返回的ItemMeta是一个拷贝. 当ItemStack为AIR时, 此方法将会返回null
      抛出:
      IllegalArgumentException - 如果元数据不是由ItemFactory创建出来的则抛出此异常
    • asMetaFor

      返回一个适用于给定的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 a BookMeta containing all information in the specified meta that is applicable to an ItemMeta, the highest common interface.

      参数:
      meta - 需要转换的ItemMeta
      material - 给定的Material
      返回:
      返回一个适用于给定的Material的ItemMeta. 不保证返回的ItemMeta是一个拷贝. 当ItemStack为AIR时, 此方法将会返回null
      抛出:
      IllegalArgumentException - 如果元数据不是由ItemFactory创建出来的则抛出此异常
    • getDefaultLeatherColor

      @NotNull @NotNull Color getDefaultLeatherColor()
      返回所有皮甲的默认颜色.

      原文: Returns the default color for all leather armor.

      返回:
      所有皮甲的默认颜色.
    • createItemStack

      Create a new ItemStack given the supplied input.

      The input should match the same input as expected by Minecraft's /give command. For example, "minecraft:diamond_sword{Enchantments:[{id:"minecraft:sharpness", lvl:3}]}" would yield an ItemStack of Material.DIAMOND_SWORD with an ItemMeta containing a level 3 Enchantment.DAMAGE_ALL enchantment.

      参数:
      input - the item input string
      返回:
      the created ItemStack
      抛出:
      IllegalArgumentException - if the input string was provided in an invalid or unsupported format
    • updateMaterial

      已过时。
      for internal use only
      Apply a material change for an item meta. Do not use under any circumstances.
      参数:
      meta - meta
      material - material
      返回:
      updated material
      抛出:
      IllegalArgumentException - if bad material or data