get ItemStack DMG

Discussion in 'Spigot Plugin Development' started by RayoxHD, May 7, 2017.

  1. Hello,
    How would i get the Damage of an ItemStack ? Version: 1.11.2
     
  2. item.getDurability()

    if you want to get how much durability it has remaining: item.getType().getMaxDurability()-item.getDurability()
     
  3. No i mean the actual attack Damage
     
  4. Your best best would probably be to hardcode damage values for each material and enchantment.
    Alternatively, you could inspect the item's NBT tag with NMS - here's some relevant code from nms ItemStack, but I don't know if this gets damage from enchants:
    Code (Text):
        public Multimap<String, AttributeModifier> a(EnumItemSlot enumitemslot) {
            Multimap<String, AttributeModifier> object;
            if (this.hasTag() && this.tag.hasKeyOfType("AttributeModifiers", 9)) {
                object = HashMultimap.create();
                NBTTagList nbttaglist = this.tag.getList("AttributeModifiers", 10);
                int i2 = 0;
                while (i2 < nbttaglist.size()) {
                    NBTTagCompound nbttagcompound = nbttaglist.get(i2);
                    AttributeModifier attributemodifier = GenericAttributes.a(nbttagcompound);
                    if (attributemodifier != null && (!nbttagcompound.hasKeyOfType("Slot", 8) || nbttagcompound.getString("Slot").equals(enumitemslot.d())) && attributemodifier.a().getLeastSignificantBits() != 0 && attributemodifier.a().getMostSignificantBits() != 0) {
                        object.put(nbttagcompound.getString("AttributeName"), attributemodifier);
                    }
                    ++i2;
                }
            } else {
                object = this.getItem().a(enumitemslot);
            }
            return object;
        }

        public void a(String s, AttributeModifier attributemodifier, @Nullable EnumItemSlot enumitemslot) {
            if (this.tag == null) {
                this.tag = new NBTTagCompound();
            }
            if (!this.tag.hasKeyOfType("AttributeModifiers", 9)) {
                this.tag.set("AttributeModifiers", new NBTTagList());
            }
            NBTTagList nbttaglist = this.tag.getList("AttributeModifiers", 10);
            NBTTagCompound nbttagcompound = GenericAttributes.a(attributemodifier);
            nbttagcompound.setString("AttributeName", s);
            if (enumitemslot != null) {
                nbttagcompound.setString("Slot", enumitemslot.d());
            }
            nbttaglist.add(nbttagcompound);
        }