Search in sources :

Example 1 with IFactionMob

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;
        }
    };
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IFactionMob(com.lying.variousoddities.api.entity.IFactionMob) LivingData(com.lying.variousoddities.capabilities.LivingData) FactionManager(com.lying.variousoddities.world.savedata.FactionManager) PlayerData(com.lying.variousoddities.capabilities.PlayerData) Predicate(java.util.function.Predicate) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IFactionMob (com.lying.variousoddities.api.entity.IFactionMob)1 LivingData (com.lying.variousoddities.capabilities.LivingData)1 PlayerData (com.lying.variousoddities.capabilities.PlayerData)1 FactionManager (com.lying.variousoddities.world.savedata.FactionManager)1 Faction (com.lying.variousoddities.world.savedata.FactionManager.Faction)1 Predicate (java.util.function.Predicate)1 LivingEntity (net.minecraft.entity.LivingEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1