zh_cn:tutorial:items
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
zh_cn:tutorial:items [2021/12/03 15:32] – [注册物品] solidblock | zh_cn:tutorial:items [2022/12/16 00:03] – solidblock | ||
---|---|---|---|
Line 3: | Line 3: | ||
==== 介绍 ==== | ==== 介绍 ==== | ||
- | 添加一个基本的物品是编写模组的第一步。 你将需要创建一个'' | + | 添加一个基本的物品是编写模组的第一步。你将需要创建一个 '' |
==== 注册物品 ==== | ==== 注册物品 ==== | ||
- | 首先,创建一个'' | + | 首先,创建一个 '' |
- | <code java [enable_line_numbers=" | + | <yarncode |
- | public class ExampleMod implements ModInitializer | + | public class ExampleMod implements ModInitializer { |
- | { | + | |
// 新物品的实例 | // 新物品的实例 | ||
- | public static final Item FABRIC_ITEM | + | public static final class_1792 CUSTOM_ITEM |
[...] | [...] | ||
} | } | ||
- | </code> | + | </yarncode> |
- | 这里使用原版注册方式来注册,基本语法是'' | + | 这里使用原版注册方式来注册,基本语法是 '' |
- | <code java [enable_line_numbers=" | + | <yarncode |
- | public class ExampleMod implements ModInitializer | + | public class ExampleMod implements ModInitializer { |
- | { | + | |
// 新物品的实例 | // 新物品的实例 | ||
- | public static final Item FABRIC_ITEM | + | public static final class_1792 CUSTOM_ITEM |
- | + | ||
@Override | @Override | ||
- | public void onInitialize() | + | public void onInitialize() { |
- | | + | |
- | | + | } |
- | } | + | |
} | } | ||
- | </code> | + | </yarncode> |
- | 现在新物品已添加到Minecraft中,运行'' | + | 现在新物品已添加到 Minecraft 中,运行“Minecraft Client”运行配置或者 |
{{: | {{: | ||
+ | |||
+ | 为了简便,也可以像这样简化代码: | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // an instance of our new item | ||
+ | public static final class_1792 CUSTOM_ITEM = | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | new class_1792(new FabricItemSettings())); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== 添加物品纹理 ==== | ==== 添加物品纹理 ==== |
zh_cn/tutorial/items.txt · Last modified: 2024/04/15 01:25 by solidblock