Page 1 of 1
Quick question
Posted: January 18th, 2012, 11:39 am
by Jonty800
I was looking at the SetSpawn handler and saw:
Code: Select all
player.TeleportTo(player.World.Map.Spawn);
player.Send(PacketWriter.MakeAddEntity(255, player.ListName, player.Position));
Why do you send an entity to the player? What does it do compared to just sending the Teleport packet? And why is the ID 255?
Thanks!
Re: Quick question
Posted: January 18th, 2012, 12:48 pm
by fragmer
Minecraft treats IDs as signed bytes. From Minecraft's perspective, bytes have range (-128...127). Minecraft treats IDs that are less than 1 as referring to "self." In C#, bytes are unsigned and have range (0...255). Anyways, "-255" in C# means "-1" in Java.
When you send a an AddEntity packet with a "self" ID, it sets player's spawn and teleports them to the given position. I'm not sure why it sends a teleport packet as well (which only teleports the player, without setting spawn). I'll look back through the old commits to see if there's a real reason for it. Could be one of those Minecraft client bug workarounds, I don't even remember...
Re: Quick question
Posted: January 19th, 2012, 2:55 am
by Jonty800
So what would happen if I changed player.ListName to "fragmer"... would I become you?
Re: Quick question
Posted: January 19th, 2012, 9:04 am
by Hellenion
You would become fragmer indeed. At least others will see fragmer's skin and his name floating above your head.
Re: Quick question
Posted: January 19th, 2012, 10:50 am
by Jonty800
I tested this, it didn't work haha!
Even after a /wflush to update the visible entities.
Out of curiosity, what is the safest way to change a player's skin?
Nvm.
Is the best way to update the player's new skin to use player.ResetVisibleEntities for everyone in the world?
eg;
Code: Select all
foreach(Player p in player.World.Players){
p.ResetVisibleEntities();
}