Mojira Archive
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 [Mod] 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.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()));

Unresolved

[Mod] Avoma

2021-07-13, 04:59 PM

2024-12-08, 01:25 PM

4

2

Confirmed

Normal

Platform

Items

1.17.1 - 1.21.41.17.1, 21w37a, 21w38a, 21w43a, 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

-