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 [2020/08/01 16:30] – update mappings for EntityContext draylar | tutorial:blocks [2022/04/20 18:08] – fixed wrong namespaces ayutac | ||
---|---|---|---|
Line 11: | Line 11: | ||
/* Declare and initialize our custom block instance. | /* Declare and initialize our custom block instance. | ||
- | We set our block material to METAL, which requires a pickaxe to efficiently break. | + | We set our block material to `METAL`, which requires a pickaxe to efficiently break. |
- | | + | |
+ | | ||
+ | | ||
+ | Stone has a hardness of 1.5f and a resistance of 6.0f, while Obsidian has a hardness of 50.0f and a resistance of 1200.0f. | ||
+ | |||
+ | You can find the stats of all vanilla blocks in the class `Blocks`, where you can also reference other blocks. | ||
*/ | */ | ||
- | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).hardness(4.0f)); | + | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); |
| | ||
@Override | @Override | ||
Line 25: | 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=" | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).hardness(4.0f)); | + | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); |
| | ||
@Override | @Override | ||
Line 48: | Line 53: | ||
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)); |
- | We set out block material to METAL, which requires a pickaxe to efficiently break. | + | |
- | | + | |
- | */ | + | |
- | | + | |
| | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Registry.register(Registry.BLOCK, | Registry.register(Registry.BLOCK, | ||
- | Registry.register(Registry.ITEM, | + | Registry.register(Registry.ITEM, |
} | } | ||
} | } | ||
Line 132: | 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 150: | Line 181: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | @Override | ||
public class ExampleBlock extends Block { | public class ExampleBlock extends Block { | ||
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 |
tutorial/blocks.txt · Last modified: 2024/08/26 01:22 by solidblock