use of net.minecraft.entity.ai.attributes.IAttribute in project Bewitchment by Um-Mitternacht.
the class BrewUtils method addPotionTooltip.
@SideOnly(Side.CLIENT)
public static void addPotionTooltip(ItemStack itemIn, List<String> tooltip) {
List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemIn);
List<Tuple<String, AttributeModifier>> attributes = Lists.newArrayList();
if (list.isEmpty()) {
tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + "---");
} else {
for (PotionEffect effect : list) {
StringBuilder string = new StringBuilder();
string.append(" - ").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, 1.0F)).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." + 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." + tuple.getFirst())));
}
}
}
}
use of net.minecraft.entity.ai.attributes.IAttribute in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class ItemKeyblade method replaceModifier.
private void replaceModifier(Multimap<String, AttributeModifier> modifierMultimap, IAttribute attribute, UUID id, double multiplier) {
// Get the modifiers for the specified attribute
final Collection<AttributeModifier> modifiers = modifierMultimap.get(attribute.getName());
// Find the modifier with the specified ID, if any
final Optional<AttributeModifier> modifierOptional = modifiers.stream().filter(attributeModifier -> attributeModifier.getID().equals(id)).findFirst();
if (modifierOptional.isPresent()) {
// If it exists,
final AttributeModifier modifier = modifierOptional.get();
// Remove it
modifiers.remove(modifier);
// Add the new modifier
modifiers.add(new AttributeModifier(modifier.getID(), modifier.getName(), modifier.getAmount() * multiplier, modifier.getOperation()));
}
}
use of net.minecraft.entity.ai.attributes.IAttribute in project ArsMagica2 by Mithion.
the class BuffStatModifiers method applyAllModifiers.
private void applyAllModifiers(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()) {
if (currentModifier != null) {
inst.removeModifier(currentModifier);
}
inst.applyModifier(entry.getValue());
}
}
}
Aggregations