User Tools

Site Tools


zh_cn:tutorial:items_docs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
zh_cn:tutorial:items_docs [2020/11/02 02:59] – bits and pieces leocth2zh_cn:tutorial:items_docs [2023/11/18 08:00] (current) solidblock
Line 1: Line 1:
 +:!: 此页面已存档。
 ====== 物品 ====== ====== 物品 ======
-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 [[tutorial:items|Practical Example: Adding an Item]].+物品是你物品栏中占据一个一个格子的内容。它们可以在右击的时候执行操作,食用,或生成实体。以下是整个''Item''(物品)类与其相关部件的简介。如果你需要一个可以边做边学的例子,请见我们[[zh_cn:tutorial:items|添加物品的教程]]
  
 ===== 物品设置 ===== ===== 物品设置 =====
  
-''Item''(物品类)的构造方法(constructor)需要一个''Item.Settings''(物品设置类)的实例。该建造者(builder class)定义物品的诸多行为,例如堆叠数量、耐久度、是否可食用等等。以下是所有可用的建造者方法:+''Item'' 的构造方法需要一个 ''Item.Settings'' 的实例,这个类定义物品的诸多行为,例如堆叠数量、耐久度、是否可食用等等。以下是所有可用的方法:
  
 ^ 方法      ^ 参数类型         ^ 简介          ^ ^ 方法      ^ 参数类型         ^ 简介          ^
Line 12: Line 13:
 | maxDamage | ''int'' | 设置该物品的最大耐久度。(与大于1的最大堆叠数量冲突,**并且会在注册时报错!**)| | maxDamage | ''int'' | 设置该物品的最大耐久度。(与大于1的最大堆叠数量冲突,**并且会在注册时报错!**)|
 | recipeRemainder | ''Item'' | 设置该物品的合成剩余物(即合成后偿还给玩家的物品)。| | recipeRemainder | ''Item'' | 设置该物品的合成剩余物(即合成后偿还给玩家的物品)。|
-| group | ''ItemGroup'' | 设置该物品的物品组(即创造物品栏中的标签页)。 | 
 | rarity | ''Rarity'' | 设置该物品的稀有度,而其也决定了物品名称的默认显示颜色。| | rarity | ''Rarity'' | 设置该物品的稀有度,而其也决定了物品名称的默认显示颜色。|
 +| fireproof | None | 使物品防火,不被熔岩和火破坏。|
 +
 +===== Fabric物品设置 =====
 +Fabric的物品API提供了一些额外的方法来设置一些其他属性。要使用这些新方法,只需要将''new Item.Settings()''替换成''new FabricItemSettings()''即可。
 +下列是所有''FabricItemSettings''提供的额外功能:
 +
 +^ 方法      ^ 参数类型         ^ 简介          ^
 +| equipmentSlot | ''EquipmentSlotProvider'' | 设置物品如何提供并指定装备槽。 |
 +| customDamage | ''CustomDamageHandler'' | 设置物品如何自定义处理伤害变化。 |
  
 ---- ----
  
-==== Food ====+==== 食物 ====
 <code java> <code java>
 public Item.Settings food(FoodComponent foodComponent) public Item.Settings food(FoodComponent foodComponent)
 </code> </code>
-''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.+''foodComponent''一个''FoodComponent''对象。设置时物品的可食属性会根据''FoodComponent''的值而变化。更深一步的讲解请见FoodComponent的简介页。
  
 ---- ----
  
-==== Max Stack Count ====+==== 最大堆叠数量 ====
 <code java> <code java>
 public Item.Settings maxCount(int maxCount) public Item.Settings maxCount(int maxCount)
 </code> </code>
-''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.+''maxCount''物品在物品堆中可堆叠的最大数量。如果之前已经调用过''maxDamage()'',游戏会抛出一个''RuntimeException''(运行时异常),因为一个物品无法同时拥有数量与耐久度。推荐将最大堆叠数量设为64以下的值,更高的值可能会引发许多问题。
  
 ---- ----
  
-==== Max Damage if Absent ====+==== 若未设置则设置最大耐久度 ====
 <code java> <code java>
 public Item.Settings maxDamageIfAbsent(int maxDamage) public Item.Settings maxDamageIfAbsent(int maxDamage)
 </code> </code>
-''maxDamage''max durability of the given ''Item'' when in ''ItemStack'' form. +''maxDamage''物品在物品堆中的最大耐久度。
  
-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.+如果之前还没有调用过''maxDamage()'',则会将最大耐久度设成参数的值。工具和盔甲//在没有设置耐久度时//会使用此方法来将物品的最大耐久度设置为工具材料(''ToolMaterial'')的最大耐久度。
  
 ---- ----
Line 57: Line 66:
 ''recipeRemainder'' - 原物品在合成完成之后返回的物品 ''recipeRemainder'' - 原物品在合成完成之后返回的物品
  
-有设置了合成剩余物的物品在合成后会将剩余物返回给玩家。设置了该属性的物品有桶(岩、水、牛奶)和瓶子(龙息、蜂蜜),合成过后则会返回对应的空物品。+有设置了合成剩余物的物品在合成后会将剩余物返回给玩家。设置了该属性的物品有桶(岩、水、牛奶)和瓶子(龙息、蜂蜜),合成过后则会返回对应的空物品。
  
 ---- ----
  
-==== 物品组 ==== 
-<code java> 
-public Item.Settings group(ItemGroup group) 
-</code> 
-''group'' - 该物品加入的''ItemGroup''(物品组) 
- 
-每个物品组都会被显示为创造模式物品栏中的一个标签页,将物品添加进该组则会将该物品加入标签页中,而显示的顺序由注册的顺序决定。若要添加一个新物品组请见[[tutorial:itemgroup|这里]]。 
- 
----- 
  
 ==== 稀有度 ==== ==== 稀有度 ====
Line 83: Line 83:
 | 稀有 | 青色 | | 稀有 | 青色 |
 | 史诗 | 淡紫色 | | 史诗 | 淡紫色 |
 +
 +==== 防火 ====
 +<code java>
 +public Item.Settings fireproof()
 +</code>
 +
 +使物品防火,包含此物品的物品实体不被火和熔岩烧毁。
zh_cn/tutorial/items_docs.1604285985.txt.gz · Last modified: 2020/11/02 02:59 by leocth2