The Bug:
"minecraft.used:minecraft.<POTTABLE_PLANT>" doesn't increase when placing plants into flower pots.
Steps to Reproduce:
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
Obtain an allium, place it on the ground, and take note of how the scoreboard increases.
Place down a flower pot and place an allium inside of it.
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);
}
} ...
Related issues
Attachments
Comments

Relates to MC-224325.

Can confirm.

Affects 1.18