Giving Custom NPC (made with packets) glowing potion effect

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

  1. Offline

    SmearySubset

    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?

    Thanks!
    SmearySubset
     
  2. Offline

    SmearySubset

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

    Tim_M

    Well what version are you on?
    Maybe this will help you:
    https://www.spigotmc.org/threads/sending-glow-effect-to-player-on-who-im-looking.420594/

    Specifically this part:
    Code:
    @SuppressWarnings("unchecked")
        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. http://wiki.vg/Entities#Entity
                @SuppressWarnings("rawtypes")
                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 wiki.vg/Entities
                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()
                e.printStackTrace();
            }
        }
    
    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.

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

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

    EDIT:
    Have you already tried:
    Code:
    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

    SmearySubset

    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

    Tim_M

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

    SmearySubset

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

    Tim_M

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

    Edit:
    I think I found a solution
    Code:
     ((LivingEntity)customMob).addPotionEffect(
    new PotionEffect(PotionEffectType.GLOWING,70000, 2
    );
    
     
    Last edited: Aug 19, 2021
  8. Offline

    SmearySubset

    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

    Tim_M

    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

Share This Page