net.minecraft.item.Item.getAttributeModifiers()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(1.5k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中net.minecraft.item.Item.getAttributeModifiers()方法的一些代码示例,展示了Item.getAttributeModifiers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getAttributeModifiers()方法的具体详情如下:
包路径:net.minecraft.item.Item
类名称:Item
方法名:getAttributeModifiers

Item.getAttributeModifiers介绍

暂无

代码示例

代码示例来源:origin: SlimeKnights/TinkersConstruct

protected String testToolAttack(ItemStack tinker, ItemStack vanilla) {
 float attack1 = ToolHelper.getActualDamage(tinker, Minecraft.getMinecraft().player);
 float attack2 = 1f;
 for(AttributeModifier mod : vanilla.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, vanilla).get(SharedMonsterAttributes.ATTACK_DAMAGE.getName())) {
  attack2 += mod.getAmount();
 }
 // enchantment
 attack2 += EnchantmentHelper.getModifierForCreature(vanilla, EnumCreatureAttribute.UNDEFINED);
 return genRow("Attack", attack1, attack2);
}

代码示例来源:origin: Zyin055/zyinhud

/**
 * 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;
}

相关文章

微信公众号

最新文章

更多