tutorial:blockentity
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:blockentity [2022/08/08 04:02] – [Sync data from server to client] solidblock | tutorial:blockentity [2022/12/16 02:14] – [Registering your BlockEntity] solidblock | ||
---|---|---|---|
Line 17: | Line 17: | ||
</ | </ | ||
- | Below will show you how to create | + | Please ensure that the constructor only takes the two parameters, otherwise the method reference '' |
You can simply add variables to this barebone class or implement interfaces such as '' | You can simply add variables to this barebone class or implement interfaces such as '' | ||
Line 23: | Line 23: | ||
===== Registering your BlockEntity ===== | ===== Registering your BlockEntity ===== | ||
- | Once you have created the '' | + | Once you have created the '' |
- | The '' | + | The '' |
<code java> | <code java> | ||
- | public static BlockEntityType< | + | |
+ | Registries.BLOCK_ENTITY_TYPE, | ||
+ | new Identifier(" | ||
+ | FabricBlockEntityTypeBuilder.create(DemoBlockEntity:: | ||
+ | ); | ||
+ | </ | ||
- | @Override | + | The block entity type defines that only the '' |
- | public void onInitialize() { | + | |
- | DEMO_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, | + | |
- | } | + | |
- | </ | + | |
==== Connecting a Block Entity to a Block ==== | ==== Connecting a Block Entity to a Block ==== | ||
Line 56: | Line 57: | ||
If you want to store any data in your '' | If you want to store any data in your '' | ||
- | '' | + | '' |
Knowing this, the example below demonstrates saving an integer from your '' | Knowing this, the example below demonstrates saving an integer from your '' | ||
Line 116: | Line 117: | ||
===== Block Entity Ticking ===== | ===== Block Entity Ticking ===== | ||
- | 1.17 has added static ticking, where before you'd implement the '' | + | 1.17 has added static ticking, where before you'd implement the '' |
Line 132: | Line 133: | ||
return checkType(type, | return checkType(type, | ||
} | } | ||
+ | } | ||
</ | </ | ||
- | And in your '' | + | And in your '' |
<code java> | <code java> | ||
public class DemoBlockEntity extends BlockEntity { | public class DemoBlockEntity extends BlockEntity { |
tutorial/blockentity.txt · Last modified: 2023/09/20 19:18 by haykam