-
Notifications
You must be signed in to change notification settings - Fork 0
Entity IDs
under construction
Entity IDs are used in packets sent from the server to the client to identify which entity the packet pertains to.
Entities include players, animals, blocks that can be interacted with like chests, etc. As of writing this, only players are implemented.
There is an issue of how entity IDs will be coordinated between peers. In the current implementation, we follow an allocation strategy. This is subject to change, so take this only as an example and use the actual code as a reference but we currently use the following scheme: Each peer uses the first 950 IDs (0 to 949) as players that are connected to them locally. It then uses 950-1000 to represent the anchored players who are standing on their server. For each peer, they assign a block of 1000 assuming the same scheme. Then to translate, we just shift the number by a multiple of 1000. Here are some example translations to make this more clear:
- We receive an entity id from a peer of 1. We've assigned this peer the block 1000-1999, so we translate this entity id into 1 + 1000 = 1001.
- We receive an entity id of 951. We know from the border crossing protocol that they've assigned the IDs 950-1000 for our players that have walked onto their server. Then we translate that ID into 951 - 950 = 1.
In general, we try to solve ID uniqueness through block allocation, rather than coordination, to reduce complexity. Entity IDs are encoded as a VarInt, which has approximately the same range as an integer. Since there are way more integers then entities the client is capable of actually rendering at once, we're moving forward with the assumption that we can use that space liberally. As a result, a block allocation scheme should be possible going forward, even if it results in large arrays of unused IDs.