Search in sources :

Example 6 with IAttribute

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

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()));
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) Multimap(com.google.common.collect.Multimap) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Minecraft(net.minecraft.client.Minecraft) EnumDoorHalf(net.minecraft.block.BlockDoor.EnumDoorHalf) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) SoundCategory(net.minecraft.util.SoundCategory) ItemSword(net.minecraft.item.ItemSword) EnumHelper(net.minecraftforge.common.util.EnumHelper) SoundEvents(net.minecraft.init.SoundEvents) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) World(net.minecraft.world.World) Collection(java.util.Collection) ModCapabilities(uk.co.wehavecookies56.kk.common.capability.ModCapabilities) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) ModItems(uk.co.wehavecookies56.kk.common.item.ModItems) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) PacketDispatcher(uk.co.wehavecookies56.kk.common.network.packet.PacketDispatcher) ActionResult(net.minecraft.util.ActionResult) BlockDoor(net.minecraft.block.BlockDoor) PlayerStatsCapability(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability) AttackEntity(uk.co.wehavecookies56.kk.common.network.packet.server.AttackEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) Optional(java.util.Optional) SoundEvent(net.minecraft.util.SoundEvent) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 8 with IAttribute

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());
        }
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

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