mojira.dev
MC-231909

"minecraft.used:minecraft.<CAMPFIRE_COOKABLE_ITEM>" doesn't increase when placing food on campfires

The Bug:

"minecraft.used:minecraft.<CAMPFIRE_COOKABLE_ITEM>" doesn't increase when placing food on campfires.

Steps to Reproduce:

  1. Create a scoreboard objective for tracking when you use some raw beef and set it to display on the sidebar by using the commands provided below.

    /scoreboard objectives add UseBeef minecraft.used:minecraft.beef
    /scoreboard objectives setdisplay sidebar UseBeef
  2. Obtain some beef, eat it, and take note of how the scoreboard increases.

  3. Place down a campfire and place some beef onto it.

  4. Take note as to whether or not "minecraft.used:minecraft.<CAMPFIRE_COOKABLE_ITEM>" increases when placing food on campfires.

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.CampfireBlock.java

public class CampfireBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
   ...
   public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
      BlockEntity blockentity = $l.getBlockEntity($bp);
      if (blockentity instanceof CampfireBlockEntity) {
         CampfireBlockEntity campfireblockentity = (CampfireBlockEntity)blockentity;
         ItemStack itemstack = $p.getItemInHand($ih);
         Optional<CampfireCookingRecipe> optional = campfireblockentity.getCookableRecipe(itemstack);
         if (optional.isPresent()) {
            if (!$l.isClientSide && campfireblockentity.placeFood($p.getAbilities().instabuild ? itemstack.copy() : itemstack, optional.get().getCookingTime())) {
               $p.awardStat(Stats.INTERACT_WITH_CAMPFIRE);
               return InteractionResult.SUCCESS;
            }

            return InteractionResult.CONSUME;
         }
      }

      return InteractionResult.PASS;
   }
   ...

If we look at the above class, we can see that no stats are awarded when placing food on campfires. The only stat that is awarded is the INTERACT_WITH_CAMPFIRE stat. This is evident through the following line of code:

$p.awardStat(Stats.INTERACT_WITH_CAMPFIRE);

Potential Fix:

Simply adding a line of code that awards a stat when placing some food on a campfire 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()));

Attachments

Comments 3

Probably intended. Since you're not eating the food, and stats don't go up if you put an item in an item frame or a chest, for example

That's very true however, I would like to give Mojang a decision on whether this is intended or not. I believe the statistics not increasing when placing an item into an item frame is MC-54972, as item frames are entities. 😃

Would be pretty annoying if that were the case

Avoma

(Unassigned)

Confirmed

Platform

Normal

Items

1.17.1, 21w37a, 21w38a, 21w43a, 1.18 Pre-release 1, ..., 1.20.1, 1.21, 1.21.3, 1.21.4, 1.21.7

Retrieved