use of de.teamlapen.vampirism.entity.converted.ConvertedVillagerEntity in project Vampirism by TeamLapen.
the class TotemTileEntity method updateCreaturesOnCapture.
private void updateCreaturesOnCapture(boolean fullConvert) {
// noinspection ConstantConditions
List<VillagerEntity> villagerEntities = this.level.getEntitiesOfClass(VillagerEntity.class, getVillageArea());
if (VampirismEventFactory.fireVillagerCaptureEventPre(this, villagerEntities, fullConvert)) {
return;
}
if (VReference.HUNTER_FACTION.equals(this.capturingFaction)) {
List<HunterBaseEntity> hunterEntities = this.level.getEntitiesOfClass(HunterBaseEntity.class, getVillageArea());
int i = Math.max(2, hunterEntities.size() / 2);
for (HunterBaseEntity hunter : hunterEntities) {
if (hunter instanceof ICaptureIgnore)
continue;
if (i-- > 0) {
this.spawnVillagerReplace(hunter, true);
}
}
for (int o = i; o > 0; o--) {
this.spawnVillagerDefault(true);
}
for (VillagerEntity villager : villagerEntities) {
ExtendedCreature.getSafe(villager).ifPresent(e -> e.setPoisonousBlood(true));
}
this.updateTrainer(false);
} else if (VReference.HUNTER_FACTION.equals(this.controllingFaction)) {
updateTrainer(true);
for (VillagerEntity villager : villagerEntities) {
ExtendedCreature.getSafe(villager).ifPresent(e -> e.setPoisonousBlood(false));
}
if (fullConvert) {
List<HunterBaseEntity> hunterEntities = this.level.getEntitiesOfClass(HunterBaseEntity.class, getVillageArea());
for (HunterBaseEntity hunter : hunterEntities) {
if (hunter instanceof ICaptureIgnore)
continue;
// noinspection ConstantConditions
this.spawnEntity(this.getCaptureEntityForFaction(this.capturingFaction).create(this.level), hunter, true, false);
}
}
} else {
updateTrainer(true);
}
if (VReference.VAMPIRE_FACTION.equals(this.capturingFaction)) {
for (VillagerEntity villager : villagerEntities) {
if (!fullConvert) {
if (RNG.nextInt(2) == 1)
continue;
SanguinareEffect.addRandom(villager, false);
} else {
villager.addEffect(new SanguinareEffectInstance(11));
}
}
} else if (VReference.VAMPIRE_FACTION.equals(this.controllingFaction)) {
for (VillagerEntity villager : villagerEntities) {
if (villager.hasEffect(ModEffects.sanguinare))
villager.removeEffect(ModEffects.sanguinare);
if (fullConvert) {
if (villager instanceof ConvertedVillagerEntity) {
this.spawnVillagerReplaceForced(villager, this.capturingFaction == VReference.HUNTER_FACTION);
}
}
}
if (fullConvert) {
List<VampireBaseEntity> vampireEntities = this.level.getEntitiesOfClass(VampireBaseEntity.class, getVillageArea());
for (VampireBaseEntity vampire : vampireEntities) {
if (vampire instanceof ICaptureIgnore)
continue;
// noinspection ConstantConditions
this.spawnEntity(this.getCaptureEntityForFaction(this.capturingFaction).create(this.level), vampire, true, false);
}
}
}
villagerEntities = this.level.getEntitiesOfClass(VillagerEntity.class, getVillageArea());
for (VillagerEntity villager : villagerEntities) {
if (villager.getVillagerData().getProfession() instanceof FactionVillagerProfession) {
villager.setVillagerData(villager.getVillagerData().setProfession(VillagerProfession.NONE));
}
}
VampirismEventFactory.fireVillagerCaptureEventPost(this, villagerEntities, fullConvert);
}
Aggregations