1.12.2 Disguising Zombie as Player crashes clients

Discussion in 'Spigot Plugin Development' started by SeanTMG, Feb 13, 2021.

  1. Hello there,

    I'm trying to make EntityPlayers that can use PathfinderGoals, but since EntityPlayer extends EntityLiving instead of EntityInsenient, this is "impossible". I had the idea of using an EntityZombie to do all the server logic, and then disguise the spawn packets with player spawn packets. I have experience in spawning NPCs through my NPC plugin, so I copied over some of my EntityPlayer/GameProfile code, hooked PacketPlayOutSpawnEntityLiving and replaced it with PacketPlayOutPlayerInfo and
    PacketPlayOutNamedEntitySpawn. This works fine, the NPC spawns. The issue is the entity IDs. Making an EntityPlayer increments the ID of the entity, so even if I disguise it as a player, the incoming/outgoing packets after that will still be affecting the zombie, not the new player. (eg; Zombie packets are sent as ID 1, player was spawned as ID 2). To solve this, I tried setting the ID of the new EntityPlayer to the ID of the EntityZombie, harmless, right? Wrong, sending PacketPlayOutNamedEntitySpawn with this configuration instantly crashes all the clients it was sent to with a "could not cast integer to byte" error, upon inspecting the source of the code it crashed at it looks like it involves an invalid DataWatcher value (isWearing on EntityPlayer, client side). This makes no sense, because changing the ID of the entity doesn't affect the DataWatcher values at all. I even tried sending the spawn packet with the normal EntityPlayer ID, and then modifying it as the packet gets sent, same crash. Anyone know what's going on?
  2. Update: I've narrowed the crash down to the PacketPlayOutEntityMetadata packet, if that never gets sent, the game doesn't crash.