Search in sources :

Example 1 with GatherAbilitiesEvent

use of com.lying.variousoddities.api.event.GatherAbilitiesEvent in project VariousOddities by Lyinginbedmon.

the class Abilities method getEntityAbilities.

public Map<ResourceLocation, Ability> getEntityAbilities(@Nullable LivingEntity entityIn) {
    if (entityIn != null) {
        Map<ResourceLocation, Ability> abilityMap = new HashMap<>();
        // Collect abilities from creature's types
        EnumCreatureType.getTypes(entityIn).addAbilitiesToMap(abilityMap);
        // Collect abilities from creature's LivingData
        LivingData bodyData = LivingData.forEntity(entityIn);
        if (bodyData != null) {
            if (bodyData.hasSpecies())
                abilityMap = bodyData.getSpecies().addToMap(abilityMap);
            if (bodyData.hasTemplates())
                for (Template template : bodyData.getTemplates()) template.applyAbilityOperations(abilityMap);
            abilityMap = bodyData.getAbilities().addCustomToMap(abilityMap);
        }
        // Remove any existing temporary abilities (these should never exist in the standard sources)
        List<ResourceLocation> invalid = Lists.newArrayList();
        abilityMap.forEach((mapName, ability) -> {
            if (ability.isTemporary())
                invalid.add(mapName);
        });
        for (ResourceLocation mapName : invalid) abilityMap.remove(mapName);
        GatherAbilitiesEvent event = new GatherAbilitiesEvent(entityIn, abilityMap, cachedAbilities);
        MinecraftForge.EVENT_BUS.post(event);
        abilityMap = event.getAbilityMap();
        // Add in new temporary abilities
        for (Ability ability : event.getTempAbilities().values()) if (!abilityMap.containsKey(ability.getMapName()))
            abilityMap.put(ability.getMapName(), ability);
        List<Ability> subAbilities = gatherSubAbilities(abilityMap.values());
        if (!subAbilities.isEmpty())
            for (Ability ability : subAbilities) if (!abilityMap.containsKey(ability.getMapName()))
                abilityMap.put(ability.getMapName(), ability.clone().setTemporary());
        return abilityMap;
    }
    return new HashMap<>();
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) IBonusJumpAbility(com.lying.variousoddities.species.abilities.IBonusJumpAbility) ICompoundAbility(com.lying.variousoddities.species.abilities.ICompoundAbility) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.util.ResourceLocation) GatherAbilitiesEvent(com.lying.variousoddities.api.event.GatherAbilitiesEvent) Template(com.lying.variousoddities.species.Template)

Aggregations

GatherAbilitiesEvent (com.lying.variousoddities.api.event.GatherAbilitiesEvent)1 Template (com.lying.variousoddities.species.Template)1 Ability (com.lying.variousoddities.species.abilities.Ability)1 IBonusJumpAbility (com.lying.variousoddities.species.abilities.IBonusJumpAbility)1 ICompoundAbility (com.lying.variousoddities.species.abilities.ICompoundAbility)1 HashMap (java.util.HashMap)1 ResourceLocation (net.minecraft.util.ResourceLocation)1