Search in sources :

Example 1 with IAttributeInstance

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

the class GuiIngameForge method renderHealth.

public void renderHealth(int width, int height) {
    bind(ICONS);
    if (pre(HEALTH))
        return;
    mc.mcProfiler.startSection("health");
    GlStateManager.enableBlend();
    EntityPlayer player = (EntityPlayer) this.mc.getRenderViewEntity();
    int health = MathHelper.ceil(player.getHealth());
    boolean highlight = healthUpdateCounter > (long) updateCounter && (healthUpdateCounter - (long) updateCounter) / 3L % 2L == 1L;
    if (health < this.playerHealth && player.hurtResistantTime > 0) {
        this.lastSystemTime = Minecraft.getSystemTime();
        this.healthUpdateCounter = (long) (this.updateCounter + 20);
    } else if (health > this.playerHealth && player.hurtResistantTime > 0) {
        this.lastSystemTime = Minecraft.getSystemTime();
        this.healthUpdateCounter = (long) (this.updateCounter + 10);
    }
    if (Minecraft.getSystemTime() - this.lastSystemTime > 1000L) {
        this.playerHealth = health;
        this.lastPlayerHealth = health;
        this.lastSystemTime = Minecraft.getSystemTime();
    }
    this.playerHealth = health;
    int healthLast = this.lastPlayerHealth;
    IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
    float healthMax = (float) attrMaxHealth.getAttributeValue();
    float absorb = MathHelper.ceil(player.getAbsorptionAmount());
    int healthRows = MathHelper.ceil((healthMax + absorb) / 2.0F / 10.0F);
    int rowHeight = Math.max(10 - (healthRows - 2), 3);
    this.rand.setSeed((long) (updateCounter * 312871));
    int left = width / 2 - 91;
    int top = height - left_height;
    left_height += (healthRows * rowHeight);
    if (rowHeight != 10)
        left_height += 10 - rowHeight;
    int regen = -1;
    if (player.isPotionActive(MobEffects.REGENERATION)) {
        regen = updateCounter % 25;
    }
    final int TOP = 9 * (mc.world.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
    final int BACKGROUND = (highlight ? 25 : 16);
    int MARGIN = 16;
    if (player.isPotionActive(MobEffects.POISON))
        MARGIN += 36;
    else if (player.isPotionActive(MobEffects.WITHER))
        MARGIN += 72;
    float absorbRemaining = absorb;
    for (int i = MathHelper.ceil((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) {
        //int b0 = (highlight ? 1 : 0);
        int row = MathHelper.ceil((float) (i + 1) / 10.0F) - 1;
        int x = left + i % 10 * 8;
        int y = top - row * rowHeight;
        if (health <= 4)
            y += rand.nextInt(2);
        if (i == regen)
            y -= 2;
        drawTexturedModalRect(x, y, BACKGROUND, TOP, 9, 9);
        if (highlight) {
            if (i * 2 + 1 < healthLast)
                //6
                drawTexturedModalRect(x, y, MARGIN + 54, TOP, 9, 9);
            else if (i * 2 + 1 == healthLast)
                //7
                drawTexturedModalRect(x, y, MARGIN + 63, TOP, 9, 9);
        }
        if (absorbRemaining > 0.0F) {
            if (absorbRemaining == absorb && absorb % 2.0F == 1.0F) {
                //17
                drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9);
                absorbRemaining -= 1.0F;
            } else {
                //16
                drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9);
                absorbRemaining -= 2.0F;
            }
        } else {
            if (i * 2 + 1 < health)
                //4
                drawTexturedModalRect(x, y, MARGIN + 36, TOP, 9, 9);
            else if (i * 2 + 1 == health)
                //5
                drawTexturedModalRect(x, y, MARGIN + 45, TOP, 9, 9);
        }
    }
    GlStateManager.disableBlend();
    mc.mcProfiler.endSection();
    post(HEALTH);
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with IAttributeInstance

use of net.minecraft.entity.ai.attributes.IAttributeInstance in project minecolonies by Minecolonies.

the class ItemCaliper method onItemUse.

@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World worldIn, final BlockPos pos, final EnumHand hand, final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
    // if client world, do nothing
    if (worldIn.isRemote) {
        return EnumActionResult.FAIL;
    }
    // if attribute instance is not known, register it.
    IAttributeInstance attribute = player.getEntityAttribute(ATTRIBUTE_CALIPER_USE);
    if (attribute == null) {
        attribute = player.getAttributeMap().registerAttribute(ATTRIBUTE_CALIPER_USE);
    }
    // if the value of the attribute is still 0, set the start values. (first point)
    if (attribute.getAttributeValue() < HALF) {
        startPosition = pos;
        attribute.setBaseValue(1.0);
        return EnumActionResult.SUCCESS;
    }
    attribute.setBaseValue(0.0);
    //Start == end, same location
    if (startPosition.getX() == pos.getX() && startPosition.getY() == pos.getY() && startPosition.getZ() == pos.getZ()) {
        LanguageHandler.sendPlayerMessage(player, ITEM_CALIPER_MESSAGE_SAME);
        return EnumActionResult.FAIL;
    }
    return handlePlayerMessage(player, pos);
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance)

Example 3 with IAttributeInstance

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

the class AMEventHandler method onEntityLiving.

@SubscribeEvent
public void onEntityLiving(LivingUpdateEvent event) {
    EntityLivingBase ent = event.entityLiving;
    World world = ent.worldObj;
    BuffStatModifiers.instance.applyStatModifiersBasedOnBuffs(ent);
    ExtendedProperties extendedProperties;
    extendedProperties = ExtendedProperties.For(ent);
    extendedProperties.handleSpecialSyncData();
    extendedProperties.manaBurnoutTick();
    //archmage armor effects & infusion
    if (ent instanceof EntityPlayer) {
        if (ent.worldObj.isRemote) {
            int divisor = extendedProperties.getAuraDelay() > 0 ? extendedProperties.getAuraDelay() : 1;
            if (ent.ticksExisted % divisor == 0)
                AMCore.instance.proxy.particleManager.spawnAuraParticles(ent);
            AMCore.proxy.setViewSettings();
        }
        ArmorHelper.HandleArmorInfusion((EntityPlayer) ent);
        ArmorHelper.HandleArmorEffects((EntityPlayer) ent, world);
        extendedProperties.flipTick();
        if (extendedProperties.getIsFlipped()) {
            if (((EntityPlayer) ent).motionY < 2)
                ((EntityPlayer) ent).motionY += 0.15f;
            double posY = ent.posY + ent.height;
            if (!world.isRemote)
                posY += ent.getEyeHeight();
            if (world.rayTraceBlocks(Vec3.createVectorHelper(ent.posX, posY, ent.posZ), Vec3.createVectorHelper(ent.posX, posY + 1, ent.posZ), true) != null) {
                if (!ent.onGround) {
                    if (ent.fallDistance > 0) {
                        try {
                            Method m = ReflectionHelper.findMethod(Entity.class, ent, new String[] { "func_70069_a", "fall" }, float.class);
                            m.setAccessible(true);
                            m.invoke(ent, ent.fallDistance);
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                        ent.fallDistance = 0;
                    }
                }
                ent.onGround = true;
            } else {
                if (ent.motionY > 0) {
                    if (world.isRemote)
                        ent.fallDistance += ent.posY - ent.prevPosY;
                    else
                        ent.fallDistance += (((EntityPlayer) ent).field_71095_bQ - ((EntityPlayer) ent).field_71096_bN) * 2;
                }
                ent.onGround = false;
            }
        }
        if (ArmorHelper.isInfusionPreset(((EntityPlayer) ent).getCurrentArmor(1), GenericImbuement.stepAssist)) {
            ent.stepHeight = 1.0111f;
        } else if (ent.stepHeight == 1.0111f) {
            ent.stepHeight = 0.5f;
        }
        IAttributeInstance attr = ent.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
        if (ArmorHelper.isInfusionPreset(((EntityPlayer) ent).getCurrentArmor(0), GenericImbuement.runSpeed)) {
            if (attr.getModifier(GenericImbuement.imbuedHasteID) == null) {
                attr.applyModifier(GenericImbuement.imbuedHaste);
            }
        } else {
            if (attr.getModifier(GenericImbuement.imbuedHasteID) != null) {
                attr.removeModifier(GenericImbuement.imbuedHaste);
            }
        }
    }
    if (!ent.onGround && ent.fallDistance >= 4f && extendedProperties.getContingencyType() == ContingencyTypes.FALL && extendedProperties.getContingencyEffect() != null) {
        int distanceToGround = MathUtilities.getDistanceToGround(ent, world);
        if (distanceToGround < -8 * ent.motionY) {
            extendedProperties.procContingency();
        }
    }
    if (extendedProperties.getContingencyType() == ContingencyTypes.ON_FIRE && ent.isBurning()) {
        extendedProperties.procContingency();
    }
    if (!ent.worldObj.isRemote && ent.ticksExisted % 200 == 0) {
        extendedProperties.setSyncAuras();
    }
    //buff particles
    //if (ent.worldObj.isRemote)
    //	AMCore.instance.proxy.particleManager.spawnBuffParticles(ent);
    //data sync
    extendedProperties.handleExtendedPropertySync();
    if (ent instanceof EntityPlayer) {
        AffinityData.For(ent).handleExtendedPropertySync();
        SkillData.For((EntityPlayer) ent).handleExtendedPropertySync();
        if (ent.isPotionActive(BuffList.flight.id) || ent.isPotionActive(BuffList.levitation.id) || ((EntityPlayer) ent).capabilities.isCreativeMode) {
            extendedProperties.hadFlight = true;
            if (ent.isPotionActive(BuffList.levitation)) {
                if (((EntityPlayer) ent).capabilities.isFlying) {
                    float factor = 0.4f;
                    ent.motionX *= factor;
                    ent.motionZ *= factor;
                    ent.motionY *= 0.0001f;
                }
            }
        } else if (extendedProperties.hadFlight) {
            ((EntityPlayer) ent).capabilities.allowFlying = false;
            ((EntityPlayer) ent).capabilities.isFlying = false;
            extendedProperties.hadFlight = false;
        }
    }
    if (ent.isPotionActive(BuffList.agility.id)) {
        ent.stepHeight = 1.01f;
    } else if (ent.stepHeight == 1.01f) {
        ent.stepHeight = 0.5f;
    }
    if (!ent.worldObj.isRemote && EntityUtilities.isSummon(ent) && !EntityUtilities.isTileSpawnedAndValid(ent)) {
        int owner = EntityUtilities.getOwner(ent);
        Entity ownerEnt = ent.worldObj.getEntityByID(owner);
        if (!EntityUtilities.decrementSummonDuration(ent)) {
            ent.attackEntityFrom(DamageSources.unsummon, 5000);
        }
        if (owner == -1 || ownerEnt == null || ownerEnt.isDead || ownerEnt.getDistanceSqToEntity(ent) > 900) {
            if (ent instanceof EntityLiving && !((EntityLiving) ent).getCustomNameTag().equals("")) {
                EntityUtilities.setOwner(ent, null);
                EntityUtilities.setSummonDuration(ent, -1);
                EntityUtilities.revertAI((EntityCreature) ent);
            } else {
                ent.attackEntityFrom(DamageSources.unsummon, 5000);
            }
        }
    }
    //leap buff
    if (event.entityLiving.isPotionActive(BuffList.leap)) {
        int amplifier = event.entityLiving.getActivePotionEffect(BuffList.leap).getAmplifier() + 1;
        switch(amplifier) {
            case BuffPowerLevel.Low:
                extendedProperties.setFallProtection(8);
                break;
            case BuffPowerLevel.Medium:
                extendedProperties.setFallProtection(20);
                break;
            case BuffPowerLevel.High:
                extendedProperties.setFallProtection(45);
                break;
            default:
                break;
        }
    }
    if (event.entityLiving.isPotionActive(BuffList.gravityWell)) {
        if (event.entityLiving.motionY < 0 && event.entityLiving.motionY > -3f) {
            event.entityLiving.motionY *= 1.59999999999999998D;
        }
    }
    // (isSneaking calls DataWatcher which are slow, so we test it late)
    if (event.entityLiving.isPotionActive(BuffList.slowfall) || event.entityLiving.isPotionActive(BuffList.shrink) || (ent instanceof EntityPlayer && AffinityData.For(ent).getAffinityDepth(Affinity.NATURE) == 1.0f && !ent.isSneaking())) {
        if (!event.entityLiving.onGround && event.entityLiving.motionY < 0.0D) {
            event.entityLiving.motionY *= 0.79999999999999998D;
        }
    }
    //watery grave
    if (event.entityLiving.isPotionActive(BuffList.wateryGrave)) {
        if (event.entityLiving.isInWater()) {
            double pullVel = -0.5f;
            pullVel *= (event.entityLiving.getActivePotionEffect(BuffList.wateryGrave).getAmplifier() + 1);
            if (event.entityLiving.motionY > pullVel)
                event.entityLiving.motionY -= 0.1;
        }
    }
    //mana link pfx
    if (ent.worldObj.isRemote)
        extendedProperties.spawnManaLinkParticles();
    if (ent.ticksExisted % 20 == 0)
        extendedProperties.cleanupManaLinks();
    if (world.isRemote) {
        AMCore.proxy.sendLocalMovementData(ent);
    }
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Method(java.lang.reflect.Method) World(net.minecraft.world.World) ExtendedProperties(am2.playerextensions.ExtendedProperties) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 with IAttributeInstance

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

the class BuffEffectHaste method applyEffect.

@Override
public void applyEffect(EntityLivingBase entityliving) {
    IAttributeInstance attributeinstance = entityliving.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
    if (attributeinstance.getModifier(hasteID) != null) {
        attributeinstance.removeModifier(hasteSpeedBoost_Diminished);
        attributeinstance.removeModifier(hasteSpeedBoost_Normal);
        attributeinstance.removeModifier(hasteSpeedBoost_Augmented);
    }
    switch(this.getAmplifier()) {
        case 0:
            attributeinstance.applyModifier(hasteSpeedBoost_Diminished);
            break;
        case 1:
            attributeinstance.applyModifier(hasteSpeedBoost_Normal);
            break;
        case 2:
            attributeinstance.applyModifier(hasteSpeedBoost_Augmented);
            break;
    }
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance)

Example 5 with IAttributeInstance

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

the class BuffEffectFrostSlowed method applyEffect.

@Override
public void applyEffect(EntityLivingBase entityliving) {
    IAttributeInstance attributeinstance = entityliving.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
    if (attributeinstance.getModifier(frostSlowID) != null) {
        attributeinstance.removeModifier(frostSlow_Diminished);
        attributeinstance.removeModifier(frostSlow_Normal);
        attributeinstance.removeModifier(frostSlow_Augmented);
    }
    switch(this.getAmplifier()) {
        case 0:
            attributeinstance.applyModifier(frostSlow_Diminished);
            break;
        case 1:
            attributeinstance.applyModifier(frostSlow_Normal);
            break;
        case 2:
            attributeinstance.applyModifier(frostSlow_Augmented);
            break;
    }
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance)

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