public class BiggerChestBlock extends BlockWithEntity { public BiggerChestBlock(Settings settings) { super(settings); } // A side effect of extending BlockWithEntity is it changes the render type to INVISIBLE, so we have to revert this @Override public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.MODEL; } // We will create the BlockEntity later. @Override public BlockEntity createBlockEntity(BlockView view) { return new BiggerChestBlockEntity(); } @Override public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { if (itemStack.hasCustomName()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BiggerChestBlockEntity) { ((BiggerChestBlockEntity)blockEntity).setCustomName(itemStack.getName()); } } } @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!world.isClient) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BiggerChestBlockEntity) { ContainerProviderRegistry.INSTANCE.openContainer(ExampleMod.BIGGER_CHEST, player, buf -> buf.writeBlockPos(pos)); } } return ActionResult.SUCCESS; } // Scatter the items in the chest when it is removed. @Override public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { if (state.getBlock() != newState.getBlock()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BiggerChestBlockEntity) { ItemScatterer.spawn(world, pos, (BiggerChestBlockEntity)blockEntity); // update comparators world.updateHorizontalAdjacent(pos, this); } super.onBlockRemoved(state, world, pos, newState, moved); } } @Override public boolean hasComparatorOutput(BlockState state) { return true; } @Override public int getComparatorOutput(BlockState state, World world, BlockPos pos) { return Container.calculateComparatorOutput(world.getBlockEntity(pos)); } }