Item enchantment glow - 1.4.6?!

Discussion in 'Plugin Development' started by TheTinySpider, Dec 9, 2012.

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

    TheTinySpider

    Im getting this error:
    Cannot invoke equalsIgnoreCase(String) on the array type String[]
     
  2. Offline

    stirante

    replace in this line a with lore :D
     
  3. Offline

    TheTinySpider

    stirante Lemme test it, it doesnt show any errors so :)

    stirante

    --EDIT--
    I opened my inv. with NBT edit and saw it had a §r infornt :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  4. Offline

    stirante

    Replace equalsIgnoreCase with contains.
     
  5. Offline

    TheTinySpider

    stirante Yea thanks, i got it all working now! :D
     
  6. Offline

    doomboy00

    Just as a note for those using 1.4.6 the code posted in this thread will no longer work, but taking an update from stirante 's awesome PrettyScaryLib and making a slight tweak the below will work:
    Code:
    public static ItemStack addGlow(ItemStack item){   
        net.minecraft.server.v1_4_6.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = null;
        if (!nmsStack.hasTag()) {
            tag = new NBTTagCompound();
            nmsStack.setTag(tag);
        }
        if (tag == null) tag = nmsStack.getTag();
        NBTTagList ench = new NBTTagList();
        tag.set("ench", ench);
        nmsStack.setTag(tag);
        return CraftItemStack.asCraftMirror(nmsStack);
    }
     
    stirante likes this.
  7. Offline

    stirante

    Yea, in other thread someone told me that. I'll soon update library.
     
  8. Offline

    fireblast709

    Or use ItemMeta ;3 (which kind of makes your library (more) useless ): )
     
  9. Offline

    doomboy00

    fireblast709 how would you achieve a glow with ItemMeta? I'm just getting in to Bukkit and was playing with ItemMeta last night but couldn't see a method where you would be able to do this unless you are setting an enchantment without a name and a minus level as you previously mentioned, would that work?
     
  10. Offline

    fireblast709

    doomboy00 that is one of the cases where ItemMeta fails, sadly enough
     
  11. Offline

    iZanax

    Is it not possible with?
    1. get Lore & get Name
    2. set Echantment
    3. set Lore & set Name

    Succes?
     
  12. Offline

    gamerzap

    You people are overcomplicating this... I'm pretty certain you can just use an enchantment with an ID that doesn't exist. (Worked for me)
     
  13. Offline

    fireblast709

    Do you have a working snippet for this? I remember something with an ArrayIndexOutOfBoundsException, or a NullPointerException with this method
     
  14. Offline

    gamerzap

    No, I accidently did it a while a go. I might have done something special that made it work, I'm not sure.
     
  15. Offline

    TheTinySpider

    So how todo this is 1.4.6??

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  16. Offline

    stirante

    Code:
    package com.stirante.ChunkWars.Items;
    
    import net.minecraft.server.v1_4_6.NBTTagCompound;
    import net.minecraft.server.v1_4_6.NBTTagList;
    
    import org.bukkit.craftbukkit.v1_4_6.inventory.CraftItemStack;
    import org.bukkit.inventory.ItemStack;
    
    /**
     * Class, that allows adding glow effect to item.
     */
    public class EnchantGlow {
        
        /**
         * Adds the glow.
         * 
         * @param item
         *            the item
         * @return the item stack
         */
        public static ItemStack addGlow(ItemStack item) {
            net.minecraft.server.v1_4_6.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag = null;
            if (!nmsStack.hasTag()) {
                tag = new NBTTagCompound();
                nmsStack.setTag(tag);
            }
            if (tag == null) tag = nmsStack.getTag();
            NBTTagList ench = new NBTTagList();
            tag.set("ench", ench);
            nmsStack.setTag(tag);
            return CraftItemStack.asCraftMirror(nmsStack);
        }
        
        /**
         * Removes the glow.
         * 
         * @param item
         *            the item
         * @return the item stack
         */
        public static ItemStack removeGlow(ItemStack item) {
            net.minecraft.server.v1_4_6.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag = null;
            if (!nmsStack.hasTag()) return item;
            tag = nmsStack.getTag();
            tag.set("ench", null);
            nmsStack.setTag(tag);
            return CraftItemStack.asCraftMirror(nmsStack);
        }
    }
    
    I'm using this code and it works on 1.4.6.
     
  17. Offline

    iZanax

    The snippet what stirante provided doesn't work any more in 1.4.7
    So I'm wondering if there are any other/new ways to add and remove glow to an Itemstack without having the problems with the Name/Lore/Effect?

    Thanks in advance.
     
  18. Offline

    DarkBladee12

    iZanax works fine for me even in 1.4.7 ^^
     
  19. Offline

    iZanax

    Its seems like it not compatible with already set lore/name.
    On a clean ItemStack its works perfect, but on my ItemStack with name/lore I doesn't work.
    Is there a work-around for this issue?
     
  20. Offline

    stirante

    You have to set glow AFTER setting name/lore. ItemMeta deletes all tags when you're setting lore/name/any custom nbt stuff with api.
     
Thread Status:
Not open for further replies.

Share This Page