zh_cn:tutorial:items
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:items [2024/10/27 14:37] – solidblock | zh_cn:tutorial:items [2024/12/08 14:24] (current) – [创建物品实例] solidblock | ||
---|---|---|---|
Line 6: | Line 6: | ||
===== 创建物品实例 ===== | ===== 创建物品实例 ===== | ||
:!: 如果是使用的 1.21.2 之后的版本,请直接跳到[[# | :!: 如果是使用的 1.21.2 之后的版本,请直接跳到[[# | ||
+ | |||
首先,创建 '' | 首先,创建 '' | ||
Line 185: | Line 186: | ||
如果你正确执行了所有操作,则使用该物品现在应该会播放声音。 | 如果你正确执行了所有操作,则使用该物品现在应该会播放声音。 | ||
- | ===== 如果我想更改物品的堆叠大小怎么办? | + | ===== 物品组件 ===== |
+ | 有时你会想给物品添加一些默认的物品组件,例如最大堆叠数量或防火。可以通过调用 '' | ||
+ | |||
+ | 这个例子中,物品默认不可破坏,并隐藏关于这一点的物品提示: | ||
+ | < | ||
+ | // For versions below 1.21.2: | ||
+ | public static final CustomItem CUSTOM_ITEM | ||
+ | .component(DataComponentTypes.UNBREAKABLE, | ||
+ | // For versions since 1.21.2: | ||
+ | public static final Item CUSTOM_ITEM | ||
+ | .component(DataComponentTypes.UNBREAKABLE, | ||
+ | </ | ||
+ | |||
+ | 特别地,最大堆叠数可使用 '' | ||
- | 使用 '' | ||
< | < | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | + | | |
- | | + | |
- | public static final CustomItem CUSTOM_ITEM = new CustomItem(new class_1792.class_1793().maxCount(16)); | + | // For versions below 1.21.2: |
+ | public static final CustomItem CUSTOM_ITEM = register(" | ||
+ | // For versions since 1.21.2: | ||
+ | public static final Item CUSTOM_ITEM = register(" | ||
[...] | [...] | ||
} | } | ||
</ | </ | ||
+ | |||
===== 让物品能作为燃料或者可堆肥 ===== | ===== 让物品能作为燃料或者可堆肥 ===== |
zh_cn/tutorial/items.1730039869.txt.gz · Last modified: 2024/10/27 14:37 by solidblock