mojira.dev
MC-254512

Breaking a crossbow increases used air statistic

The bug

You can use air in minecraft when you break a crossbow in 1.14+ (1.14-1.19). 

Video that shows it: https://youtu.be/ggE56xeICmA?t=13

In the scoreboard and files it shows the stat, but in the statistics menu its not counted.

To reproduce

  1. Execute the following commands:

    /scoreboard objectives add usedAir minecraft.used:minecraft.air "usedAir"
    /scoreboard objectives setdisplay sidebar usedAir

    Until 1.20.4

    /give @p minecraft:crossbow{Charged:1b,ChargedProjectiles:[{id:"minecraft:arrow",Count:1b}],Damage:465}

    1.20.5+

    /give @p minecraft:crossbow[charged_projectiles=[{id:"minecraft:arrow",count:1b}],damage=465]
  2. Use the given crossbow.

  3. ❌ The score goes up by one, indicating you have used air.

Code analysis

The bug is caused because the code of crossbow breaking is before that the adding the stat. In the screenshot (named Screenshot_20220723_183443) we can see that is on the function "onCrossbowShot". This function is called in the Screenshot_20220723_183409, and the breaking of the item is in "shootProjectile". So the item here is null or is less than 0, in the first photo we can see that is called "getItem()" (Screenshot_20220723_183309), if the variable "emptyCacheFlag" is true it returns air (here is the air use). This variable depends on the function "isEmpty" that is true when the crossbow breaks.

(The class of the 2 first screenshots is "CrossbowItem", and the other is "ItemStack")

To fix this bug the easiest way is to move the count of the stat in the start of the function "performShooting"

Linked issues

Attachments

Comments 3

Can confirm in 1.19.1.

Can confirm in 1.19.2.

Can confirm in 1.20.4.

luisch444

(Unassigned)

Confirmed

Platform

Low

Items, Statistics

1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4 Pre-release 3, ..., 23w18a, 1.20.1, 1.20.4, 24w05b, 24w13a

Retrieved