use of com.lying.variousoddities.api.entity.IFactionMob in project VariousOddities by Lyinginbedmon.
the class NearestAttackableTargetGoalMixin method getPredicate.
private static Predicate<LivingEntity> getPredicate(LivingEntity goalOwnerIn) {
return new Predicate<LivingEntity>() {
public boolean test(LivingEntity target) {
// Undead mobs do not target other undead
if (goalOwnerIn.isNonBoss() && goalOwnerIn.isEntityUndead())
if (target.isEntityUndead())
return false;
// Mobs do not attack creatures that have mind-controlled them somehow
LivingData mobData = LivingData.forEntity(goalOwnerIn);
if (mobData != null && mobData.isTargetingHindered(target))
return false;
// Faction mobs do not attack mobs with good reputation
if (goalOwnerIn instanceof IFactionMob) {
FactionManager factionManager = FactionManager.get(target.getEntityWorld());
Faction ownerFaction = factionManager.getFaction(goalOwnerIn);
if (ownerFaction != null)
if (target.getType() == EntityType.PLAYER) {
PlayerData data = PlayerData.forPlayer((PlayerEntity) target);
if (data != null) {
int reputation = data.reputation.getReputation(ownerFaction.name);
if (reputation == Integer.MIN_VALUE) {
data.reputation.setReputation(ownerFaction.name, ownerFaction.startingRep);
reputation = ownerFaction.startingRep;
}
return EnumAttitude.fromRep(reputation).allowsInteraction(EnumInteraction.ATTACK);
}
} else if (target instanceof IFactionMob) {
Faction inputFaction = factionManager.getFaction(target);
if (inputFaction != null)
return ownerFaction.relationWith(inputFaction.name).allowsInteraction(EnumInteraction.ATTACK);
}
}
return true;
}
};
}
Aggregations