Solved Mob/Entity invisibility NMS no longer works?

Discussion in 'Plugin Help/Development/Requests' started by Drkmaster83, Jun 21, 2015.

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

    Drkmaster83

    I'm trying to make a Zombie invisible, but the NMS won't allow for it. Any ideas?
    Code:
    Zombie z = (Zombie) player.getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE);
    ((CraftEntity)z).getHandle().setInvisible(true);
    The above is psuedocode, but assume 'player' is a Player object that comes from a correctly caster CommandSender in onCommand.
     
  2. Offline

    Drkmaster83

  3. Offline

    Drkmaster83

    Not for basic entities that aren't living (i.e., arrows). Besides, the particles are lame anyways
     
  4. @Drkmaster83 Fair enough, can I see the full code for this class?
     
  5. Offline

    Drkmaster83

    There's no class to be had. The code above is psuedocode, but if you put it anywhere and use the correct imports for your Bukkit (or the unmentionable Spigot, praise be unto it), it will not make the zombie invisible. I can write some if it's truly necessary and give the whole class, but I figure that the above would have been proof enough...
     
  6. @Drkmaster83 For all we know, though, something you were doing with the rest of the code might have broken this. To me, "setInvisible()" definitely sounds like it would make the entity invisible. As I've no experience using the method myself, and don't have the time to test it or anything, I'd rather see it in an actual usage, just in case. :)
     
  7. Offline

    xTrollxDudex

    PacketPlayOutDestroyEntities
     
  8. Offline

    I Al Istannen

    @xTrollxDudex Maybe he wants for example it's name to get rendered though. That isn't always an option.

    @Drkmaster83 To the Potion particles. I believe the last boolean in this constructor is for this.
     
  9. Offline

    xTrollxDudex

    Non living entities don't have names as far as I can recall
     
  10. Offline

    Drkmaster83

    @xTrollxDudex They can have custom names... items can, for example.

    Regardless, PacketPlayOutDestroyEntity seems to break functionality in one of the cases I tried. Setting an entity passenger to an arrow and then sending the packet would make the passenger dismount.

    The whole class, just for putting the psuedocode into coherent class form.
    Code:
    package me.Drkmaster83.ClassName;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Zombie;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin
    {
        @Override
        public void onEnable() {
       
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("test")) {
                if(!(sender instanceof Player)) {
                    return false;
                }
                Player player = (Player) sender;
                Zombie z = (Zombie) player.getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE);
                ((CraftEntity)z).getHandle().setInvisible(true);
            }
            return false;
        }
    }
    And, in case you doubt my sanity further, the plugin.yml:
    Code:
    name: Test
    main: me.Drkmaster83.ClassName.Test
    version: 1.0
    commands:
      test:
    The outcome of this:
    The zombie spawns, but very much so not invisible. No errors in the console. I've tried with multiple versions of the .jar that I'm getting my v1_8_R* import from.
     
    Last edited by a moderator: Jun 25, 2015
  11. Offline

    I Al Istannen

    @Drkmaster83 It works just fine, if you run the "invisible code" 2 or more ticks later.
    Maybe the dataWatcher isn't set up before? I don't really know why.
     
  12. Offline

    Drkmaster83

    Odd... such a quirk in the code. Didn't used to have to do that, but now you do. Thanks, bud. Thread solved.
    Modified (and working) code:
    Code:
    package me.Drkmaster83.ClassName;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Zombie;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin
    {
        @Override
        public void onEnable() {
       
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("test")) {
                if(!(sender instanceof Player)) {
                    return false;
                }
                final Player player = (Player) sender;
                final Zombie z = (Zombie) player.getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE);
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        ((CraftEntity)z).getHandle().setInvisible(true);
                    }
                }
            }
            return false;
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page