Solved ItemStack createItemWithLore Not work on 1.13.2++

Discussion in 'Spigot Plugin Development' started by Keybax, Jan 11, 2020.

  1. Hello any one can help me ? idk why not work on 1.13++ on 1.8.8 - 1.12.2 was allways work



    Code (YAML):
        public static ItemStack createItemWithLore(final String name, final int id, final int subid, final int anzahl, final String lore) {
            final ItemStack item = new ItemStack(Material.getMaterial(id), anzahl, (short)(byte)subid);
            final ItemMeta im = item.getItemMeta();
            im.setDisplayName(name);
            final List<String> loreL = Lists.newArrayList();
            loreL.add("");
            loreL.add(lore.replaceAll("&", "ยง"));
            loreL.add("");
            im.setLore((List)loreL);
            item.setItemMeta(im);
            return item;
        }
     
  2. first of all, what is not working?
    Second, ItemStacks with integer ids and data bytes and that stuff are long deprecated and should not be used.
    The only constructors that should be used are ItemStack(Material) or ItemStack(Material, amount).
    Everything else can have unpredicted behavior
     
  3. eclipse tell me

    " The method getMaterial(String) in the type Material is not applicable for the arguments (int) "


    .getMaterial is red ...

    i know is old i never have any problem whit this
     
  4. You're getting an error because you're trying to get the ID as a material. Instead, get the material name.
     
    • Like Like x 1

  5. omg.. i am so stupid xDD okay okay ty for the fast help :)
     
  6. yea, read the second part. You should not (and as it seems, you cannot as of 1.13) construct a Material of a String. As @Darrionat pointed out, use the string. Be careful thou as getMaterial() is an enum lookup, the name must be precisely the same (e.g. OAK_PLANKS). If you want to lookup the "minecraft:eek:ak_planks" name, use Material#matchMaterial()

    Edit: "minecraft:\ oak_planks"...