For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/ItemFoodComponent.md.

Class: ItemFoodComponent

component

Beta

表示物品食物组件。当出现在物品上时,实体可以消耗此物品。 注意,只能在数驱物品上获取和使用该组件。

When present on an item, this item is consumable by entities. Note that this component only applies to data-driven items.

Extends

Properties

canAlwaysEat

readonly canAlwaysEat: boolean

Beta

Remarks

若为 true ,则无论饥饿值是否已满,玩家始终可以食用该物品。

If true, the player can always eat this item (even when not hungry).

Throws

This property can throw when used.


isValid

readonly isValid: boolean

Beta

Remarks

返回该组件是否有效。如果组件的拥有者有效,并且满足组件所需的任何额外验证,则该组件被视为有效。

Returns whether the component is valid. A component is considered valid if its owner is valid, in addition to any addition to any additional validation required by the component.

Inherited from

ItemComponent.isValid


nutrition

readonly nutrition: number

Beta

Remarks

表示实体在食用该物品后恢复的饥饿值,即营养值。

Represents how much nutrition this food item will give an entity when eaten.

Throws

This property can throw when used.


saturationModifier

readonly saturationModifier: number

Beta

Remarks

当一个物品被食用, 将根据公式 nutrition * saturation_modifier * 2 来为玩家添加饱和状态。

When an item is eaten, this value is used according to this formula (nutrition * saturation_modifier * 2) to apply a saturation buff.

Throws

This property can throw when used.


typeId

readonly typeId: string

Beta

Remarks

组件的标识符。

Identifier of the component.

Inherited from

ItemComponent.typeId


usingConvertsTo

readonly usingConvertsTo: string

Beta

Remarks

若给出,则使用时将该物品转换为标识符指定的物品。

When specified, converts the active item to the one specified by this property.

Throws

This property can throw when used.


componentId

readonly static componentId: "minecraft:food" = 'minecraft:food'

Beta

同领域相关