Solved Putting armour on a packet entity

Discussion in 'Plugin Development' started by TJM4, Oct 14, 2015.

Thread Status:
Not open for further replies.
  1. Hi,

    I am not sure why this code is not working. I am attempting to send the player an armour stand that has some bedrock on its head using packets (so it does not really spawn in the world). Here is my code:

    Code:
        public void spawn(Location loc, Player p, Material m) {
            WorldServer s = ((CraftWorld)loc.getWorld()).getHandle();
            EntityArmorStand stand = new EntityArmorStand(s);
            p.sendMessage(m + "");
        
            stand.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0, 0);
            stand.setCustomName("I'm a Armorstand!");
            stand.setCustomNameVisible(true);
            stand.setGravity(true);
            stand.setEquipment(1, CraftItemStack.asNMSCopy(new ItemStack(Material.BEDROCK)));
         
    
            PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving((EntityLiving) stand);
         
            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
            }
    The code managers to spawn the armour stand with the name "I'm a Armorstand!" but a block does not appear on its head. I have had a look at this form already: https://bukkit.org/threads/entity-equipment-packet.206214/

    Hope someone can help

    TJM4
     
  2. @TJM4
    An entity spawn packet sends nothing about armor, you need to send an equipment packet for each different slot. (PacketPlayOutEntityEquipment)
     
  3. @megamichiel Thanks for the replay. I have done as you asked but I am still not getting a bedrock hat on the armour stand. Here is my updated code:
    Code:
    public class VillageEntityMangment {
        public void spawn(Location loc, Player p, Material m) {
            WorldServer s = ((CraftWorld)loc.getWorld()).getHandle();
            EntityArmorStand stand = new EntityArmorStand(s);
            p.sendMessage(m + "");
          
            stand.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0, 0);
            stand.setCustomName("I'm a Armorstand!");
            stand.setCustomNameVisible(true);
            stand.setGravity(true);
           
    
            PacketPlayOutSpawnEntityLiving spawnP = new PacketPlayOutSpawnEntityLiving((EntityLiving) stand);
           
            PacketPlayOutEntityEquipment EquipP = new PacketPlayOutEntityEquipment(stand.getId(), 1, CraftItemStack.asNMSCopy(new ItemStack(Material.BEDROCK)));
           
            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(spawnP);
            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(EquipP);
            }
    
    }
     
  4. Offline

    Zombie_Striker

    Keep fields lowercase.


    Did you debug? are you sure the method is being read? Are you sure the packets are being sent?
     
  5. @TJM4
    It probably because I didn't give enough explanation. You need to send an equipment packet for each different slot (held item, armor), here's a list of them:
    0: held item, 1–4: armor slot (1: boots, 2: leggings, 3: chestplate, 4: helmet). You sent a packet with slot 1, which would be boots. For your case the slot has to be 4 for helmet.
     
  6. @TJM4
    Ah, it might be due to the thread being 2 years old or the person giving wrong information, but I hope it's fixed now ;).
     
  7. @megamichiel got a question: Is there a way to give the armor stand something like infinite hp or make it unremovable? without eventhandlers??
     
  8. Offline

    Scimiguy

    I'm pretty sure armorstands handle damage events differently to normal events, but you could try giving it the Invulnerable NBT tag
     
Thread Status:
Not open for further replies.

Share This Page