Search in sources :

Example 6 with IAttributeInstance

use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.

the class BuffStatModifiers method clearAllModifiers.

private void clearAllModifiers(EntityLivingBase entity, KeyValuePair<IAttribute, AttributeModifier>... modifiers) {
    for (KeyValuePair<IAttribute, AttributeModifier> entry : modifiers) {
        IAttributeInstance inst = entity.getEntityAttribute(entry.getKey());
        if (inst == null)
            continue;
        AttributeModifier currentModifier = inst.getModifier(entry.getValue().getID());
        if (currentModifier == entry.getValue()) {
            inst.removeModifier(currentModifier);
        }
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 7 with IAttributeInstance

use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.

the class BuffStatModifiers method applyOrRemoveScalingModifiersForBuff.

private void applyOrRemoveScalingModifiersForBuff(EntityLivingBase entity, int potionID, IAttribute attribute, AttributeModifier... modifiers) {
    IAttributeInstance inst = entity.getEntityAttribute(attribute);
    if (inst == null) {
        return;
    }
    AttributeModifier currentModifier = inst.getModifier(modifiers[0].getID());
    if (entity.isPotionActive(potionID)) {
        int magnitude = entity.getActivePotionEffect(Potion.potionTypes[potionID]).getAmplifier();
        AttributeModifier modifier = modifiers[Math.min(magnitude, modifiers.length - 1)];
        if (currentModifier != modifier) {
            if (currentModifier != null) {
                inst.removeModifier(currentModifier);
            }
            inst.applyModifier(modifier);
        }
    } else {
        if (currentModifier != null) {
            inst.removeModifier(currentModifier);
        }
    }
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 8 with IAttributeInstance

use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.

the class AffinityModifiers method applyHealthModifiers.

public void applyHealthModifiers(EntityPlayer ent, float enderDepth, float waterDepth, float fireDepth, float lightningDepth) {
    IAttributeInstance attribute = ent.getEntityAttribute(SharedMonsterAttributes.maxHealth);
    applyOrRemoveModifier(attribute, waterWeakness, ((fireDepth >= 0.5f && fireDepth <= 0.9f) || (enderDepth >= 0.5f && enderDepth <= 0.9f) || (lightningDepth >= 0.5f && lightningDepth <= 0.9f)) && ent.isWet());
    applyOrRemoveModifier(attribute, fireWeakness, (waterDepth >= 0.5f && waterDepth <= 0.9f) && (ent.isBurning() || ent.worldObj.provider.dimensionId == -1));
    int worldTime = (int) ent.worldObj.getWorldTime() % 24000;
    applyOrRemoveModifier(attribute, sunlightWeakness, (enderDepth > 0.65 && enderDepth <= 0.95f) && ent.worldObj.canBlockSeeTheSky((int) ent.posX, (int) ent.posY, (int) ent.posZ) && (worldTime > 23000 || worldTime < 12500));
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance)

Example 9 with IAttributeInstance

use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.

the class AffinityModifiers method applySpeedModifiersBasedOnDepth.

public void applySpeedModifiersBasedOnDepth(EntityPlayer ent, float natureDepth, float iceDepth, float lightningDepth) {
    IAttributeInstance attribute = ent.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
    applyOrRemoveModifier(attribute, natureAffinityRoots, natureDepth >= 0.5f);
    applyOrRemoveModifier(attribute, lightningAffinitySpeed, lightningDepth >= 0.65f);
    applyOrRemoveModifier(attribute, iceAffinityColdBlooded, iceDepth >= 0.1f && !isOnIce(ent));
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance)

Example 10 with IAttributeInstance

use of net.minecraft.entity.ai.attributes.IAttributeInstance in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onEntitySpawnEvent.

@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    World world = event.getWorld();
    int id = world.provider.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
    if (PowerConfiguration.preventSpawnUnpowered) {
        if (dimensionInformation != null) {
            // RFTools dimension.
            DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
            int energy = storage.getEnergyLevel(id);
            if (energy <= 0) {
                event.setResult(Event.Result.DENY);
                Logging.logDebug("Dimension power low: Prevented a spawn of " + event.getEntity().getClass().getName());
            }
        }
    }
    if (dimensionInformation != null) {
        if (dimensionInformation.hasEffectType(EffectType.EFFECT_STRONGMOBS) || dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
            if (event.getEntity() instanceof EntityLivingBase) {
                EntityLivingBase entityLivingBase = (EntityLivingBase) event.getEntity();
                IAttributeInstance entityAttribute = entityLivingBase.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
                double newMax;
                if (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
                    newMax = entityAttribute.getBaseValue() * GeneralConfiguration.brutalMobsFactor;
                } else {
                    newMax = entityAttribute.getBaseValue() * GeneralConfiguration.strongMobsFactor;
                }
                entityAttribute.setBaseValue(newMax);
                entityLivingBase.setHealth((float) newMax);
            }
        }
    }
    if (event.getEntity() instanceof IMob) {
        BlockPos coordinate = new BlockPos((int) event.getEntity().posX, (int) event.getEntity().posY, (int) event.getEntity().posZ);
        /* if (PeacefulAreaManager.isPeaceful(new GlobalCoordinate(coordinate, id))) {
                event.setResult(Event.Result.DENY);
                Logging.logDebug("Peaceful manager: Prevented a spawn of " + event.entity.getClass().getName());
            } else */
        if (dimensionInformation != null && dimensionInformation.isPeaceful()) {
            // RFTools dimension.
            event.setResult(Event.Result.DENY);
            Logging.logDebug("Peaceful dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
        }
    } else if (event.getEntity() instanceof IAnimals) {
        if (dimensionInformation != null && dimensionInformation.isNoanimals()) {
            // RFTools dimension.
            event.setResult(Event.Result.DENY);
            Logging.logDebug("Noanimals dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
        }
    }
// @todo
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)14 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)3 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 World (net.minecraft.world.World)2 EntityAIRangedAttackSpell (am2.entities.ai.EntityAIRangedAttackSpell)1 ExtendedProperties (am2.playerextensions.ExtendedProperties)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 Method (java.lang.reflect.Method)1 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)1 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)1 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 IMob (net.minecraft.entity.monster.IMob)1 IAnimals (net.minecraft.entity.passive.IAnimals)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1