public class DemoBlock extends BaseEntityBlock { [...] @Override protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (level.isClient) return InteractionResult.SUCCESS; if (!(level.getBlockEntity(pos) instanceof DemoBlockEntity blockEntity)) { return InteractionResult.PASS; } if (!player.getItemInHand(hand).isEmpty()) { // Check what is the first open slot and put an item from the player's hand there if (blockEntity.getItem(0).isEmpty()) { // Put the stack the player is holding into the container blockEntity.setItem(0, player.getItemInHand(hand).copy()); // Remove the stack from the player's hand player.getItemInHand(hand).setCount(0); } else if (blockEntity.getItem(1).isEmpty()) { blockEntity.setItem(1, player.getItemInHand(hand).copy()); player.getItemInHand(hand).setCount(0); } else { // If the container is full we'll notify the player player.displayClientMessage(Component.literal("The inventory is full! The first slot holds ") .append(blockEntity.getItem(0).getItemName()) .append(" and the second slot holds ") .append(blockEntity.getItem(1).getItemName())); } } return InteractionResult.SUCCESS; } }