zh_cn:tutorial:blocks
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:blocks [2024/08/26 01:21] – solidblock | zh_cn:tutorial:blocks [2024/12/08 14:23] (current) – [下一步] solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 添加方块 ====== | ====== 添加方块 ====== | ||
- | 将方块添加到你的模组过程与[[zh_cn: | + | 将方块添加到你的模组过程与[[zh_cn: |
===== 创建方块 ===== | ===== 创建方块 ===== | ||
+ | :!: 使用你使用的是 1.21.2 或者之后的版本,请直接看 [[#在 1.21.2+ 中注册方块]]。 | ||
首先创建 '' | 首先创建 '' | ||
Line 24: | Line 25: | ||
// 对于 1.20.5 以下版本: | // 对于 1.20.5 以下版本: | ||
// public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | ||
- | // 对于自 1.20.5 之后的版本: | + | // 对于自 1.20.5 之后、1.21.2 以前的版本: |
public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
Line 46: | Line 47: | ||
// 对于 1.20.5 以下版本: | // 对于 1.20.5 以下版本: | ||
// public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | ||
- | // 对于自 1.20.5 之后的版本: | + | // 对于自 1.20.5 之后、1.21.2 以前的版本: |
public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
Line 72: | Line 73: | ||
// 对于 1.20.5 以下版本: | // 对于 1.20.5 以下版本: | ||
// public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | ||
- | // 对于自 1.20.5 之后的版本: | + | // 对于自 1.20.5 之后、1.21.2 之前的版本: |
public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
Line 89: | Line 90: | ||
===== 注册方块的最佳实践 ===== | ===== 注册方块的最佳实践 ===== | ||
+ | :!: 本段不适用于 1.21.2 之后的版本。 | ||
+ | |||
有时你的模组有许多方块。如果这样注册,你会为每个方块都写这样复杂的代码,代码就会显乱。所以,类似于注册物品,我们为方块创建单独的类,以及一个实用方法以注册方块和物品。 | 有时你的模组有许多方块。如果这样注册,你会为每个方块都写这样复杂的代码,代码就会显乱。所以,类似于注册物品,我们为方块创建单独的类,以及一个实用方法以注册方块和物品。 | ||
Line 115: | Line 118: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== 在 1.21.2+ 中注册方块 ===== | ||
+ | 在 1.21.2+ 中,要把 '' | ||
+ | |||
+ | <code java> | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | public static final Block EXAMPLE_BLOCK = register(" | ||
+ | |||
+ | private static Block register(String path, Function< | ||
+ | final Identifier identifier = Identifier.of(" | ||
+ | final RegistryKey< | ||
+ | |||
+ | final Block block = Blocks.register(registryKey, | ||
+ | Items.register(block); | ||
+ | return block; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 上面的代码中,'' | ||
===== 给予方块外观 ===== | ===== 给予方块外观 ===== | ||
Line 195: | Line 218: | ||
在 1.17,破坏方块有所改变,定义采集工具和采集等级需要使用标签,请参考[[zh_cn: | 在 1.17,破坏方块有所改变,定义采集工具和采集等级需要使用标签,请参考[[zh_cn: | ||
- | * 采集工具:'' | + | |
- | * 采集等级:'' | + | * 采集等级:'' |
<code JavaScript src/ | <code JavaScript src/ | ||
Line 297: | Line 320: | ||
[[zh_cn: | [[zh_cn: | ||
- | [[zh_cn: | + | [[zh_cn: |
要让方块可燃(也就是说,可以被火燃烧),可使用 '' | 要让方块可燃(也就是说,可以被火燃烧),可使用 '' |
zh_cn/tutorial/blocks.1724635278.txt.gz · Last modified: 2024/08/26 01:21 by solidblock