-
Bug
-
Resolution: Unresolved
-
None
-
1.15.1, 1.17.1, 22w11a, 1.19, 1.19.3, 1.20.2, 23w41a, 23w42a, 1.20.3 Release Candidate 1, 1.20.3, 1.20.4, 24w05a, 1.20.6
-
Confirmed
-
Player
The Bug
If the player continues to hold down the 'use' key after they break a shield in their off-hand, they will be unable to properly use items in your main hand. This includes things such as using a bow & arrow, eating an item, where the player will appear to use the item, but will never fully finish the action.
Steps to Reproduce:
(Must be in Survival Mode)
- Run this command to place a command block below the player
/setblock ~1 ~-1 ~ command_block{Command:"/damage @p 3 minecraft:mob_attack at ~1 ~2 ~"} replace
- Place a pressure plate above the command block
- Give the player a shield with 1 durability (Hold in main hand)
/give @p shield{Damage:335} 1
- Give the player a golden apple (Hold in off-hand)
/give @p golden_apple
- Block with the shield (Continue holding the 'use' key through step 6)
- Face the south direction, and activate the command block with the pressure plate
Observed Results:
The player will block the attack damage, and the shield will break. When it does, the player will then attempt to eat the golden apple, but will be unable to. Instead, the animation and sound will loop repeatedly never finishing.
Expected Results:
The player would block the attack, and then eat the golden apple completely.
Screenshots/Videos:
Me reproducing the bug:
2023-10-13_13-40-30.mp4
Code Analysis:
Here inside the below method the game sees if the entity which is blocking has taken more than 3 damage points. If they have, the shield is then damaged, or possibly broken. It then checks if the useItem is empty (if the shield has broken) and if it has, set the "EquipmentSlot" to empty. After that, the shield breaking sound is played.
The issue here is that there is nothing telling the blocking entity to stop using the "useItem" (shield) after it has broken. This leads to the behavior where the player cannot use items such as the golden apple, because technically they still have not stopped using their shield. The fix for this, is add "this.stopUsingItem();" after the break sound is played.
Class: net\minecraft\world\entity\player\Player.java - Method: hurtCurrentlyUsedShield()
protected void hurtCurrentlyUsedShield(float damageIn) { if (this.useItem.is(Items.SHIELD)) { if (!this.level().isClientSide) { this.awardStat(Stats.ITEM_USED.get(this.useItem.getItem())); } if (damageIn >= 3.0F) { int i = 1 + Mth.floor(damageIn); InteractionHand interactionhand = this.getUsedItemHand(); this.useItem.hurtAndBreak(i, this, (player) -> { player.broadcastBreakEvent(interactionhand); }); if (this.useItem.isEmpty()) { if (interactionhand == InteractionHand.MAIN_HAND) { this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY); } else { this.setItemSlot(EquipmentSlot.OFFHAND, ItemStack.EMPTY); } this.useItem = ItemStack.EMPTY; this.playSound(SoundEvents.SHIELD_BREAK, 0.8F, 0.8F + this.level().random.nextFloat() * 0.4F); Fix Start this.stopUsingItem(); Fix End } } } }
This provides the following behavior:
2023-10-13_14-44-35.mp4
Notes:
- Switching items in your main hand will allow you to use the item you swap to.
- Releasing the 'use' key and pressing it again will properly allow you to use the item in your mian hand.
- is duplicated by
-
MC-234354 Shields are broken when using 2 of them
- Resolved