Search in sources :

Example 1 with AttributeModifier

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

use of net.minecraft.entity.ai.attributes.AttributeModifier in project Minechem by iopleke.

the class AugmentSharp method getAttributeModifiers.

@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(ItemStack stack, int level) {
    Multimap multimap = super.getAttributeModifiers(stack, level);
    multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(AugmentedItem.itemUUID, "Weapon modifier", (double) level, 0));
    return multimap;
}
Also used : Multimap(com.google.common.collect.Multimap) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 3 with AttributeModifier

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

use of net.minecraft.entity.ai.attributes.AttributeModifier in project Gaia-Dimension by Andromander.

the class GDApexPredatorSword method getItemAttributeModifiers.

// TODO: Make this sword special with effects
// TODO: [FUTURE] Can be used to unlock Unknown Spinel Princess Structure
// We will need this in order to make the weapon slow
@Override
@Nonnull
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
    Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
    if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
        // This is not our speed anymore
        multimap.removeAll(SharedMonsterAttributes.ATTACK_SPEED.getName());
        // Speed is set to 0.8; 0.8 less than normal
        multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -3.2, 0));
    }
    return multimap;
}
Also used : AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) Nonnull(javax.annotation.Nonnull)

Example 5 with AttributeModifier

use of net.minecraft.entity.ai.attributes.AttributeModifier in project Gaia-Dimension by Andromander.

the class GDSpinelPrincessSword method getItemAttributeModifiers.

// TODO: Make this sword have fire projectiles, reducig durability by 2
// TODO: [FUTURE] Can be used to unlock Unknown Zircon Prince Structure
// We will need this in order to make the weapon slow
@Override
@Nonnull
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
    Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
    if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
        // This is not our speed anymore
        multimap.removeAll(SharedMonsterAttributes.ATTACK_SPEED.getName());
        // Speed is set to 1; 0.6 less than normal
        multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.5, 0));
    }
    return multimap;
}
Also used : AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) Nonnull(javax.annotation.Nonnull)

Aggregations

AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)107 Nonnull (javax.annotation.Nonnull)19 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)11 ItemStack (net.minecraft.item.ItemStack)9 Multimap (com.google.common.collect.Multimap)8 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)8 UUID (java.util.UUID)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 Calendar (java.util.Calendar)3 Map (java.util.Map)3 Potion (net.minecraft.potion.Potion)3 PotionEffect (net.minecraft.potion.PotionEffect)3 EnergyUpgrade (crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade)2 Collection (java.util.Collection)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 AbstractAttributeMap (net.minecraft.entity.ai.attributes.AbstractAttributeMap)2 ModifiableAttributeInstance (net.minecraft.entity.ai.attributes.ModifiableAttributeInstance)2