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<>();
}
Aggregations