@SideOnly(Side.CLIENT) public void addDetails(ItemStack itemstack, EntityPlayer player, @Nullable World worldIn, List<String> infos) { super.addDetails(itemstack, player, worldIn, infos); Multimap<String, AttributeModifier> multimap = getModifiers(MOPlayerCapabilityProvider.GetAndroidCapability(player), itemstack); if (multimap != null) { multimap.values() .forEach(modifier -> { switch (modifier.getOperation()) { case 0: infos.add(TextFormatting.GREEN + String.format("%s: +%s", modifier.getName(), modifier.getAmount())); break; case 1: infos.add(TextFormatting.GREEN + String.format("%s: %s", modifier.getName(), (modifier.getAmount() >= 0 ? "+" : "") + DecimalFormat.getPercentInstance().format(modifier.getAmount()))); break; default: infos.add(TextFormatting.GREEN + String.format("%s: %s", modifier.getName(), DecimalFormat.getPercentInstance().format(modifier.getAmount() + 1))); } }); } }
private double getAttribute(EntityPlayer player, ItemStack stack, Multimap<String, AttributeModifier> map, String key) { if(player == null) // apparently this can happen return 0; Collection<AttributeModifier> collection = map.get(key); if(collection.isEmpty()) return 0; AttributeModifier attributemodifier = collection.iterator().next(); double d0 = attributemodifier.getAmount(); boolean flag = false; if(key.equals("generic.attackDamage")) { d0 += player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getBaseValue(); d0 += (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED); } else if(key.equals("generic.attackSpeed")) d0 += player.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED).getBaseValue(); return d0; }
/** * Gets the amount of melee damage delt by the specified item * @param itemStack * @return -1 if it doesn't have a damage modifier */ public static double GetItemWeaponDamage(ItemStack itemStack) { Multimap multimap = itemStack.getItem().getAttributeModifiers(itemStack); if (multimap.containsKey(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName())) { Collection attributes = multimap.get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()); if (attributes.size() > 0) { Object attribute = attributes.iterator().next(); if (attribute instanceof AttributeModifier) { AttributeModifier weaponModifier = (AttributeModifier)attribute; return weaponModifier.getAmount(); } } } return -1; }
public static double getMaxHealth(EntityLivingBase living) { IAttributeInstance healthAttribute = living.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); double maxHealth = healthAttribute.getBaseValue(); AttributeModifier modifier = healthAttribute.getModifier(HEALTH_MODIFIER_ID); if (modifier != null) { maxHealth += modifier.getAmount(); } return maxHealth; }
double d0 = attributemodifier.getAmount();
public ItemStack addAttributeToPart(ItemStack part, AttributeModifier attribute) { if (part.getTagCompound() == null) { part.setTagCompound(new NBTTagCompound()); } NBTTagList attributeList = part.getTagCompound().getTagList("CustomAttributes", Constants.NBT.TAG_COMPOUND); NBTTagCompound attributeTag = new NBTTagCompound(); attributeTag.setString("Name", attribute.getName()); attributeTag.setDouble("Amount", attribute.getAmount()); attributeTag.setString("UUID", attribute.getID().toString()); attributeTag.setByte("Operation", (byte) attribute.getOperation()); attributeList.appendTag(attributeTag); part.setTagInfo("CustomAttributes", attributeList); return part; }