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/05/30 11:40] – [Giving your block a model] Use wikitut namespace for item model parent jamieswhiteshirt | tutorial:blocks [2020/03/30 17:35] – [Creating a Block class] liach | ||
---|---|---|---|
Line 3: | Line 3: | ||
==== Introduction ==== | ==== Introduction ==== | ||
- | 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 | ||
Line 21: | Line 18: | ||
==== Registering a Block ==== | ==== Registering a Block ==== | ||
- | We're going to register our block, just like you would an item or any other addition. You can call // | + | Registering blocks is the same as registering items. Call // |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 27: | Line 24: | ||
{ | { | ||
// block creation | // block creation | ||
- | […] | + | [...] |
| | ||
@Override | @Override | ||
public void onInitialize() | public void onInitialize() | ||
{ | { | ||
- | Registry.register(Registry.BLOCK, | + | Registry.register(Registry.BLOCK, |
} | } | ||
} | } | ||
</ | </ | ||
- | Your block will not be accessible as an item, but it can be seen in-game by using / | + | Your block will //not// be accessible as an item, but it can be seen in-game by using '' |
==== Registering a BlockItem ==== | ==== Registering a BlockItem ==== | ||
Line 55: | Line 52: | ||
[...] | [...] | ||
| | ||
- | Registry.register(Registry.ITEM, | + | Registry.register(Registry.ITEM, |
} | } | ||
} | } | ||
Line 64: | Line 61: | ||
As you probably have noticed, the block is simply a purple and black checkerboard pattern in-game. This is Minecraft' | As you probably have noticed, the block is simply a purple and black checkerboard pattern in-game. This is Minecraft' | ||
- | Blockstate: src/ | + | Blockstate: src/ |
- | Block Model: src/ | + | Block Model: src/ |
- | Item Model: src/ | + | Item Model: src/ |
- | Block Texture: src/ | + | Block Texture: src/ |
The blockstate file determines which model that the block should use depending on it's blockstate. As our block has only one state, the file is a simple as this: | The blockstate file determines which model that the block should use depending on it's blockstate. As our block has only one state, the file is a simple as this: | ||
- | <code JavaScript src/ | + | <code JavaScript src/ |
{ | { | ||
" | " | ||
- | "": | + | "": |
} | } | ||
} | } | ||
Line 81: | Line 78: | ||
The block model file defines the shape and texture of your block. We will use block/ | The block model file defines the shape and texture of your block. We will use block/ | ||
- | <code JavaScript src/ | + | <code JavaScript src/ |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
Line 92: | Line 89: | ||
In most cases you want the block to look the same in hand. To do this, you can make an item file that inherits from the block model file: | In most cases you want the block to look the same in hand. To do this, you can make an item file that inherits from the block model file: | ||
- | <code JavaScript src/ | + | <code JavaScript src/ |
{ | { | ||
- | " | + | " |
} | } | ||
</ | </ | ||
Line 104: | Line 101: | ||
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 113: | Line 110: | ||
{ | { | ||
" | " | ||
- | " | + | " |
} | } | ||
], | ], | ||
Line 141: | Line 138: | ||
</ | </ | ||
- | 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.putBlock(/ | ||
+ | </ | ||
+ | |||
+ | 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 162: | Line 167: | ||
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 ==== | ||
+ | [[tutorial: | ||
+ | |||
+ | [[tutorial: |
tutorial/blocks.txt · Last modified: 2024/06/21 21:37 by ryhon