Giving Custom NPC (made with packets) glowing potion effect

Discussion in 'Plugin Development' started by SmearySubset, Jun 22, 2021.

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


    Hello. I made a custom EntityPlayer npc using packets and wanted to give it a glowing effect so other players on the server can see its outline through walls/floors. I've tried researching the answer but I really can't seem to find what I'm looking for. Can anyone assist?

  2. Offline


    bump. Anyone have a solution to this?
  3. Offline


    Well what version are you on?
    Maybe this will help you:

    Specifically this part:
        public void setGlowing(Player glowingPlayer, Player sendPacketPlayer, boolean glow) {
            try {
                EntityPlayer entityPlayer = ((CraftPlayer) glowingPlayer).getHandle();
                DataWatcher dataWatcher = entityPlayer.getDataWatcher();
                entityPlayer.glowing = glow; // For the update method in EntityPlayer to prevent switching back.
                // The map that stores the DataWatcherItems is private within the DataWatcher Object.
                // We need to use Reflection to access it from Apache Commons and change it.
                Map<Integer, DataWatcher.Item<?>> map = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(dataWatcher, "d", true);
                // Get the 0th index for the BitMask value.
                DataWatcher.Item item = map.get(0);
                byte initialBitMask = (Byte) item.b(); // Gets the initial bitmask/byte value so we don't overwrite anything.
                byte bitMaskIndex = (byte) 0x40; // The index as specified in
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex))); // Inverts the specified bit from the index.
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(glowingPlayer.getEntityId(), dataWatcher, true);
                ((CraftPlayer) sendPacketPlayer).getHandle().playerConnection.sendPacket(metadataPacket);
            } catch (IllegalAccessException e) { // Catch statement necessary for FieldUtils.readDeclaredField()
    You know, you could have just googled yourself...

    Anyway you should do a loop and send all players the packet in the same world as the player who should glow.

    Oops I didn't see that it was entityplayer and not player. Sorry, give me some time to read the docs.

    Oh it's a NMS thing, not a CB thing, ok.
    This is annoying can't really find a NMS documentation.

    Have you already tried:
    private EntityPlayer entity;
    entity.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, Integer.MAX_VALUE, 1, true, true, Color.WHITE));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited: Jul 29, 2021
  4. Offline


    As I mentioned in my original prompt, I said I did google it myself but had alot of trouble finding a solution. Yes I have tried addPotionEffect() but you cannot use it on an EntityPlayer and you can't cast it to player nor LivingEntity. So I'm not sure how to handle this.
  5. Offline


    try with NMS
    Last edited: Aug 9, 2021
  6. Offline


    Anyone else have any ideas? I'm still stuck
  7. Offline


    sr m8 but I dont think its possible without atleast some NMS

    I think I found a solution
    new PotionEffect(PotionEffectType.GLOWING,70000, 2
    Last edited: Aug 19, 2021
  8. Offline


    Unfortunately doesn't work. I get the following error:

    Caused by: java.lang.ClassCastException: net.minecraft.server.v1_15_R1.EntityPlayer cannot be cast to org.bukkit.entity.LivingEntity

    Is there a way I could do it in 1.17?
  9. Offline


    I figured it out!!! Try LivingEntity.getBukkitEntity().addPotionEffect()

    Edit: I just realized you can't cast entityplayer to livingentity... does entityplayer contain .getBukkitEntity?
    Last edited: Aug 31, 2021
Thread Status:
Not open for further replies.

Share This Page