Persistent villagers without experience can despawn after converting to a witch
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();
Created Issue:
Villager to witch conversion loses persistence if the villager is not experienced
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();
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();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();
Villagerto witch conversion loses persistenceif the villageris notexperiencedVillagers hit by a lightning strike can despawn if the villager has no experience
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();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();
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();
Villagershitby a lightning strike can despawn if the villager has no experiencePersistent villagers without experience can despawn after converting to a witch
