tutorial:blocks
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:blocks [2021/01/30 12:04] – updating to latest mappings and fixing continuity errors leocth2 | tutorial:blocks [2022/07/17 11:57] – A not available function has been changed(new LiteralText -> Text.of), becuase it cannot work properly. luo_tian_wy | ||
---|---|---|---|
Line 30: | Line 30: | ||
==== Registering your Block ==== | ==== Registering your Block ==== | ||
- | Blocks should be registered under the '' | + | Blocks should be registered under the '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 133: | Line 133: | ||
] | ] | ||
} | } | ||
+ | </ | ||
+ | |||
+ | In minecraft 1.17, there has been a change for breaking blocks. Now, to define harvest tools and harvest levels, we need to use tags. Read about tags at: [[tutorial: | ||
+ | |||
+ | Harvest tool: src/ | ||
+ | Harvest level: src/ | ||
+ | |||
+ | <code JavaScript src/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code JavaScript src/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | For the harvest level tags (needs_stone_tool, | ||
+ | |||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public static final Block EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.of(Material.METAL).strength(4.0f).requiresTool()); | ||
</ | </ | ||
===== Creating a Custom Block Class ===== | ===== Creating a Custom Block Class ===== | ||
- | The above approach works well for simple | + | The above approach works well for simple |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 160: | Line 190: | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
if (!world.isClient) { | if (!world.isClient) { | ||
- | player.sendMessage(new LiteralText(" | + | player.sendMessage(Text.of(" |
} | } | ||
Line 170: | Line 200: | ||
To use your custom block class, replace //new Block// with //new ExampleBlock//: | To use your custom block class, replace //new Block// with //new ExampleBlock//: | ||
- | <code java [enable_line_numbers=" | + | <code java [enable_line_numbers=" |
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | public static final ExampleBlock EXAMPLE_BLOCK = new ExampleBlock(Block.Settings.of(Material.STONE).hardness(4.0f)); | + | public static final ExampleBlock EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.of(Material.STONE).hardness(4.0f)); |
| | ||
@Override | @Override | ||
Line 191: | Line 221: | ||
To fix this, we have to define the '' | To fix this, we have to define the '' | ||
- | < | + | < |
- | | + | public class ExambleBlock extends Block { |
- | | + | [...] |
- | | + | |
- | } | + | public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { |
+ | return VoxelShapes.cuboid(0f, | ||
+ | } | ||
+ | } | ||
</ | </ | ||
Line 206: | Line 239: | ||
[[tutorial: | [[tutorial: | ||
+ | |||
+ | To make your block flammable (that is, can be burned in fire), you may use '' |
tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock