User Tools

Site Tools


tutorial:blockentity

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
tutorial:blockentity [2019/07/22 17:38]
fudge typo
tutorial:blockentity [2020/05/07 18:53]
yanis48 typo
Line 17: Line 17:
 </​code>​ </​code>​
  
-Bellow ​will show you how to create the ''​ExampleMod.DEMO_BLOCK_ENTITY''​ field.+Below will show you how to create the ''​ExampleMod.DEMO_BLOCK_ENTITY''​ field.
  
 You can simply add variables to this barebone class or implement interfaces such as ''​Tickable''​ and ''​Inventory''​ to add more functionality. ''​Tickable''​ provides a single ''​tick()''​ method, which is called once per tick for every loaded instance of your Block in the world., while ''​Inventory''​ allows your BlockEntity to interact with automation such as hoppers - there will likely be a separate tutorial dedicated entirely to this interface later. You can simply add variables to this barebone class or implement interfaces such as ''​Tickable''​ and ''​Inventory''​ to add more functionality. ''​Tickable''​ provides a single ''​tick()''​ method, which is called once per tick for every loaded instance of your Block in the world., while ''​Inventory''​ allows your BlockEntity to interact with automation such as hoppers - there will likely be a separate tutorial dedicated entirely to this interface later.
Line 32: Line 32:
 @Override @Override
 public void onInitialize() { public void onInitialize() {
-   ​DEMO_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY, "​modid:​demo",​ BlockEntityType.Builder.create(DemoBlockEntity::​new,​ DEMO_BLOCK).build(null));​+   ​DEMO_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, "​modid:​demo",​ BlockEntityType.Builder.create(DemoBlockEntity::​new,​ DEMO_BLOCK).build(null));​
 } }
 </​code>​ </​code>​
  
-Once your ''​BlockEntityType''​ has been created and registered ​as seen above, you can simply implement ​''​BlockEntityProvider'' ​in your ''​Block'' ​class:+==== Connecting a Block Entity to a Block ==== 
 + 
 +Once your ''​BlockEntityType''​ has been created and registered, you'll need a block that is associated with it. You can do this by implementing ​''​BlockEntityProvider'' ​and overriding ​''​createBlockEntity''​. Each time your block is placed, your Block Entity will spawn alongside it.
  
 <code java> <code java>
-@Override +public class MyBlock extends Block implements BlockEntityProvider { 
-public BlockEntity createBlockEntity(BlockView blockView) { + 
-   ​return new DemoBlockEntity();​+   ​[...] 
 + 
 +   @Override 
 +   ​public BlockEntity createBlockEntity(BlockView blockView) { 
 +      return new DemoBlockEntity();​ 
 +   }
 } }
 </​code>​ </​code>​
tutorial/blockentity.txt · Last modified: 2020/05/07 19:15 by earthcomputer