Quick question

For all mod-related questions and custom code.
Post Reply
Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Quick question

Post 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!
You cannot use certain BBCodes: [img].

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Quick question

Post 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...

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Quick question

Post by Jonty800 »

So what would happen if I changed player.ListName to "fragmer"... would I become you?
You cannot use certain BBCodes: [img].

User avatar
Hellenion
Offline
Posts: 220
Joined: October 20th, 2011, 9:20 am
Location: Subnet
Contact:

Re: Quick question

Post by Hellenion »

You would become fragmer indeed. At least others will see fragmer's skin and his name floating above your head.
A = {x ∈ P(U) | x ∉ x}
Mods:
  1. /Su - Allows players to temporarily become a different rank
  2. /Snap - Like /Line but only draws straight or diagonal lines.
  3. pre-0.630 skip/none block

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Quick question

Post 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();
}
You cannot use certain BBCodes: [img].

Post Reply