Search in sources :

Example 1 with IAttribute

use of net.minecraft.entity.ai.attributes.IAttribute in project Witchworks by Um-Mitternacht.

the class BrewUtils method addPotionTooltip.

@SideOnly(Side.CLIENT)
public static void addPotionTooltip(ItemStack itemIn, List<String> tooltip, float durationFactor) {
    List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemIn);
    List<Tuple<String, AttributeModifier>> attributes = Lists.newArrayList();
    if (list.isEmpty()) {
        String empty = I18n.format("effect.none").trim();
        tooltip.add(TextFormatting.GRAY + empty);
    } else {
        for (PotionEffect effect : list) {
            StringBuilder string = new StringBuilder();
            string.append(I18n.format(effect.getEffectName()).trim());
            Potion potion = effect.getPotion();
            Map<IAttribute, AttributeModifier> map = potion.getAttributeModifierMap();
            if (!map.isEmpty()) {
                for (Map.Entry<IAttribute, AttributeModifier> entry : map.entrySet()) {
                    AttributeModifier attribute = entry.getValue();
                    attribute = new AttributeModifier(attribute.getName(), potion.getAttributeModifierAmount(effect.getAmplifier(), attribute), attribute.getOperation());
                    attributes.add(new Tuple<>(entry.getKey().getName(), attribute));
                }
            }
            if (effect.getAmplifier() > 0) {
                string.append(" ").append(RomanNumber.getRoman(effect.getAmplifier()));
            }
            if (effect.getDuration() > 20) {
                string.append(" (").append(Potion.getPotionDurationString(effect, durationFactor)).append(")");
            }
            if (potion.isBadEffect()) {
                tooltip.add(TextFormatting.DARK_RED + string.toString());
            } else {
                tooltip.add(TextFormatting.DARK_BLUE + string.toString());
            }
        }
    }
    if (!attributes.isEmpty()) {
        tooltip.add("");
        tooltip.add(TextFormatting.DARK_PURPLE + I18n.format("potion.whenDrank"));
        for (Tuple<String, AttributeModifier> tuple : attributes) {
            AttributeModifier modifier = tuple.getSecond();
            double amount = modifier.getAmount();
            double newAmount;
            if (modifier.getOperation() != 1 && modifier.getOperation() != 2) {
                newAmount = modifier.getAmount();
            } else {
                newAmount = modifier.getAmount() * 100.0D;
            }
            if (amount > 0.0D) {
                tooltip.add(TextFormatting.BLUE + I18n.format("attribute.modifier.plus." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + (String) tuple.getFirst())));
            } else if (amount < 0.0D) {
                newAmount = newAmount * -1.0D;
                tooltip.add(TextFormatting.RED + I18n.format("attribute.modifier.take." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + (String) tuple.getFirst())));
            }
        }
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) Potion(net.minecraft.potion.Potion) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) Tuple(net.minecraft.util.Tuple) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IAttribute

use of net.minecraft.entity.ai.attributes.IAttribute in project GregTech by GregTechCE.

the class GTUtility method addPotionTooltip.

/**
 * Adds potion tooltip into given lines list
 *
 * @param potions potion effects to add to tooltip
 * @param lines   description lines
 */
