public class DemoBlock extends BaseEntityBlock { [...] @Override protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { ... if (!player.getItemInHand(hand).isEmpty()) { ... } else { // If the player is not holding anything we'll get give him the items in the block entity one by one // Find the first slot that has an item and give it to the player if (!blockEntity.getItem(1).isEmpty()) { // Give the player the stack in the container player.getInventory().placeItemBackInInventory(blockEntity.getItem(1)); // Remove the stack from the container blockEntity.removeItem(1); } else if (!blockEntity.getItem(0).isEmpty()) { player.getInventory().placeItemBackInInventory(blockEntity.getItem(0)); blockEntity.removeItem(0); } else { return InteractionResult.TRY_WITH_EMPTY_HAND; } } return InteractionResult.SUCCESS; } }