Entities & Packets

Discussion in 'Spigot Plugin Development' started by iSoda, Jun 4, 2017.

  1. When you send a packet of a certain entity (for the sake of example, lets say pig entity) and you send it to the player but you set the entity ID into an EXISTING entity ID (so for example, the pig packet id will be the same ID as a sheep near the player), the sheep will disappear and instead the pig will appear,
    so the player will see the pig even though the entity is actually a sheep (will make sheep sound, can be sheared, eat grass, etc)
    so in a nutshell, the player will see a pig instead of a sheep, despite the entity being a sheep.
    this all works fine and everything, the body position, pitch, yaw, etc...
    however - if the player goes (far) away from the entity and then comes back to the entity, the sheep will appear again, is there a way to force the player to see the pig again without checking the players distance to the pig and then sending the packet? how can i make sure the player always see the pig whenever its near the sheep? for login, I can use login event and then send the packet with delay of a tick or two, but Im not sure about seeing an entity...
  2. If the player goes far away enough, the clients unloads all entities in the chunck and al the blocks. If he comes back to the chunck, the clients sends a request to load the chunck. The only way to make it a pig again is to send that pig packet again. You could use packet injection to change the data in the chunck data packet that is sent afeter the request. I don't think there is any other way because the client doesn't save the data after unload.
    • Like Like x 1
    • Agree Agree x 1
  3. Thank you, is there a simple way of doing that without using any external libraries or plugins (such as tinyprotocol, or protocollib), is there an event of some sort? (do mind that different players will be going away and to the entity at same times, so using chunk load event will not do much)
  4. Minecraft uses netty to send the packets. I think netty has an api for packet injection and that kind of stuff. I saw ProtocolLib use that, but i don't know how it works.

    At this moment i am making my own packet api to but i am not far enough to worry about injection and stuff.
    • Like Like x 1
  5. Thanks again, I will look into that.
    how do plugins and libraries such as Citizens or plugins that let you morph into another entity are forcing the client to see the NPC / entity you are morph into even if the morphed player is far and gets near a new player?
  6. bump.... there must be a way to achieve it without the use of playermoveevent or intensive network stuff... how does morph / diguise plugins do it?
  7. I think they just use packets.
    • Like Like x 1
  8. what packet is being sent while an entity is load (or a chunk load packet which contains a list of the loaded entities? ) I couldnt find any.. I did found ChunkData but it didnt contain any info about entities ...
  9. bump, any pros can join in? what packet is sent by the server to the client when the client load a new chunk and entities? is there a better way to do it without the use of playermoveevent?
  10. Spawning a packet entity and disguise a player is different.
    In fact if you want to disguise someone you have to destroy the player, spawn a packet entity for example a pig and then you have to set the pig Id by using reflection as the same of the player id.
    It means that the pig is now the player, and the pig will follow the player movement.
    After that, if someone meet the disguised player, then he goes far away and come back to the disguised player, you have to listen the packet sended to the player called: Player PacketPlayOutEntityNamedSpawn or something like that and send again the pig spawn packet.
    Now if you want to do this with a simple entity wich is does not linked to a real entity it will be not possible to use this method.
    It means that you have to use a real entity :)
    With a noAI
    • Like Like x 2
  11. I don't think it is PacketPlayOutEntityNamedSpawn. The name says it is a out going packet.
    • Like Like x 1
    • Like Like x 1
    • Like Like x 2
  12. ty both, is there a normal living entity packet that it sent ? the best example i can think of is dungeon realms, you have player NPCs everywhere and they always stay there.
  13. I do not understand
    What do you want to do ?..
    • Like Like x 1
  14. I want to disguse a sheep as a pig (or any entity as other entity),
    Im able to disguse the sheep into a pig by sending a packet that spawns the pig with the same entity ID as the sheep (and Im able to see a pig instead of a sheep,) however when a player unloads the cunk and then go back, the pig packet will disappear and instead the sheep will appear,
    what packet is sent when the client loads an entity? (Im using tiny protocol)
  15. Soo, it depends on your sheep, is it named ? so this is PacketPlayOutNamedEntitySpawn
    not named ? PacketPlayOutEntityLivingSpawn
    • Like Like x 1
  16. thank you so much! however, named entity spawn packet is for players only (Im able to listen to it and modify it whenever I send the player packet to another player, but it does not fire when a non player entity spawns even if its named), and playoutentityliving spawn is not a valid packet... any other packets which can be used to detect entity spawn?
  17. PacketPlayOutSpawnEntityLiving is probably what you are looking for.
    • Like Like x 1
  18. thank you,

    A note for the future for the ones who attempting to achieve the same (it can also be used to fake player NPCs and such.)
    to achieve it:
    1. listen to the packets sent by the server to the client
    2. use reflection to get field "a" which is the entity ID
    3. send a new packet with the SAME entity ID of the original packet
    4. cancel the packet sent by the server