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:
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
Place down a chest, open it, and take note of how the scoreboard correctly increases.
Summon a locked chest by using the command provided below.
/setblock ~ ~ ~ minecraft:chest{lock:{components:{"minecraft:custom_name":'"Mojira"'}}}
Attempt to open it.
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
is duplicated by 1
Attachments
Comments 15
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.
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.
Can confirm for MC 1.12.1.
A chest lock can be set using the following command.