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 [2019/11/14 22:02] – fudge | tutorial:blocks [2020/06/14 00:13] – block formatting changes + 1.16 draylar | ||
---|---|---|---|
Line 4: | Line 4: | ||
To add a block to your mod, you will need to register a new instance of the Block class. For more control over your block, you can create a custom block class. We'll also look at adding a block model. | To add a block to your mod, you will need to register a new instance of the Block class. For more control over your block, you can create a custom block class. We'll also look at adding a block model. | ||
+ | |||
==== Creating a Block ==== | ==== Creating a Block ==== | ||
To start, create an instance of Block in your main mod class. Block' | To start, create an instance of Block in your main mod class. Block' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class ExampleMod implements ModInitializer | + | public class ExampleMod implements ModInitializer { |
- | { | + | |
// an instance of our new block | // an instance of our new block | ||
- | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).build()); | + | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL)); |
- | | + | |
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | |||
+ | } | ||
} | } | ||
</ | </ | ||
Line 21: | Line 26: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class ExampleMod implements ModInitializer | + | public class ExampleMod implements ModInitializer { |
- | { | + | |
- | // block creation | + | // an instance of our new block |
- | | + | |
| | ||
@Override | @Override | ||
- | public void onInitialize() | + | public void onInitialize() { |
- | | + | |
Registry.register(Registry.BLOCK, | Registry.register(Registry.BLOCK, | ||
} | } | ||
Line 99: | Line 103: | ||
==== Adding a block loot table ==== | ==== Adding a block loot table ==== | ||
- | The block must have a loot table for any items to drop when the block is broken. Assuming you have created an item for your block and registered it using the same name as the block, the following file will produce regular block drops '' | + | The block must have a loot table for any items to drop when the block is broken. Assuming you have created an item for your block and registered it using the same name as the block, the following file will produce regular block drops '' |
<code JavaScript src/ | <code JavaScript src/ | ||
Line 138: | Line 142: | ||
</ | </ | ||
- | Just like we did in the item tutorial, you can override methods in the block class for custom functionality. | + | Just like we did in the item tutorial, you can override methods in the block class for custom functionality. |
+ | |||
+ | If you want your block to be transparent, in your client mod initializer code, do: | ||
+ | <code java> | ||
+ | BlockRenderLayerMap.INSTANCE.putBlock(EXAMPLE_BLOCK, | ||
+ | </ | ||
+ | |||
+ | In versions before 1.15/ | ||
<code java> | <code java> | ||
@Environment(EnvType.CLIENT) | @Environment(EnvType.CLIENT) | ||
+ | @Override | ||
public BlockRenderLayer getRenderLayer() { | public BlockRenderLayer getRenderLayer() { | ||
return BlockRenderLayer.TRANSLUCENT; | return BlockRenderLayer.TRANSLUCENT; | ||
Line 159: | Line 171: | ||
Your custom block should now be transparent! | Your custom block should now be transparent! | ||
+ | |||
+ | |||
+ | ==== Custom VoxelShape ==== | ||
+ | |||
+ | When making custom blocks which do not entirely fill the block, the adjacent blocks might hide their faces. In this case of a custom vertical slab it would look like this: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | We have to define the VoxelShape of the new block into one which is not an entire block: | ||
+ | |||
+ | < | ||
+ | @Override | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | By doing so we also define getCollisionShape, | ||
+ | |||
+ | {{: | ||
+ | |||
==== Next Steps ==== | ==== Next Steps ==== | ||
[[tutorial: | [[tutorial: | ||
- | [[tutorial: | + | [[tutorial: |
tutorial/blocks.txt · Last modified: 2024/08/26 01:22 by solidblock