Use CustomBlockEntityType

With the CustomBlockEntityType class provided by the MModding Library, registering a new BlockEntityType is more simple.

Create your BlockEntity class

MModdingBlockEntity.java
public class MModdingBlockEntity extends BlockEntity {
    
    public MModdingBlockEntity(BlockPos pos, BlockState state) {
        super(NOTHING, pos, state);
    }
}

Create and register your BlockEntityType

In your BlockEntityTypes class :

BlockEntityTypes.java
public class BlockEntityTypes {
    public static final CustomBlockEntityType<TestBlockEntity> TEST = new CustomBlockEntityType<>(MModdingBlockEntity::new, BLOCK)
	.createAndRegister(new Identifier("mmodding_exemple_mod", "testBlockEntityType"));
}

Replace "BLOCK" by the instance of the block that uses the BlockEntity.

Update your BlockEntity class

Replace "NOTHING" by your BlockEntityType :

MModdingBlockEntity.java
public class MModdingBlockEntity extends BlockEntity {
    
    public MModdingBlockEntity(BlockPos pos, BlockState state) {
        super(BlockEntityTypes.TEST.getBlockEntityTypeIfCreated(), pos, state);
    }
}

Last updated