mojira.dev
MC-231743

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

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 @unknown 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);
            }
         } ...

Linked issues

Attachments

Comments 4

Thank you for your report!
After consideration, the issue is being closed as Working as Intended.

Please note, that mechanics of the game may change between updates.
Things such as graphics, sounds, world creation, biomes, redstone, villagers, and animals may not work the same in current versions.

Full Version HistorySnapshot Version HistoryThe official Minecraft feedback site

Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki

Avoma

(Unassigned)

Confirmed

Statistics

1.17.1, 21w37a, 1.18 Pre-release 1, 1.18.1, 22w05a, , 1.20.1, 1.21, 1.21.3, 1.21.4, 1.21.7

Retrieved