Solved Spawn a custom entity ArmorStand with packet

Discussion in 'Spigot Plugin Development' started by FyzDesign, Jun 15, 2021.

  1. Hi everyone !

    Im trying to spawn a custom ArmorStand entity using the PacketPlayOutSpawnEntityLiving packet, when I try to spawn it simply in the word without packet it work without problems but when I try with packet, It just don't appear and I don't have error in the console.

    Maybe Im forgetting something but when I replace "FollowingArmorStand" with "EntityArmorStand" it work without any problem.

    Hope you can help me !

    Here is my FollowingArmorStand class :

    Code (Java):
    public class FollowingArmorStand extends EntityArmorStand {

        public UUID player;

        public FollowingArmorStand(World world, Player p) {
            super(world);
            player = p.getUniqueId();
        }
       
        @Override
        public void n() {

            EntityPlayer p = ((CraftPlayer) Bukkit.getPlayer(player)).getHandle();
            setPosition(p.locX, p.locY + 1.2, p.locZ);
            this.yaw = p.yaw;
            this.pitch = p.pitch;
            setBodyPose(new Vector3f(0.0F, p.yaw, 0.0F));
            setHeadPose(new Vector3f(p.pitch, 0.0F, 0.0F));
        }


    }
    And here is how I call the entity :

    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            EntityPlayer cp = ((CraftPlayer) e.getPlayer()).getHandle();
            FollowingArmorStand frame = new FollowingArmorStand(cp.world, e.getPlayer());
            frame.setCustomName("Hi Friend !");
            frame.setCustomNameVisible(true);
            frame.setInvisible(false);
            Location l = e.getPlayer().getLocation();
            frame.setLocation(l.getX(), l.getY(), l.getZ(), l.getPitch(), l.getYaw());
            cp.playerConnection.sendPacket(new PacketPlayOutSpawnEntityLiving(frame));

        }
    Have a great day !
     
  2. I believe you need to send a PacketPlayOutEntityMetadata aswell,

    Code (Java):
    cp.playerConnection.sendPacket(new PacketPlayOutEntityMetadata(frame.getId(), frame.getDataWatcher(), true));
     
  3. Thank you for the reply !

    After trying, it doesn't work, the entity still doesn't appear ...
     
  4. Add a way to make sure your event listener is being fired.
    for example, send a message to the player saying hi
     
  5. As I said, when I replace the custom entity with a "normal" EntityArmorStand, the Armor stand appear with no problem, so... Im sure the event is called
     
  6. You are overriding the n() method but not using super.n();
    Also, you will most likely need to use PacketPlayOutEntityMetadata after each shift. Without this, the stand will most likely not move visually.
     
  7. I dont really understand the "not using super.n()" part, the n function is the "onTick()" function of the ArmorStand, by overriding it, I can change how he "react" each tick.

    For now the armor stand don't appear visually x) and I guess that he don't really shift cause Im editing how the entity work directly.

    But first, do you have any idea why the armor stand just... don't appear ?

    Thanks for your help !
     
  8. Sooo, I found another way to do what I wanted to do, when we spawn an entity with packet, the entity has no AI and we can't interact with her, that's not what I wanted so I guess this is not what I need to search.

    Thanks for your help !
    Have a great day.