Proper use of PacketPlayOutAttachEntity

Discussion in 'Plugin Development' started by Excel8392, May 12, 2020.

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

    Excel8392

    So I am trying to create an invisible armor stand which is spawned on the server (using NMS), and then for each player, I want to summon a different item as a passenger of that armor stand.
    So player X might get a rose item, and player Y might get a dandelion.

    (Reason why I am trying to make the items a passenger of the armor stand is because otherwise, they just fall to the ground, and I have heard that putting them on top of an armor stand is a way to get the client to ignore item stack physics.)

    Please note that the armor stand will be spawned server side, while the items will be "faked" using NMS packets.

    I currently have this code for spawning the armor stand and displaying it for players (works 100% fine):
    Code:
    this.armorStand = new EntityArmorStand(((CraftWorld) Npc.this.location.getWorld()).getHandle(), Npc.this.location.getX(), Npc.this.location.getY() + 3, Npc.this.location.getZ());
    this.armorStand.setSmall(true);
    this.armorStand.setInvisible(true);
    this.armorStand.setMarker(true);
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInt("DisabledSlot", 2039589);
    this.armorStand.c(tag);
    worldServer.addEntity(this.armorStand);
    
    // Spawning for a player
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutSpawnEntityLiving(this.armorStand));
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(this.armorStand.getId(), this.armorStand.getDataWatcher(), true));
    I try to spawn the item like so:
    Code:
    EntityItem item = new EntityItem(
            ((CraftWorld) Npc.this.location.getWorld()).getHandle(),
            Npc.this.location.getX(),
            Npc.this.location.getY(),
            Npc.this.location.getZ(),
            CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(material)));
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutSpawnEntity(item, 2));
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(item.getId(), item.getDataWatcher(), true));
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutAttachEntity(Npc.this.armorStand, item));
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityVelocity(item));
    However, the items show up completely detached from the armor stand, and I am sure that this is because the PacketPlayOutAttachEntity is not working correctly.

    Can anyone show me the correct usage for that packet, and what I am doing wrong?
    Thanks


    Please note that I do not want to use item.startRiding(armorStand) or anything of the sort because after some testing, I have seen that those functions cause the item to be spawned on the server, which is not what I want, I want to just fake it with packets.
     
Thread Status:
Not open for further replies.

Share This Page