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())));
}
}
}
}
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())));
}
}
}
}
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()));
}
}
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);
}
}
}
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());
}
}
Aggregations