Spawning a NMS ItemFrame at exact location?

Discussion in 'Spigot Plugin Development' started by MrAndeos, Aug 29, 2018.

  1. Hello.
    I need to spawn a fake ItemFrame with NMS at exact coordinates (double), I've already kind of achieved that using the PlayOutSpawnEntity packet, but after decompiling the class of this packet I see that there are only int fields and the ItemFrame spawns only at fixed coordinates (eg. 1.0, 2.0...). Setting the Position in EntityItemFrame and sending additional PlayOutEntityMetadata or PlayOutUpdateEntityNBT packet with right entity ID and data from EntityItemFrame (EntityItemFrame#getDataWatcher() or EntityItemFrame#getNBTTag()) doesn't help either.
    Code:
    Code (Java):
    WorldServer worldServer = ((CraftWorld)location.getWorld()).getHandle();
    EntityItemFrame frame = new EntityItemFrame(worldServer);
    frame.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    PacketPlayOutSpawnEntity spawnEntityPacket = new PacketPlayOutSpawnEntity(frame, 71);
    PlayerConnection connection = craftPlayer.getHandle().playerConnection;
    connection.sendPacket(spawnEntityPacket);
    How can I achieve that?
    I am using Spigot 1.8.8 (NMS v1_8_R3).
     
  2. From PacketPlayOutSpawnEntity constructor:

    Code (Java):

    this.b = MathHelper.floor(entity.locX * 32.0D);
    this.c = MathHelper.floor(entity.locY * 32.0D);
    this.d = MathHelper.floor(entity.locZ * 32.0D);
     
    It seems to be multiplying by 32 and making it an int then dividing on the other side back to float to preserve some decimal accuracy...
     
    • Like Like x 1
  3. So looks like this is some sort of client-side issue. Like ItemFrames can only exist at fixed, integer accuracy coordinates?
     
  4. md_5

    Administrator Developer

    Seems like it
     
    • Like Like x 1
    • Agree Agree x 1