mojira.dev
MC-196736

Hoglins break their leash when zombifying, despite zoglins being leashable

The bug

After zombifying, hoglins break their leash when they convert into a zoglin. This seems somewhat inconsistent, as zoglins can be leashed.

The video attachment shows a hoglin breaking its leash connected to a fence after it finishes its zombifying process; hoglins also break its leash when the player is holding the lead, not just when connected to a fence.

Code analysis

Code analysis and fix by @unknown can be found in this comment.

Linked issues

Attachments

Comments 12

Added video attachment, and I can still reproduce in 1.16.2pre2

Able to reproduce in pre3

I can confirm for 1.16.3

Can confirm in 20w51a.

Can confirm in 21w03a.

2 more comments

Can confirm in 1.16.5 and 1.17 Release Candidate 1.

Can confirm in 1.17.

Can confirm in 1.17.1.

Code analysis (Mojang mappings, 1.19.2): there is no code in Mob#convertTo(...) to transfer the leash holder from a mob to another. Ideally, this should be fixed in this function for future-proofing. But this can also be fixed (hack-fixed?) by changing Hoglin#finishConversion(ServerLevel).

Potential (not ideal) fix (might cause other issues):
Change Hoglin#finishConversion(ServerLevel) from

private void finishConversion(ServerLevel $$0) {
        Zoglin $$1 = this.convertTo(EntityType.ZOGLIN, true);
        if ($$1 != null) {
            $$1.addEffect(new MobEffectInstance(MobEffects.CONFUSION, 200, 0));
        }
    }

to

private void finishConversion(ServerLevel $$0) {
        Entity leashHolder = this.getLeashHolder();
        if (leashHolder != null) {
            this.dropLeash(false, false);
        }
        Zoglin $$1 = this.convertTo(EntityType.ZOGLIN, true);
        if ($$1 != null) {
            if (leashHolder != null) {
                $$1.setLeashedTo(leashHolder, true);
            }
            $$1.addEffect(new MobEffectInstance(MobEffects.CONFUSION, 200, 0));
        }
    }

This has been fixed in 24w36a.

BlockOfNetherite

(Unassigned)

Confirmed

Gameplay

Normal

Mob behaviour

hoglin, lead, mob-behavior, zoglin

1.16.2 Pre-release 1, 1.16.2 Pre-release 2, 1.16.2 Pre-release 3, 1.16.2 Release Candidate 1, 1.16.2 Release Candidate 2, ..., 1.19.3, 23w05a, 1.20.2, 24w05b, 1.21.1

24w36a

Retrieved