use of com.lying.variousoddities.network.PacketAbilityRemove in project VariousOddities by Lyinginbedmon.
the class Abilities method updateAbilityCache.
public void updateAbilityCache() {
if (this.entity == null)
return;
boolean dirty = false;
Map<ResourceLocation, Ability> currentAbilities = getCurrentAbilities();
// If a map name in cachedAbilities doesn't exist in currentAbilities, remove it from cachedAbilities
List<ResourceLocation> removedAbilities = Lists.newArrayList();
cachedAbilities.keySet().forEach((mapname) -> {
if (!currentAbilities.containsKey(mapname))
removedAbilities.add(mapname);
});
if (!removedAbilities.isEmpty())
dirty = true;
removedAbilities.forEach((mapname) -> {
Ability ability = cachedAbilities.get(mapname);
ability.onAbilityRemoved(this.entity);
MinecraftForge.EVENT_BUS.post(new AbilityRemoveEvent(this.entity, ability, this));
if (this.entity.getType() == EntityType.PLAYER)
PacketHandler.sendTo((ServerPlayerEntity) this.entity, new PacketAbilityRemove(mapname));
uncacheAbility(mapname);
});
List<ResourceLocation> overrides = Lists.newArrayList();
currentAbilities.forEach((mapname, ability) -> {
// If the source ID of an ability in currentAbilities doesn't match its counterpart in cachedAbilities, overwrite it in cachedAbilities
if (!cachedAbilities.containsKey(mapname) || !ability.isTemporary() && !ability.getSourceId().equals(cachedAbilities.get(mapname).getSourceId()))
overrides.add(mapname);
});
if (!overrides.isEmpty())
dirty = true;
overrides.forEach((mapname) -> {
Ability ability = currentAbilities.get(mapname);
ability.onAbilityAdded(this.entity);
MinecraftForge.EVENT_BUS.post(new AbilityAddEvent(this.entity, ability, this));
cacheAbility(ability);
});
if (dirty)
markDirty();
this.cacheDirty = false;
}
use of com.lying.variousoddities.network.PacketAbilityRemove in project VariousOddities by Lyinginbedmon.
the class Abilities method removeCustomAbility.
public void removeCustomAbility(ResourceLocation mapName) {
Ability ability = this.customAbilities.get(mapName);
if (ability != null && this.entity != null) {
ability.onAbilityRemoved(this.entity);
MinecraftForge.EVENT_BUS.post(new AbilityRemoveEvent(this.entity, ability, this));
if (this.entity.getType() == EntityType.PLAYER && !this.entity.getEntityWorld().isRemote)
PacketHandler.sendTo((ServerPlayerEntity) this.entity, new PacketAbilityRemove(ability.getMapName()));
}
this.customAbilities.remove(mapName);
markForRecache();
markDirty();
}
Aggregations