@SideOnly(Side.CLIENT)
public static void addPotionTooltip(Iterable<PotionEffect> potions, List<String> lines) {
    ArrayList<Tuple<String, AttributeModifier>> attributeLines = new ArrayList<>();
    for (PotionEffect potionEffect : potions) {
        String line = I18n.format(potionEffect.getEffectName());
        Potion potion = potionEffect.getPotion();
        Map<IAttribute, AttributeModifier> attributes = potionEffect.getPotion().getAttributeModifierMap();
        if (!attributes.isEmpty()) {
            for (Map.Entry<IAttribute, AttributeModifier> entry : attributes.entrySet()) {
                AttributeModifier modifier = entry.getValue();
                attributeLines.add(new Tuple<>(entry.getKey().getName(), new AttributeModifier(modifier.getName(), potion.getAttributeModifierAmount(potionEffect.getAmplifier(), modifier), modifier.getOperation())));
            }
        }
        if (potionEffect.getAmplifier() > 0) {
            line = line + " " + I18n.format("potion.potency." + potionEffect.getAmplifier());
        }
        if (potionEffect.getDuration() > 20) {
            line = line + " (" + Potion.getPotionDurationString(potionEffect, 1.0f) + ")";
        }
        if (potion.isBadEffect()) {
            lines.add(TextFormatting.RED + line);
        } else {
            lines.add(TextFormatting.BLUE + line);
        }
    }
    if (!attributeLines.isEmpty()) {
        lines.add("");
        lines.add(TextFormatting.DARK_PURPLE + I18n.format("potion.whenDrank"));
        for (Tuple<String, AttributeModifier> tuple : attributeLines) {
            AttributeModifier modifier = tuple.getSecond();
            double d0 = modifier.getAmount();
            double d1;
            if (modifier.getOperation() != 1 && modifier.getOperation() != 2) {
                d1 = modifier.getAmount();
            } else {
                d1 = modifier.getAmount() * 100.0D;
            }
            if (d0 > 0.0D) {
                lines.add(TextFormatting.BLUE + I18n.format("attribute.modifier.plus." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(d1), I18n.format("attribute.name." + tuple.getFirst())));
            } else if (d0 < 0.0D) {
                d1 = d1 * -1.0D;
                lines.add(TextFormatting.RED + I18n.format("attribute.modifier.take." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(d1), I18n.format("attribute.name." + tuple.getFirst())));
            }
        }
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) Potion(net.minecraft.potion.Potion) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) Tuple(net.minecraft.util.Tuple) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IAttribute

use of net.minecraft.entity.ai.attributes.IAttribute in project Bewitchment by Um-Mitternacht.

the class BrewAttributeModifier method applyAttributeModifiers.

public void applyAttributeModifiers(AbstractAttributeMap attributeMap, int amplifier) {
    for (Map.Entry<IAttribute, AttributeModifier> entry : modifierMap.entrySet()) {
        IAttributeInstance attribute = attributeMap.getAttributeInstance(entry.getKey());
        if (attribute == null)
            continue;
        AttributeModifier modifier = entry.getValue();
        attribute.removeModifier(modifier);
        attribute.applyModifier(new AttributeModifier(modifier.getID(), this.getName() + " " + amplifier, modifier.getAmount() * (amplifier + 1), modifier.getOperation()));
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) Map(java.util.Map)

Example 4 with IAttribute

use of net.minecraft.entity.ai.attributes.IAttribute 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 5 with IAttribute

use of net.minecraft.entity.ai.attributes.IAttribute in project Bewitchment by Um-Mitternacht.

the class BrewAttributeModifier method removeAttributeModifiers.

public void removeAttributeModifiers(AbstractAttributeMap attributeMapIn, int amplifier) {
    for (Map.Entry<IAttribute, AttributeModifier> entry : modifierMap.entrySet()) {
        IAttributeInstance attribute = attributeMapIn.getAttributeInstance(entry.getKey());
        if (attribute == null)
            continue;
        attribute.removeModifier(entry.getValue());
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) Map(java.util.Map)

Aggregations

AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)8 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)8 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)4 Potion (net.minecraft.potion.Potion)3 PotionEffect (net.minecraft.potion.PotionEffect)3 Tuple (net.minecraft.util.Tuple)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 Map (java.util.Map)2 AbstractAttributeMap (net.minecraft.entity.ai.attributes.AbstractAttributeMap)2 Multimap (com.google.common.collect.Multimap)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 BlockDoor (net.minecraft.block.BlockDoor)1 EnumDoorHalf (net.minecraft.block.BlockDoor.EnumDoorHalf)1 Minecraft (net.minecraft.client.Minecraft)1 SharedMonsterAttributes (net.minecraft.entity.SharedMonsterAttributes)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 SoundEvents (net.minecraft.init.SoundEvents)1 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)1