1.8.8 NBTTagCompound Spawn invisible villager [HELP]

Discussion in 'Spigot Plugin Development' started by Seeyko, Apr 17, 2017.

  1. Hello all !

    So i write a plugin where each team have a king to defend, this king is an amor stand with some item on it.
    But as you know, the hitbox of the armor is litlle.
    In order to make easy to fight the king, i have spawn a villager in the same place as the armorstand so when you hit king, it's the invisible villager who take the damage (the take the damage, and decrease a double, when this double is under 1, the king and the invisible villager are kill, then the player who have their king dead can't respawn when they die.

    So basically this is the idea, i have all setup exept the invisible villager. I search all days the nbt tag for invisible mob but it only disponible for armorstand.
    I think this is possible to do it using packet but i never use those and i don't want to start to learn them or now, i'm don't think i'm enough experiment...

    If someone can explain me a little bit more how i can set a mob invisible, using packet or not but if it's with packet i will need a further explanation ^^

    This is the code i have for spawning armorstand and villager for the moment :

    Code (Text):


    //Spawn the armorstand Blue.
    ArmorStand Blue = (ArmorStand) player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);    
    //Give Blue arms
    Blue.setArms(true);
    //Register the armorstand as an entity and create a new NBTTag for Blue : armorStandTag
    EntityArmorStand as = ((CraftArmorStand) Blue).getHandle();
    NBTTagCompound armorStandTag = new NBTTagCompound();
    //Spawn the villager kingBlue
    Entity kingBlue = player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.VILLAGER);
    //kingBlue set name blueVillager and set is name invisible (by the way this did'nt work, his name is always visible...
    kingBlue.setCustomName("blueVillager");
    kingBlue.setCustomNameVisible(false);
    Same as NBTTag for armorstand but for the villager
    net.minecraft.server.v1_8_R3.Entity nmsVillager = ((CraftEntity) kingBlue).getHandle();
    NBTTagCompound villagerTag = nmsVillager.getNBTTag();
                             if(villagerTag == null){
                                 villagerTag = new NBTTagCompound();
                             }
    //This his here i get troube... for modifying the NBTTagCompound we use "nmsVillager.?(?)" and i don't know to what correspond the letter .c or .f or .a or .setByte or .setString, i don't really know how to use this and didn't found any docs...
    nmsVillager.c(villagerTag);
    compound.setBoolean("Invisible", true);
    villagerTag.setInt("NoAI", 1);
    villagerTag.setByte("Silent", (byte) 8);
    nmsVillager.b(true);
    nmsVillager.setCustomNameVisible(false);
    nmsVillager.setInvisible(false);
    nmsVillager.f(villagerTag);
    as.b(true);
    as.c(armorStandTag);
    armorStandTag.setInt("NoAI", 1);
    as.c(armorStandTag);
    as.f(armorStandTag);
    Blue.setGravity(false);
    Blue.setVisible(true);
    Blue.setCustomNameVisible(true);
    Blue.setCustomName("§6Roi §9Bleu");
     
  2. Why use an armorstand? Why don't you just use an entity like a skeleton with armor, which won't take knockback or move.
     
  3. Hum... I have no problem with the armorstand but ... I use it because i want to make a king with a little bit of style, holding an item in is hand, left arm up in the air etc...

    And i have give potion effect to my villager so there are invicible but i'm sure nbt tag can do this because with command bloc we can !
     
  4. Yeh. You defiantly can. Try googling it.
     
  5. Why not just apply the potion effect to the villager using addPotionEffect()?
     
  6. This is what i do for the moment but i want to learn using NBTTag because it's such an important things :)

    I'm going to see this !
    Edit: Yes, this is with Packets and not with NBTTag... I know we can do like this but i don't want to start looking at packets right now, i have so many other things to learn before...
    But in minecraft with command bloc, the invisible it's a tag so i think's it's possible with NBTTag no ?
     
    #7 Seeyko, Apr 17, 2017
    Last edited: Apr 17, 2017