-
Bug
-
Resolution: Unresolved
-
None
-
1.16.5, 21w14a, 21w15a, 21w16a, 21w17a, 21w18a, 21w19a, 21w20a, 1.17 Pre-release 1, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1 Pre-release 3, 1.17.1 Release Candidate 1, 1.17.1, 1.18, 1.18.1, 22w05a, 1.18.2, 22w18a, 1.19, 1.19.2, 22w43a, 1.19.3, 1.19.4, 1.20.1, 1.20.4, 23w51b, 24w20a, 1.21
-
Confirmed
-
Mob behaviour
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 ~ ~ ~1 minecraft:chest{Lock:"Test"}
- 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.
- Take note as to whether or not piglins become aggressive when attempting to open locked blocks that they guard.
Observed Behavior:
Piglins become aggressive.
Expected Behavior:
Piglins would not become aggressive.
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 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.