tutorial:blockentity
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:blockentity [2024/08/26 01:16] – solidblock | tutorial:blockentity [2025/04/01 12:20] (current) – [Block entity ticking] solidblock | ||
---|---|---|---|
Line 23: | Line 23: | ||
Once you have created the '' | Once you have created the '' | ||
- | The '' | + | The '' |
<code java TutorialBlocks.java> | <code java TutorialBlocks.java> | ||
Line 29: | Line 29: | ||
[...] | [...] | ||
| | ||
- | public static final DemoBlock DEMO_BLOCK = register(" | + | |
+ | // public static final DemoBlock DEMO_BLOCK = register(" | ||
+ | |||
+ | // For version 1.21.2 and later | ||
+ | public static final DemoBlock DEMO_BLOCK = register(" | ||
| | ||
[...] | [...] | ||
Line 43: | Line 47: | ||
public static final BlockEntityType< | public static final BlockEntityType< | ||
" | " | ||
- | BlockEntityType.Builder.create(DemoBlockEntity:: | + | |
+ | FabricBlockEntityTypeBuilder.create(DemoBlockEntity:: | ||
); | ); | ||
| | ||
Line 68: | Line 73: | ||
For old versions, if you cannot access '' | For old versions, if you cannot access '' | ||
- | The block entity type defines that only the '' | + | The block entity type defines that only the '' |
- | ==== Connecting | + | > **Note:** Like other blocks, |
- | Once your '' | + | ===== Connecting the block entity and the block ===== |
+ | |||
+ | Once your '' | ||
<code java DemoBlock.java> | <code java DemoBlock.java> | ||
Line 88: | Line 95: | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new DemoBlockEntity(pos, | return new DemoBlockEntity(pos, | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected BlockRenderType getRenderType(BlockState state) { | ||
+ | return BlockRenderType.MODEL; | ||
} | } | ||
} | } | ||
</ | </ | ||
- | To serialize data for bloc kentities, see [[block_entity_modifying_data]]. | + | Overriding '' |
- | ===== Block Entity Ticking | + | ===== Block entity ticking |
Ticking means the block should run something on every tick (which is 1/20 second). For your block to tick, you would normally use '' | Ticking means the block should run something on every tick (which is 1/20 second). For your block to tick, you would normally use '' | ||
Line 111: | Line 123: | ||
And in your '' | And in your '' | ||
<code java DemoBlockEntity.java> | <code java DemoBlockEntity.java> | ||
- | public class DemoBlockEntity extends BlockEntity { | + | public class DemoBlockEntity extends BlockEntity |
[...] | [...] | ||
| | ||
Line 121: | Line 133: | ||
</ | </ | ||
- | ===== Overview | + | ===== Next steps ===== |
+ | |||
+ | You should now have your very own '' | ||
- | You should now have your very own '' | + | You also learned how to add ticking for it. Next step, you can try some other complex operations for the block entities, such as: |
+ | * [[blockentity_modify_data|Modifying block entity data]] | ||
+ | * [[inventory|Storing items in the block entity as an inventory]] | ||
+ | * [[blockentityrenderers|Using block entity renderers | ||
+ | * [[screenhandler|Creating a container block]] |
tutorial/blockentity.1724634969.txt.gz · Last modified: 2024/08/26 01:16 by solidblock