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:35] – solidblock | tutorial:blockentity [2025/12/05 16:43] (current) – redirect to docs cassiancc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ~~REDIRECT> | ||
| + | |||
| ====== Adding a BlockEntity ====== | ====== Adding a BlockEntity ====== | ||
| Line 29: | Line 31: | ||
| [...] | [...] | ||
| | | ||
| - | 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 49: | ||
| public static final BlockEntityType< | public static final BlockEntityType< | ||
| " | " | ||
| - | BlockEntityType.Builder.create(DemoBlockEntity:: | + | |
| + | FabricBlockEntityTypeBuilder.create(DemoBlockEntity:: | ||
| ); | ); | ||
| | | ||
| Line 68: | Line 75: | ||
| 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 97: | ||
| 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; | ||
| } | } | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | Overriding '' | ||
| ===== Block entity ticking ===== | ===== Block entity ticking ===== | ||
| Line 109: | Line 125: | ||
| And in your '' | And in your '' | ||
| <code java DemoBlockEntity.java> | <code java DemoBlockEntity.java> | ||
| - | public class DemoBlockEntity extends BlockEntity { | + | public class DemoBlockEntity extends BlockEntity |
| [...] | [...] | ||
| | | ||
tutorial/blockentity.1724636119.txt.gz · Last modified: 2024/08/26 01:35 by solidblock