mojira.dev
MC-75532

"minecraft.custom:minecraft.open_<LOCKABLE_BLOCK>" and "minecraft.custom:minecraft.inspect_<LOCKABLE_BLOCK>" incorrectly increase when attempting to open or inspect locked blocks

The Bug:

"minecraft.custom:minecraft.open_<LOCKABLE_BLOCK>" and "minecraft.custom:minecraft.inspect_<LOCKABLE_BLOCK>" incorrectly increase when attempting to open or inspect locked blocks.

Steps to Reproduce:

  1. Create a scoreboard objective for tracking when you open a chest and set it to display on the sidebar by using the commands provided below.

    /scoreboard objectives add OpenChest minecraft.custom:minecraft.open_chest
    /scoreboard objectives setdisplay sidebar OpenChest
  2. Place down a chest, open it, and take note of how the scoreboard correctly increases.

  3. Summon a locked chest by using the command provided below.

    /setblock ~ ~ ~ minecraft:chest{lock:{components:{"minecraft:custom_name":'"Mojira"'}}}
  4. Attempt to open it.

  5. Take note as to whether or not "minecraft.custom:minecraft.open_<LOCKABLE_BLOCK>" and "minecraft.custom:minecraft.inspect_<LOCKABLE_BLOCK>" incorrectly increase when attempting to open or inspect locked blocks.

Observed Behavior:

The scoreboard incorrectly increases.

Expected Behavior:

The scoreboard would not increase.

Code Analysis:

Code analysis by @unknown can be found below.

The following is based on a decompiled version of Minecraft 1.18.2 using MCP-Reborn.

net.minecraft.world.level.block.ChestBlock.java

public class ChestBlock extends AbstractChestBlock<ChestBlockEntity> implements SimpleWaterloggedBlock {
   ...
   public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
      if ($l.isClientSide) {
         return InteractionResult.SUCCESS;
      } else {
         MenuProvider menuprovider = this.getMenuProvider($bs, $l, $bp);
         if (menuprovider != null) {
            $p.openMenu(menuprovider);
            $p.awardStat(this.getOpenChestStat());
            PiglinAi.angerNearbyPiglins($p, true);
         }

         return InteractionResult.CONSUME;
      }
   }
   ...

If we look at the above class, we can see that no checks are carried out the see whether or not the desired chest contains a lock when attempting to open it, before awarding the appropriate statistic. The awardStat() method will always be called when the chest is right-clicked on, regardless of whether or not it has a lock, resulting in this issue occurring.

Linked issues

Attachments

Comments 15

Can confirm for MC 1.12.1.
A chest lock can be set using the following command.

/blockdata ~ ~ ~ {Lock:"Lock"}

This bug still occurs in 1.14, and 1.15, and 1.15.1. Mojang PLEASE fix this bug, it makes no sense for something like this to be postponed for so many versions. This hinders our ability to map make; we shouldn't have to be making workarounds to bugs that are supposed to get fixed within a reasonable time frame. Five years of not fixing this is unacceptable in my opinion. I'd like to see this get fixed in 1.16.

Confirmed in 20w13b

Confirmed in 20w15a

Confirmed in 1.16-pre5.

5 more comments

Can confirm in 21w14a.

Can confirm in 21w17a.

Can confirm in 1.17.1.

I'd like to request ownership of this ticket since the current reporter has been inactive since December 2014. I'm willing to provide all of the necessary information and will keep this report updated.

This isn't just the case with the minecraft.custom:minecraft.open_chest. This also affects other scoreboard objectives. I've updated this ticket accordingly to reflect this information.

Joseph Smith

Avoma

(Unassigned)

Confirmed

Platform

Low

Statistics

Minecraft 1.8.2-pre1, Minecraft 1.8.8, Minecraft 15w47c, Minecraft 1.10.2, Minecraft 16w43a, ..., 1.21, 1.21.4, 25w08a, 1.21.5, 1.21.6

Retrieved