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/01/16 06:23] – [注册物品] 更新代码 solidblock | zh_cn:tutorial:items [2022/12/16 00:05] – [添加物品纹理] solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 添加一个物品 ====== | + | ====== 添加物品 ====== |
==== 介绍 ==== | ==== 介绍 ==== | ||
- | 添加一个基本的物品是编写模组的第一步。 你将需要创建一个'' | + | 添加一个基本的物品是编写模组的第一步。你将需要创建一个 '' |
==== 注册物品 ==== | ==== 注册物品 ==== | ||
- | 首先,创建一个'' | + | 首先,创建一个 '' |
- | <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 { | ||
- | 为物品注册材质需要物品模型.json文件和材质图像文件。 您将需要将它们添加到资源目录中。每个的直接路径是: | + | // 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())); | ||
- | 物品模型: | + | |
- | 物品材质: < | + | public void onInitialize() { |
- | 我们将使用[[https:// | + | } |
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 添加物品纹理 ==== | ||
+ | |||
+ | 为物品注册纹理需要物品模型.json文件和纹理图像文件。 您将需要将它们添加到资源目录中。每个的直接路径是: | ||
+ | |||
+ | | ||
+ | 物品纹理: < | ||
+ | 我们将使用[[https:// | ||
- | 如果您在第一步中正确注册了物品,则游戏将以类似于以下方式的方式抱怨缺少材质文件: | + | 如果您在第一步中正确注册了物品,则游戏将以类似于以下方式的方式抱怨缺少纹理文件: |
- | [Server-Worker-1/ | + | [Server-Worker-1/ |
游戏能很方便地告诉你它想要的资源路径。遇事不决,日志解决。 | 游戏能很方便地告诉你它想要的资源路径。遇事不决,日志解决。 | ||
Line 48: | Line 60: | ||
<code JavaScript> | <code JavaScript> | ||
{ | { | ||
- | " | + | " |
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
</ | </ | ||
- | 物品模型会将所有属性继承自父模型,例如对工具、方块等物品十分有用的自定义手持模型('' | + | 物品模型会将所有属性继承自父模型,例如对工具、方块等物品十分有用的自定义手持模型('' |
- | 最终材质的结果: | + | 最终纹理的结果: |
{{: | {{: | ||
Line 64: | Line 76: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class FabricItem extends Item { | public class FabricItem extends Item { | ||
- | | + | |
- | | + | |
super(settings); | super(settings); | ||
} | } | ||
Line 73: | Line 85: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class FabricItem extends Item { | public class FabricItem extends Item { | ||
- | | + | |
- | | + | |
super(settings); | super(settings); | ||
} | } | ||
Line 90: | Line 102: | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
// | // | ||
- | public static final FabricItem FABRIC_ITEM = new FabricItem(new | + | public static final FabricItem FABRIC_ITEM = new FabricItem(new |
[...] | [...] | ||
} | } | ||
Line 98: | Line 110: | ||
==== 如果我想更改物品的堆叠大小怎么办? | ==== 如果我想更改物品的堆叠大小怎么办? | ||
- | 使用' | + | 使用'' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
// | // | ||
- | public static final FabricItem FABRIC_ITEM = new FabricItem(new | + | public static final FabricItem FABRIC_ITEM = new FabricItem(new |
[...] | [...] | ||
} | } |
zh_cn/tutorial/items.txt · Last modified: 2024/04/15 01:25 by solidblock