Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-222950

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

XMLWordPrintable

    • Icon: Bug 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
    • Confirmed
    • Mob behaviour

      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 ~ ~ ~1 minecraft:chest{Lock:"Test"}
      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.
      5. 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.

        1. MC-222950.mp4
          4.25 MB
        2. MC-222950.png
          MC-222950.png
          872 kB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: