User Tools

Site Tools


zh_cn:tutorial:items_docs

This is an old revision of the document!


物品

Items are the pieces of content that appear in your inventory. They can perform actions when you click, act as food, or spawn entities. The following documentation will give you a rundown of the entire Item class and everything related to it. For a tutorial you can follow along, visit Practical Example: Adding an Item.

物品设置

Item(物品类)的构造方法(constructor)需要一个Item.Settings(物品设置类)的实例。该建造者类(builder class)定义物品的诸多行为,例如堆叠数量、耐久度、是否可食用、等等。以下是所有可用的建造者方法:

方法 参数类型 简介
food FoodComponent 设置该物品的FoodComponent(食品部分)为参数值,并标记该物品可食用。
maxCount int 设置该物品的最大堆叠数量为参数值。与大于0的耐久度冲突。
maxDamageIfAbsent int 若该物品未设置最大耐久度以及堆叠数量不大于1,则设置最大耐久度为参数值。
maxDamage int 设置该物品的最大耐久度。(与大于1的最大堆叠数量冲突,并且会在注册时报错!
recipeRemainder Item 设置该物品的合成后所偿还给玩家的物品(如牛奶桶偿还的物品则是空桶)。
group ItemGroup 设置该物品的物品组(即创造物品栏中的标签页)。
rarity Rarity 设置该物品的稀有度,而其也决定了物品名称的默认显示颜色。

Food

public Item.Settings food(FoodComponent foodComponent)

foodComponent - instance of'FoodComponent. When set, the Item will be edible based on the settings provided by the FoodComponent builder. For an in-depth explanation of the available options, view the FoodComponent Overview page.


Max Stack Count

public Item.Settings maxCount(int maxCount)

maxCount - the maximum count of an ItemStack for the given Item. If maxDamage() has already been called, a RuntimeException is thrown, as an Item cannot have both damage and count. Keeping the max count at or below 64 is recommended, as any value above that can lead to various issues.


Max Damage if Absent

public Item.Settings maxDamageIfAbsent(int maxDamage)

maxDamage - max durability of the given Item when in ItemStack form.

If maxDamage() has not been called yet, the max durability of the Item is set to the value passed in. This is used for cases such as tools and armor, where the Item's durability is only set to the ToolMaterial's durability if it has not been set yet.


Max Damage

public Item.Settings maxDamage(int maxDamage)

maxDamage - max durability of the given Item when in ItemStack form.


Recipe Remainder

public Item.Settings recipeRemainder(Item recipeRemainder)

recipeRemainder - Item to return as a remainder when the base Item is used in a crafting recipe.

When a recipe remainder is set on an Item, any recipe using that Item will return the remainder on craft. This is used for buckets (Water, Lava, Milk) and bottles (Dragon Breath, Honey) returning their respective empty items when used in recipes.


Group

public Item.Settings group(ItemGroup group)

group - ItemGroup to add Item in.

Each ItemGroup appears as a tab in the creative inventory. Adding an Item to this group will add it to the tab. The order of the group is based on registry order. For more information on creating a group, see the ItemGroups page.


Rarity

public Item.Settings rarity(Rarity rarity)

rarity - Rarity of the given Item.

If Rarity is set, the given Item will have a custom name color. An Item's Rarity defaults to common.

Rarity Color
Common White
Uncommon Yellow
Rare Aqua
Epic Light Purple
zh_cn/tutorial/items_docs.1604158058.txt.gz · Last modified: 2020/10/31 15:27 by leocth2