Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-265697

After breaking a brush, the player's off-hand can't finish using some items

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.2, 23w40a, 23w41a, 23w42a, 1.20.3 Release Candidate 1, 1.20.3, 1.20.4, 23w51b, 24w05a, 24w09a, 24w10a, 24w11a, 1.20.6
    • Confirmed
    • Survival
    • Player Animation
    • Low
    • Gameplay

      When a player breaks a brush after brushing a suspicious sand/or suspicious gravel block and continues to hold down the 'use' button, they will not be able to properly finish using some items.

      Steps to Reproduce:

      1. Get a brush with 1 durrability, a suspicious sand, and a food item.
        /give @s brush[minecraft:damage=63]
        
      2. Make sure the player is hungry
        /effect give @p hunger 2 255
        
      3. Hold the food item in the off-hand, and the brush in the main hand
      4. Brush the suspicious gravel

      Observed Results:

      The player will brush the gravel to completion, but after the brush breaks and the player starts trying to eat the food item, they will be stuck in the animation unable to finish eating it completely.

      Expected Results:

      The player would brush the block, and eat the item.

      Screenshots/Videos:

      2023-10-07_22-50-59.mp4

      Code Analysis \ Possible Fix \ Mcp-Reborn 1.20.2

      Here near the end of this method, the game checks for which hand the player is holding the brush in, and then will damage and/or break it. The problem lies in that the game does not properly state that the player has actually stopped using the item.

      To fix this, first a check is done to see if the item's damage is equal to it's max damage (broken), and if it is, the player will stop using the item

      Class: net\minecraft\world\item\BrushItem.java Method: onUseTick()
      
      . . .
                        level.playSound(player, blockpos, soundevent, SoundSource.BLOCKS);
                        if (!level.isClientSide()) {
                           BlockEntity blockentity = level.getBlockEntity(blockpos);
                           if (blockentity instanceof BrushableBlockEntity) {
                              BrushableBlockEntity brushableblockentity = (BrushableBlockEntity)blockentity;
                              boolean flag1 = brushableblockentity.brush(level.getGameTime(), player, blockhitresult.getDirection());
                              if (flag1) {
                                 EquipmentSlot equipmentslot = itemStack.equals(player.getItemBySlot(EquipmentSlot.OFFHAND)) ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND;
                                 itemStack.hurtAndBreak(1, livingEntity, (livingEntity1) -> livingEntity1.broadcastBreakEvent(equipmentslot));
      Fix Start
                                 if (itemStack.getDamageValue() == itemStack.getMaxDamage()) {
                                    player.stopUsingItem();
                                 }
      Fix End
                              }
                           }
                        }
      . . .
      

      This fix provides the following behavior:
      2023-10-07_23-15-29.mp4

      Notes:

      1. This issue relates to MC-168573
      2. This specifically affects using tridents, bows/crossbows, and food.

            billy.sjoberg [Mojang] Billy Sjöberg
            Jingy Jiingy
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              CHK: