The Bug:
Piglins become aggressive when attempting to open locked blocks that they guard.
Steps to Reproduce:
Enter survival mode and equip a piece of golden armor.
Summon a locked chest by using the command provided below.
/setblock ~ ~ ~ minecraft:chest{lock:{components:{"minecraft:custom_name":'"Mojira"'}}}
Summon a piglin by using the command provided below.
/summon minecraft:piglin ~ ~ ~ {IsImmuneToZombification:1b}
Attempt to open the chest and observe the behavior of the piglin.
Observed Behavior:
Piglins become aggressive.
Expected Behavior:
Piglins would not become aggressive.
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 to see whether the desired chest contains a lock when attempting to open it, before angering nearby piglins. The angerNearbyPiglins()
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.
Attachments
Comments 2
While in Minecraft version 1.21.5 using the setup in the attached image, I noted that piglins become aggressive once any standard container (Not stuff like droppers or furnaces) is opened. This is not the case when there is a block above the containers that prevents them from being opened(including the locked chests), but a block like a barrel will still make them aggressive, because the result, even if there is a block, is still to open. Like Avoma said, there should be a check in place to see if the designated container is locked.
-Isaiah0Jackson
[media]
Can confirm. This doesn’t happen if the chest is prevented from opening by a block. This may be intended as you may be trying to steal their treasure.