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

"minecraft.used:minecraft.<POTTABLE_PLANT>" doesn't increase when placing plants into flower pots

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.17.1, 21w37a, 1.18 Pre-release 1, 1.18.1, 22w05a, 1.18.2, 22w17a, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20.1, 1.21, 1.21.3, 1.21.4
    • None
    • Confirmed
    • Statistics

      The Bug:

      "minecraft.used:minecraft.<POTTABLE_PLANT>" doesn't increase when placing plants into flower pots.

      Steps to Reproduce:

      1. Create a scoreboard objective for tracking when you use an allium and set it to display on the sidebar by using the commands provided below.   
        /scoreboard objectives add UseAllium minecraft.used:minecraft.allium
        /scoreboard objectives setdisplay sidebar UseAllium
      2. Obtain an allium, place it on the ground, and take note of how the scoreboard increases.
      3. Place down a flower pot and place an allium inside of it.
      4. Take note as to whether or not "minecraft.used:minecraft.<POTTABLE_PLANT>" increases when placing plants into flower pots.

      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.18.1 using MCP-Reborn.

      net.minecraft.world.level.block.FlowerPotBlock.java
      public class FlowerPotBlock extends Block {
         ...
         public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
            ItemStack itemstack = $p.getItemInHand($ih);
            Item item = itemstack.getItem();
            BlockState blockstate = (item instanceof BlockItem ? POTTED_BY_CONTENT.getOrDefault(((BlockItem)item).getBlock(), Blocks.AIR) : Blocks.AIR).defaultBlockState();
            boolean flag = blockstate.is(Blocks.AIR);
            boolean flag1 = this.isEmpty();
            if (flag != flag1) {
               if (flag1) {
                  $l.setBlock($bp, blockstate, 3);
                  $p.awardStat(Stats.POT_FLOWER);
                  if (!$p.getAbilities().instabuild) {
                     itemstack.shrink(1);
                  }
               } ...

      If we look at the above class, we can see that no stats are awarded when placing plants into flower pots. The only stat that is awarded is the POT_FLOWER stat. This is evident through the following line of code:

      $p.awardStat(Stats.POT_FLOWER);

      Potential Fix:

      Simply adding a line of code that awards a stat when placing a plant into a flower pot should resolve this problem. The following line of code could be used in order to fix this:

      $p.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));

      The correct piece of code within its class should look something like the following:

      net.minecraft.world.level.block.FlowerPotBlock.java
      public class FlowerPotBlock extends Block {
         ...
         public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
            ItemStack itemstack = $p.getItemInHand($ih);
            Item item = itemstack.getItem();
            BlockState blockstate = (item instanceof BlockItem ? POTTED_BY_CONTENT.getOrDefault(((BlockItem)item).getBlock(), Blocks.AIR) : Blocks.AIR).defaultBlockState();
            boolean flag = blockstate.is(Blocks.AIR);
            boolean flag1 = this.isEmpty();
            if (flag != flag1) {
               if (flag1) {
                  $l.setBlock($bp, blockstate, 3);
                  $p.awardStat(Stats.POT_FLOWER);
                  $p.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
                  if (!$p.getAbilities().instabuild) {
                     itemstack.shrink(1);
                  }
               } ...

        1. MC-231743.mp4
          4.95 MB
        2. MC-231743.png
          MC-231743.png
          649 kB
        3. MC-231743-1.png
          MC-231743-1.png
          291 kB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            5 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              CHK: