mojira.dev
MC-222950

Piglins become aggressive when attempting to open locked blocks that they guard

The Bug:

Piglins become aggressive when attempting to open locked blocks that they guard.

Steps to Reproduce:

  1. Enter survival mode and equip a piece of golden armor.

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

    /setblock ~ ~ ~ minecraft:chest{lock:{components:{"minecraft:custom_name":'"Mojira"'}}}
  3. Summon a piglin by using the command provided below.

    /summon minecraft:piglin ~ ~ ~ {IsImmuneToZombification:1b}
  4. 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

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.

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]

Avoma

(Unassigned)

Confirmed

Mob behaviour

piglin

1.16.5, 21w14a, 21w15a, 21w16a, 21w17a, ..., 23w51b, 24w20a, 1.21, 1.21.4, 1.21.7

Retrieved