Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. 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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.8.2-pre1, Minecraft 1.8.8, Minecraft 15w47c, Minecraft 1.10.2, Minecraft 16w43a, Minecraft 1.11.2, Minecraft 17w06a, Minecraft 1.12.1, Minecraft 18w03b, Minecraft 1.13.1, 1.15.2, 20w13b, 20w15a, 1.16 Pre-release 5, 1.16.2, 1.16.4, 20w46a, 20w48a, 21w03a, 1.16.5, 21w05b, 21w06a, 21w11a, 21w14a, 21w17a, 1.17.1, 21w38a, 21w39a, 21w40a, 21w42a, 1.18 Pre-release 1, 1.18 Pre-release 7, 1.18, 1.18.1, 22w05a, 1.18.2 Release Candidate 1, 1.18.2, 22w17a, 22w18a, 1.19, 1.19.2, 22w43a, 1.19.3, 23w05a, 23w06a, 1.19.4, 1.20, 1.20.1, 1.20.4, 23w51b, 24w11a, 24w19b, 1.21, 1.21.4
    • None
    • Confirmed
    • Statistics
    • Low
    • Platform

      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 Avoma 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.

        1. MC-75532.mp4
          6.65 MB
        2. MC-75532.png
          MC-75532.png
          493 kB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            16 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              CHK: