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

Persistent villagers without experience can despawn after converting to a witch

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 20w22a
    • 1.16 Pre-release 1
    • None
    • Confirmed
    • Entities
    • Normal

    Description

      The bug

      If a villager with no experience and {PersistenceRequired: 1b} is struck by lightning and converted into a witch, the witch that replaces the villager will have {PersistenceRequired: 0b}.

      Code analysis (Yarn mappings)

      LOGGER.info("Villager {} was struck by lightning {}.", this, lightning);
      WitchEntity witchEntity = (WitchEntity)EntityType.WITCH.create(this.world);
      witchEntity.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch);
      witchEntity.initialize(this.world, this.world.getLocalDifficulty(witchEntity.getBlockPos()), SpawnReason.CONVERSION, (EntityData)null, (CompoundTag)null);
      witchEntity.setAiDisabled(this.isAiDisabled());
      if (this.hasCustomName()) {
          witchEntity.setCustomName(this.getCustomName());
          witchEntity.setCustomNameVisible(this.isCustomNameVisible());
      }
      
      // Unlike other conversion code, this does not check whether this.isPersistent() as well
      if (this.getExperience() > 0) {
          witchEntity.setPersistent();
      }
      
      this.world.spawnEntity(witchEntity);
      this.remove();
      

      Attachments

        Activity

          People

            panda4994 [Mojang] Panda
            haykam haykam
            Votes:
            7 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              CHK: