Guard Villagers

Guard Villagers

46M Downloads

[1.18.2]Crash When Villager Guard Transforms to zombie Because its null

wolflord212312 opened this issue ยท 2 comments

commented

**Suggested Fix **

add a Null Check Into the Die Event So if it equals null to Just kill it.

Code in question

@Override
public void die(DamageSource source) {
    if ((this.level.getDifficulty() == Difficulty.NORMAL || this.level.getDifficulty() == Difficulty.HARD) && source.getEntity() instanceof Zombie &&  net.minecraftforge.event.ForgeEventFactory.canLivingConvert((LivingEntity) source.getEntity(), EntityType.ZOMBIE_VILLAGER, (timer) -> {})) {
        if (this.level.getDifficulty() != Difficulty.HARD && this.random.nextBoolean()) {
            return;
        }
        ZombieVillager zombieguard = this.convertTo(EntityType.ZOMBIE_VILLAGER, true);
        zombieguard.finalizeSpawn((ServerLevelAccessor) this.level, this.level.getCurrentDifficultyAt(zombieguard.blockPosition()), MobSpawnType.CONVERSION, new Zombie.ZombieGroupData(false, true), (CompoundTag) null);
        if (!this.isSilent()) this.level.levelEvent((Player) null, 1026, this.blockPosition(), 0);
        this.discard();
    }
    super.die(source);
}

**CrashLog**: https://mclo.gs/e3Tdf6o
**LatestLog**: https://mclo.gs/XI9Ibxj
commented

idk whats wrong ur guard villagers but they turn perfectly fine into guard villager zombies

commented

this will only be fixed for the 1.19 versions as 1.18 is no longer supported.