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 02:44] – solidblock | tutorial:blockentity [2025/04/01 12:20] (current) – [Block entity ticking] solidblock | ||
---|---|---|---|
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 '' |
> **Note:** Like other blocks, the block also needs a block model and an item model, and may also need a loot table, see [[blocks]] for how to create them. As for loot tables, [[blockentity_sync_itemstack|subsequent tutorials]] will cover how to improve the loot tables to include block entity data. | > **Note:** Like other blocks, the block also needs a block model and an item model, and may also need a loot table, see [[blocks]] for how to create them. As for loot tables, [[blockentity_sync_itemstack|subsequent tutorials]] will cover how to improve the loot tables to include block entity data. | ||
Line 74: | Line 79: | ||
===== Connecting the block entity and the block ===== | ===== Connecting the block entity and the block ===== | ||
- | Once your '' | + | Once your '' |
<code java DemoBlock.java> | <code java DemoBlock.java> | ||
Line 90: | 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; | ||
} | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | Overriding '' | ||
===== Block entity ticking ===== | ===== Block entity ticking ===== | ||
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 |
[...] | [...] | ||
| |
tutorial/blockentity.1724640274.txt.gz · Last modified: 2024/08/26 02:44 by solidblock