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 [2023/11/18 08:35] – solidblock | zh_cn:tutorial:blocks [2024/04/15 01:52] (current) – [自定义形状] solidblock | ||
---|---|---|---|
Line 19: | Line 19: | ||
| | ||
*/ | */ | ||
- | //public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).hardness(4.0f)); // fabric api 版本 | + | |
- | public static final Block EXAMPLE_BLOCK | + | // 对于 1.20 以下版本: |
+ | | ||
+ | | ||
+ | // public static final Block EXAMPLE_BLOCK | ||
+ | // 对于自 1.20.5 之后的版本: | ||
+ | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
+ | | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Line 36: | Line 42: | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | + | |
+ | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | ||
+ | // 对于 1.20.5 以下版本: | ||
+ | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | ||
+ | // 对于自 1.20.5 之后的版本: | ||
+ | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
@Override | @Override | ||
Line 54: | Line 65: | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | + | |
+ | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | ||
+ | // 对于 1.20.5 以下版本: | ||
+ | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | ||
+ | // 对于自 1.20.5 之后的版本: | ||
+ | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Registry.register(Registries.BLOCK, | Registry.register(Registries.BLOCK, | ||
- | Registry.register(Registries.ITEM, | + | |
+ | // Registry.register(Registries.ITEM, | ||
+ | // 对于自 1.20.5 之后的版本: | ||
+ | Registry.register(Registries.ITEM, | ||
} | } | ||
} | } | ||
Line 162: | Line 181: | ||
</ | </ | ||
- | 对于采集等级标签('' | + | 对于采集等级标签('' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public static final Block EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.create().strength(4.0f).requiresTool()); | + | public static final Block EXAMPLE_BLOCK = new ExampleBlock(Block.Settings.create().strength(4.0f).requiresTool()); |
</ | </ | ||
Line 190: | Line 209: | ||
} | } | ||
+ | // 对于 1.20.5 以下版本,方法参数应该是“BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit” | ||
@Override | @Override | ||
- | public ActionResult onUse(BlockState state, | + | public ActionResult onUse(World world, PlayerEntity player, BlockHitResult hit) { |
if (!world.isClient) { | if (!world.isClient) { | ||
player.sendMessage(Text.literal(" | player.sendMessage(Text.literal(" | ||
Line 206: | Line 226: | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | public static final ExampleBlock EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.create().hardness(4.0f)); | + | public static final ExampleBlock EXAMPLE_BLOCK = new ExampleBlock(Block.Settings.create().strength(4.0f)); |
| | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Registry.register(Registries.BLOCK, | Registry.register(Registries.BLOCK, | ||
- | Registry.register(Registries.ITEM, | + | Registry.register(Registries.ITEM, |
} | } | ||
} | } | ||
Line 238: | Line 258: | ||
{{: | {{: | ||
+ | 你也可以定义其他几类方块形状,方块形状的类型包括: | ||
+ | * **外观形状(outline shape)**:方块大多数类型的形状都使用这个值作为默认。在世界中,当你指向这个形状时,会根据此形状绘制道明的黑色边框。大多数时候,这个形状不应该是空的。 | ||
+ | * **碰撞形状(collision shape)**:用于计算碰撞的形状。实体(包括玩家)移动时,其碰撞箱通常不能与方块的碰撞形状重合。一些方块,例如栅栏和墙,碰撞形状高于一格。一些方块,例如花,碰撞形状是空的。除了修改 '' | ||
+ | * **raycasting shape**:用于计算视线投射(判断你正在指向哪个方块的过程)的形状。通过不需要指定。 | ||
+ | * **相机碰撞形状(camera collision shape)**:用于计算第三人称视角的相机的位置的形状。玻璃和细雪的相机碰撞形状为空。 | ||
===== 下一步 ===== | ===== 下一步 ===== | ||
[[zh_cn: | [[zh_cn: |
zh_cn/tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock