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.


最大耐久度

public Item.Settings maxDamage(int maxDamage)

maxDamage - 物品在物品堆中的最大耐久度。


合成剩余物

public Item.Settings recipeRemainder(Item recipeRemainder)

recipeRemainder - 原物品在合成完成之后返回的物品

有设置了合成剩余物的物品在合成后会将剩余物返回给玩家。设置了该属性的物品有桶(岩浆、水、牛奶)和瓶子(龙息、蜂蜜),合成过后则会返回对应的空物品。


物品组

public Item.Settings group(ItemGroup group)

group - 该物品加入的ItemGroup(物品组)

每个物品组都会被显示为创造模式物品栏中的一个标签页,将物品添加进该组则会将该物品加入标签页中,而显示的顺序由注册的顺序决定。若要添加一个新物品组请见这里


稀有度

public Item.Settings rarity(Rarity rarity)

rarity - 该物品的稀有度。(默认为常见)

有自定义的稀有度的物品名称会变成不同的颜色。

稀有度 字体颜色
常见 白色
少见 黄色
稀有 青色
史诗 淡紫色
zh_cn/tutorial/items_docs.1604285985.txt.gz · Last modified: 2020/11/02 02:59 by leocth2