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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • None
    • 1.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
    • None
    • Confirmed
    • Items
    • Normal

    Description

      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 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()));

      Attachments

        1. MC-231909.mp4
          7.03 MB
        2. MC-231909.png
          MC-231909.png
          605 kB

        Activity

          People

            Unassigned Unassigned
            Avoma [Helper] Avoma
            Votes:
            4 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              CHK: