Search in sources :

Example 1 with PacketAbilityRemove

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;
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) IBonusJumpAbility(com.lying.variousoddities.species.abilities.IBonusJumpAbility) ICompoundAbility(com.lying.variousoddities.species.abilities.ICompoundAbility) ResourceLocation(net.minecraft.util.ResourceLocation) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbilityRemoveEvent(com.lying.variousoddities.api.event.AbilityEvent.AbilityRemoveEvent) PacketAbilityRemove(com.lying.variousoddities.network.PacketAbilityRemove) AbilityAddEvent(com.lying.variousoddities.api.event.AbilityEvent.AbilityAddEvent)

Example 2 with PacketAbilityRemove

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();
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) IBonusJumpAbility(com.lying.variousoddities.species.abilities.IBonusJumpAbility) ICompoundAbility(com.lying.variousoddities.species.abilities.ICompoundAbility) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbilityRemoveEvent(com.lying.variousoddities.api.event.AbilityEvent.AbilityRemoveEvent) PacketAbilityRemove(com.lying.variousoddities.network.PacketAbilityRemove)

Aggregations

AbilityRemoveEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityRemoveEvent)2 PacketAbilityRemove (com.lying.variousoddities.network.PacketAbilityRemove)2 Ability (com.lying.variousoddities.species.abilities.Ability)2 IBonusJumpAbility (com.lying.variousoddities.species.abilities.IBonusJumpAbility)2 ICompoundAbility (com.lying.variousoddities.species.abilities.ICompoundAbility)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 AbilityAddEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityAddEvent)1 ResourceLocation (net.minecraft.util.ResourceLocation)1