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 [2022/12/16 00:07] – [创建物品类] solidblock | zh_cn:tutorial:items [2024/04/15 01:25] (current) – [如果我想更改物品的堆叠大小怎么办?] solidblock | ||
---|---|---|---|
Line 5: | Line 5: | ||
添加一个基本的物品是编写模组的第一步。你将需要创建一个 '' | 添加一个基本的物品是编写模组的第一步。你将需要创建一个 '' | ||
==== 注册物品 ==== | ==== 注册物品 ==== | ||
- | 首先,创建一个 '' | + | 首先,创建一个 '' |
< | < | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
Line 13: | Line 13: | ||
} | } | ||
</ | </ | ||
- | 这里使用原版注册方式来注册,基本语法是 '' | + | 这里使用原版注册方式来注册,基本语法是 '' |
< | < | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
// 新物品的实例 | // 新物品的实例 | ||
+ | // 对于 1.20.4 之前版本 | ||
public static final class_1792 CUSTOM_ITEM = new class_1792(new FabricItemSettings()); | public static final class_1792 CUSTOM_ITEM = new class_1792(new FabricItemSettings()); | ||
+ | // 对于 1.20.5 之后版本 | ||
+ | public static final class_1792 CUSTOM_ITEM = new class_1792(new class_1792.class_1793()); | ||
@Override | @Override | ||
Line 25: | Line 28: | ||
} | } | ||
</ | </ | ||
- | 现在新物品已添加到 Minecraft 中,运行“Minecraft Client”运行配置或者 '' | + | 现在新物品已添加到 Minecraft 中,运行“Minecraft Client”运行配置或者 '' |
{{: | {{: | ||
Line 36: | Line 39: | ||
public static final class_1792 CUSTOM_ITEM = | public static final class_1792 CUSTOM_ITEM = | ||
class_2378.method_10230(class_7923.field_41178, | class_2378.method_10230(class_7923.field_41178, | ||
- | new class_1792(new | + | new class_1792(new |
@Override | @Override | ||
Line 91: | Line 94: | ||
@Override | @Override | ||
- | public class_1271< | + | public class_1271< |
playerEntity.method_5783(class_3417.field_14983, | playerEntity.method_5783(class_3417.field_14983, | ||
return class_1271.method_22427(playerEntity.method_5998(hand)); | return class_1271.method_22427(playerEntity.method_5998(hand)); | ||
Line 103: | Line 106: | ||
// 新物品的实例 | // 新物品的实例 | ||
- | public static final CustomItem CUSTOM_ITEM = new CustomItem(new | + | public static final CustomItem CUSTOM_ITEM = new CustomItem(new |
[...] | [...] | ||
} | } | ||
Line 111: | Line 114: | ||
==== 如果我想更改物品的堆叠大小怎么办? | ==== 如果我想更改物品的堆叠大小怎么办? | ||
- | 使用'' | + | 使用 '' |
- | <code java [enable_line_numbers=" | + | <yarncode |
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | // | + | // 我们新物品的实例,最大堆叠大小为16 |
- | public static final FabricItem FABRIC_ITEM | + | public static final CustomItem CUSTOM_ITEM |
[...] | [...] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 让物品能作为燃料或者可堆肥 ==== | ||
+ | |||
+ | 如果需要让物品能作为燃料在熔炉中燃烧,可以使用 '' | ||
+ | <code java> | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | [...] | ||
+ | | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | [...] | ||
+ | FuelRegistry.INSTANCE.add(CUSTOM_ITEM, | ||
+ | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | 类似地,你也可以使用 '' | ||
==== 下一步 ==== | ==== 下一步 ==== | ||
试着[[zh_cn: | 试着[[zh_cn: |
zh_cn/tutorial/items.1671149253.txt.gz · Last modified: 2022/12/16 00:07 by solidblock