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

minecraft.used:minecraft.goat_horn doesn't increase when using goat horns

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 22w42a
    • 22w17a, 22w18a, 22w19a, 1.19 Pre-release 1, 1.19 Pre-release 2, 1.19, 1.19.1 Pre-release 1, 1.19.1 Pre-release 2, 1.19.1 Pre-release 5, 1.19.1, 1.19.2
    • Confirmed
    • Statistics
    • Normal

      The Bug:

      minecraft.used:minecraft.goat_horn doesn't increase when using goat horns.

      Steps to Reproduce:

      • Create a scoreboard objective for tracking the use of a goat horn and set it to display on the sidebar.
      • /scoreboard objectives add UseGoatHorn minecraft.used:minecraft.goat_horn
      • /scoreboard objectives setdisplay sidebar UseGoatHorn
      • Obtain a goat horn and use it.
      • Take note as to whether or not minecraft.used:minecraft.goat_horn increases when using goat horns.

      Observed Behavior:

      The scoreboard doesn't increase.

      Expected Behavior:

      The scoreboard would increase.

      Code Analysis:

      Code analysis by Avoma can be found below.

      The following is based on a decompiled version of Minecraft 1.19 Pre-release 2 using Mojang mappings.

      net.minecraft.world.item.InstrumentItem.java
      public class InstrumentItem extends Item {
         ...
         @Override
            public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand interactionHand) {
               ItemStack itemStack = player.getItemInHand(interactionHand);
               Optional<Holder<Instrument>> optional = this.getInstrument(itemStack);
               if (optional.isPresent()) {
                  Instrument instrument = optional.get().value();
                  player.startUsingItem(interactionHand);
                  InstrumentItem.play(level, player, instrument);
                  player.getCooldowns().addCooldown(this, instrument.useDuration());
                  return InteractionResultHolder.consume(itemStack);
               }
               return InteractionResultHolder.fail(itemStack);
            }
            ...

      If we look at the above class, we can see that the awardStat() method (the method responsible for incrementing player statistics) is never called throughout this piece of code, thus making minecraft.used:minecraft.goat_horn not increase when using goat horns.

      Fix:

      Simply calling the awardStat() method where appropriate within this piece of code will resolve this problem. The following line of code can be used to fix this issue.

      player.awardStat(Stats.ITEM_USED.get(this));

        1. MC-250943.mp4
          5.70 MB
          [Mod] Avoma
        2. MC-250943.png
          2.59 MB
          [Mod] Avoma
        3. MC-250943 - Current Code.png
          45 kB
          [Mod] Avoma
        4. MC-250943 - Fixed Code.png
          49 kB
          [Mod] Avoma

            MNilsson [Mojang] MNilsson
            Avoma [Mod] Avoma
            Votes:
            21 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: