1.11 Spigot - How to Render "Glow" Enchantment on Skulls in GUIs

Discussion in 'Spigot Plugin Development' started by ArZor, Mar 7, 2017.

  1. Let me prefix this first by saying I am not a developer, just a humble server owner trying to assist a dev I hired find a solution. So please be patient with me as I may not describe my questions in the most technical or code-based manner. That's not to say don't respond with technical answers, the dev I hired will be reading them and I'm sure they'll understand your suggestions even if I don't. Thanks in advanced :D

    So in a nutshell, we are trying to make it where a player can click a skull representing an online player and make it "glow" to signify it has been selected and then click it again to remove the "glow" enchantment to signify it has been deselected. I was told "this may not be possible due to as of 1.9 skulls don't render enchantments properly. but it may be possible. That information was back from like, probably well over a year ago. It's likely been changed." I hope that the collective genius of all you talented people can help us find a solution :D

    Thanks
    ArZor
     
  2. Just clarifying before I try one or two things, is this just rendering, or does it matter if it has an enchantment on it?
     
  3. Try adding the enchantment then removing the flag


    Sent from my iPhone using Tapatalk
     
  4. I hope I'm understanding your question correctly. I believe it just needs to look like it has the enchantment "render" but doesn't actually physically need to have it since its only meant for display and a player would never actually be able to obtain the item (skull).
     
  5. without a client modification its not possible because minecraft does naturally not render enchantments on skulls.
     
    • Agree Agree x 2
  6. What do you mean by click?
     
  7. Every itemstack has the ability to glow. Register a custom enchantment and add it to the item.

    In your on enable register the enchantment.
    Code (Text):
        public void registerGlow(){
            try {
                Field f = Enchantment.class.getDeclaredField("acceptingNew");
                f.setAccessible(true);
                f.set(null, true);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            try{
                Enchantment.registerEnchantment(ench);
            }catch(Exception e){
             
            }
        }
    Extend enchantment class and make your own enchantment.
    Code (Text):
    package xyz.almia.enchantsystem;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.enchantments.EnchantmentTarget;
    import org.bukkit.inventory.ItemStack;
    public class BlankEnchant extends Enchantment {
        public BlankEnchant(int id) {
            super(id);
        }
        @Override
        public boolean canEnchantItem(ItemStack item) {
            return true;
        }
        @Override
            public boolean conflictsWith(Enchantment other) {
            return false;
        }
        @Override
        public EnchantmentTarget getItemTarget() {
            return null;
        }
        @Override
        public int getMaxLevel() {
            return 2;
        }
        @Override
        public String getName() {
            return "CoolFlyEnchantThingy"; //the name
        }
        @Override
        public int getId(){
            return 69;
        }
        @Override
        public int getStartLevel() {
            return 1;
        }

        @Override
        public boolean isCursed() {
            return false;
        }

        @Override
        public boolean isTreasure() {
            return false;
        }
    }
    Now just add the enchantment with id 69 or whatever id you made onto the itemstack and it will glow. Public knowledge now you can find code like this everywhere.
     
    • Optimistic Optimistic x 1
  8. nice reflection ;p
     
  9. im always confused on exceptions, couldnt you just do catch(Exception e) to cover all the exceptions?
     
  10. You indeed could, it's just not good practice to do so. You should always be printing stack traces on exceptions you catch as well, unless you are expecting it to be thrown and want to do something once it is. This code I posted isn't meant to be copied, rather just to show that you need to register the enchantment in your on enable.
     
  11. I have to agree, just tested it- you can add an enchantment to a skull, but it won't render as glowing.
     
  12. Really? I thought all itemstacks where capable of glowing?
     
  13. Apparently not. It's easy enough to test for yourself.

    In that case I don't think a custom enchantment would make any difference, nor would there be a ProtocolLib solution.
     
  14. here is the related bugreport on mojangs official bugtracker:
    https://bugs.mojang.com/browse/MC-69683
     
    • Informative Informative x 2
  15. Chests for example can't glow either. At least they didn't the last time i tried (beginning of 1.11).