Help with Item Attributes, for 1.15.2 snap changes

Discussion in 'Plugin Development' started by Charliebiff05, Apr 23, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Charliebiff05

    Code:
    net.minecraft.server.v1_15_R2.ItemStack nms = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = new NBTTagCompound();
        NBTTagCompound cmpd = new NBTTagCompound();
        cmpd.set("AttributeName", new NBTTagString("Magika"));
        cmpd.set("Name", new NBTTagString("Magika"));
        cmpd.set("Amount", new NBTTagInt(20));
        cmpd.set("Operation", new NBTTagInt(0));
        cmpd.set("UUIDLeast", new NBTTagInt(894654));
        cmpd.set("UUIDMost", new NBTTagInt(2872));
        cmpd.set("Slot", new NBTTagString("chest"));
        NBTTagList list = new NBTTagList();
        list.add(cmpd);
        tag.set("AttributeModifiers", list);
        nms.setTag(tag);
        ItemStack itemS = CraftItemStack.asCraftMirror(nms);
    please sir I need some help as to where I am going wrong or for any newer methods.
    Code:
    public class Itemsmith {
    
        public ItemStack makeItem(Material m, String name, String desc, int amount) {
         
            ItemStack item = new ItemStack (m, amount);
         
            //Create the item's meta data (name, lore/desc text, etc.)
            ItemMeta im = item.getItemMeta();
            im.setDisplayName(name);
            //Creates the lore
            ArrayList<String> lore = new ArrayList<String>();
            lore.add(desc);
            im.setLore(lore);
            //Hides the vanilla Minecraft tooltip text
            im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
            im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            //Sets the item's meta data to the custom "im" meta data
            item.setItemMeta(im);
         
            return item;
         
        }
     
        public ItemStack buildWeapon(String sword) {
         
            Material m = Material;
            String name = new String();
            String desc = new String();
         
            if ( sword.toLowerCase().equals("midas") ) {
                m = Material.GOLDEN_SWORD;
                name = (ChatColor.GOLD + "" + ChatColor.BOLD + "Sword of King Midas");
                desc = (ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "The golden sword of King Midas!");
            } else if ( sword.toLowerCase().equals("excalibur") ) {
                m = Material.IRON_SWORD;
                name = (ChatColor.GOLD + "" + ChatColor.BOLD + "Sword of King Arthur");
                desc = (ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "The fantastic sword of King Arthur!");
            } else if ( sword.toLowerCase().equals("troll") ) {
                m = Material.STONE_SWORD;
                name = (ChatColor.GOLD + "" + ChatColor.BOLD + "Sword of the Troll King");
                desc = (ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "The powerful and heavy Troll King's sword!");
            }
         
            return makeItem(m, name, desc, 1);
         
        }
     
    }
    Still going wrong but here is what I have now

    Even a simple attack damage attribute version would be fine, I just need tips :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 24, 2020
  2. Offline

    NukerFall

    whats the trouble
     
    Charliebiff05 likes this.
  3. Offline

    Charliebiff05

    private ItemStack addAttribute(ItemStack item, String attribute, int amount, int operation, int least, int most, String slot) {
    net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();

    NBTTagList modifiers = new NBTTagList();
    NBTTagCompound speed = new NBTTagCompound();


    speed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
    speed.set("Name", new NBTTagString("generic.attackSpeed"));
    speed.set("Amount", new NBTTagDouble(0.01));
    speed.set("Operation", new NBTTagInt(0));
    speed.set("UUIDLeast", new NBTTagInt(894654));
    speed.set("UUIDMost", new NBTTagInt(2872));
    speed.set("Slot", new NBTTagString("mainhand"));

    modifiers.add(speed);
    compound.set("AttributeModifiers", modifiers);
    nmsStack.setTag(compound);

    item = CraftItemStack.asBukkitCopy(nmsStack);
    return item;
    }


    Where am I going wrong?!!

    many thnaks for the help - ps this is the latest try I have given it!

    still no luck on my many searches

    Hello? its been three days

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 25, 2020
Thread Status:
Not open for further replies.

Share This Page