接口 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

      根据提供的输入创建一个新的ItemStack。

      输入应与Minecraft的/give命令期望的输入格式相同。例如,

      "minecraft:diamond_sword[minecraft:enchantments={levels:{"minecraft:sharpness": 3}}]"
      将生成一个Material.DIAMOND_SWORD的ItemStack,其ItemMeta包含 3级的Enchantment.SHARPNESS附魔。

      原文: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[minecraft:enchantments={levels:{"minecraft:sharpness": 3}}]"
      would yield an ItemStack of Material.DIAMOND_SWORD with an ItemMeta containing a level 3 Enchantment.SHARPNESS enchantment.
      参数:
      input - 物品输入字符串
      返回:
      创建的ItemStack
      抛出:
      IllegalArgumentException - 如果输入字符串的格式无效或不支持
    • getSpawnEgg

      获取代表指定EntityType刷怪蛋的Material。
      对于没有对应刷怪蛋的实体类型,将返回null。

      原文:Gets a Material representing the spawn egg for the provided EntityType.
      Will return null for EntityTypes that do not have a corresponding spawn egg.

      参数:
      type - 实体类型
      返回:
      该实体类型的刷怪蛋Material,如果没有则返回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 - 用作随机源的实体
      item - 要附魔的物品
      level - 要使用的等级,即附魔台中的等级
      allowTreasures - 如果为true,允许宝藏附魔,例如经验修补
      返回:
      包含附魔结果的新ItemStack
    • 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 - 用作随机源的世界
      item - 要附魔的物品
      level - 要使用的等级,即附魔台中的等级
      allowTreasures - 如果为true,允许宝藏附魔,例如经验修补
      返回:
      包含附魔结果的新ItemStack
    • 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 - 要附魔的物品
      level - 要使用的等级,即附魔台中的等级
      allowTreasures - 如果为true,允许宝藏附魔,例如经验修补
      返回:
      包含附魔结果的新ItemStack
    • createExplorerMap

      @NotNull @NotNull ItemStack createExplorerMap(@NotNull @NotNull World world, @NotNull @NotNull Location structureLocation, @NotNull MapCursor.Type mapIcon)
      Create a new explorer map targeting the given structure location.
      参数:
      world - the world the map will belong to
      structureLocation - the location of the structure
      mapIcon - the icon displayed for the given structure
      返回:
      the newly created item stack