public class BoxBlock extends BlockWithEntity { protected BoxBlock(Settings settings) { super(settings); } @Override public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return new BoxBlockEntity(pos, state); } @Override public BlockRenderType getRenderType(BlockState state) { //With inheriting from BlockWithEntity this defaults to INVISIBLE, so we need to change that! return BlockRenderType.MODEL; } @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!world.isClient) { //This will call the createScreenHandlerFactory method from BlockWithEntity, which will return our blockEntity casted to //a namedScreenHandlerFactory. If your block class does not extend BlockWithEntity, it needs to implement createScreenHandlerFactory. NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos); if (screenHandlerFactory != null) { //With this call the server will request the client to open the appropriate Screenhandler player.openHandledScreen(screenHandlerFactory); } } return ActionResult.SUCCESS; } //This method will drop all items onto the ground when the block is broken @Override public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { if (state.getBlock() != newState.getBlock()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BoxBlockEntity) { ItemScatterer.spawn(world, pos, (BoxBlockEntity)blockEntity); // update comparators world.updateComparators(pos,this); } super.onStateReplaced(state, world, pos, newState, moved); } } @Override public boolean hasComparatorOutput(BlockState state) { return true; } @Override public int getComparatorOutput(BlockState state, World world, BlockPos pos) { return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); } }