Search in sources :

Example 26 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method clearAttributes.

public static ItemStack clearAttributes(ItemStack original) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
    NBTTagCompound compound = nmsStack.hasTag() ? nmsStack.getTag() : new NBTTagCompound();
    NBTTagList modifiers = new NBTTagList();
    setAttribute(modifiers, "dummy", 0, "dummyslot", 0);
    compound.set("AttributeModifiers", modifiers);
    nmsStack.setTag(compound);
    return CraftItemStack.asBukkitCopy(nmsStack);
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 27 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method getAttribute.

public static double getAttribute(ItemStack stack, String attribute) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
    if (nmsStack.hasTag()) {
        NBTTagCompound compound = nmsStack.getTag();
        NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
        if (modifiers != null) {
            for (int index = 0; index < modifiers.size(); index++) {
                NBTTagCompound attributeTag = modifiers.get(index);
                if (attributeTag.getString("AttributeName").equals(attribute))
                    return attributeTag.getDouble("Amount");
            }
            return Double.NaN;
        } else
            return Double.NaN;
    } else
        return Double.NaN;
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 28 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method getAttributes.

public static Single[] getAttributes(ItemStack stack) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
    if (nmsStack.hasTag()) {
        NBTTagCompound compound = nmsStack.getTag();
        NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
        if (modifiers != null) {
            Single[] attributes = new Single[modifiers.size()];
            for (int index = 0; index < modifiers.size(); index++) {
                NBTTagCompound attributeTag = modifiers.get(index);
                String attribute = attributeTag.getString("Name");
                String slot = attributeTag.getString("Slot");
                int operation = attributeTag.getInt("Operation");
                double amount = attributeTag.getDouble("Amount");
                attributes[index] = new Single(attribute, slot, operation, amount);
            }
            return attributes;
        } else {
            return new Single[0];
        }
    } else {
        return new Single[0];
    }
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString)

Example 29 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method createWithAttributes.

public static ItemStack createWithAttributes(Material type, int amount, Single... attributes) {
    ItemStack original = new ItemStack(type, amount);
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
    NBTTagCompound compound = nmsStack.hasTag() ? nmsStack.getTag() : new NBTTagCompound();
    NBTTagList modifiers = new NBTTagList();
    if (attributes.length == 0)
        setAttribute(modifiers, "dummy", 0, "dummyslot", 0);
    for (Single attribute : attributes) setAttribute(modifiers, attribute.attribute, attribute.value, attribute.slot, attribute.operation);
    compound.set("AttributeModifiers", modifiers);
    nmsStack.setTag(compound);
    return CraftItemStack.asCraftMirror(nmsStack);
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 30 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method listAttributes.

public static String[] listAttributes(ItemStack stack) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
    if (nmsStack.hasTag()) {
        NBTTagCompound compound = nmsStack.getTag();
        NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
        if (modifiers != null) {
            String[] attributes = new String[modifiers.size()];
            for (int index = 0; index < modifiers.size(); index++) {
                NBTTagCompound attributeTag = modifiers.get(index);
                attributes[index] = attributeTag.getString("AttributeName") + ": " + attributeTag.getDouble("Amount");
            }
            return attributes;
        } else
            return null;
    } else
        return null;
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)24 ArrayList (java.util.ArrayList)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)20 ListTag (com.wasteofplastic.org.jnbt.ListTag)20 StringTag (com.wasteofplastic.org.jnbt.StringTag)20 Tag (com.wasteofplastic.org.jnbt.Tag)20 Map (java.util.Map)20 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)17 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)17 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)8 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)6 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)6 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_16_R3.NBTTagList)5 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_9_R2.NBTTagList)5