public class DemoBlock extends BlockWithEntity { [...] @Override protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { ... if (!player.getStackInHand(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.getStack(1).isEmpty()) { // Give the player the stack in the inventory player.getInventory().offerOrDrop(blockEntity.getStack(1)); // Remove the stack from the inventory blockEntity.removeStack(1); } else if (!blockEntity.getStack(0).isEmpty()) { player.getInventory().offerOrDrop(blockEntity.getStack(0)); blockEntity.removeStack(0); } else { return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } } return ItemActionResult.SUCCESS; } }