Monday 7 October 2013

Server Packets: Changes to Entities

The following Packets are used to inform the client about changes to Entities.  These are usually generated by
  • EntityTrackerEntry (keeps track of entities near to each player)
  • EntityPlayerMP (keeps track of player status, position, health, inventory, etc
The Client generally handles these packets by calling methods in
  • EntityClientPlayerMP (for changes to the user / controlling player)
  • WorldClient (addition or removal of Entities)
  • Entity (for status changes to entities in general, eg health, position, etc)


Typical server origin
NetClientHandler (Client processing)
Called by Client during processing
Packet5PlayerInventory
Change the equipped item or armour of an entity (player, other players, mob)
EntityLivingBase.onUpdate()
EntityTrackerEntry
.handlePlayerInventory()

Entity.setCurrentItemOrArmor()
Packet6SpawnPosition
Tells the client where the player will respawn next.
ServerConfigurationManager
.handleSpawnPosition()

EntityClientPlayerMP.setSpawnChunk()
WorldInfo.setSpawnPosition()
Packet8UpdateHealth
Sends updated health and food status to the client.
EntityPlayerMP.onUpdateEntity()
.handleUpdateHealth()

EntityClientPlayerMP
Packet9Respawn
Tell the client to respawn the player at the given location.
ServerConfigurationManager
.transferPlayerToDimension()
.respawnPlayer()

.handleRespawn()
Change dimension, create new WorldClient, change game type
Minecraft.setDimensionAndSpawnPlayer
PlayerControllerMP.setGameType
Packet10Flying,
Packet11PlayerPosition,
Packet12PlayerLook,
Packet13PlayerLookMove


NetServerHandler
.setPlayerLocation()

Only Packet13 is ever sent from server to client.  It is sent once per second, to keep client and server synchronised.  Used as a signal to the client that the world reload after respawning has completed.
.handleFlying()
Update position and/or look to the new values.  Then send the same Packet with updated values (in particular the foot and eye y-values) back to the server.  Get rid of respawn screen.
EntityClientPlayerMP
.setPositionAndRotation()
Packet16BlockItemSwitch
Changes the selected hotbar slot (0..8)
ServerConfigurationManager
handleBlockItemSwitch()
Change inventory.currentitem to the nominated slot.

Packet17Sleep
Put a player to sleep
EntityPlayerMP.sleepInBedAt
handleSleep()
Put a player to sleep at the specified location, if possible.
Entityplayer.sleepInBedAt
Packet18Animation
Entity performs an action
1 = swing item
2 = gets hurt (not used)
3 = wake up
6 = critical hit
7 = magic critical hit
EntityPlayerMP
EntityLivingBase
handleAnimation()
Starts the appropriate animation (entity) or EffectRenderer
EffectRenderer.addEffect()
Entity
EntityLivingBase
EntityPlayer
<![if !supportLineBreakNewLine]>
<![endif]>
Packet20NamedEntitySpawn
Spawn an Other Player on the client
EntityTrackerEntry
handleNamedEntitySpawn()
Spawn the other player on the client, set its position, look, current item, and other metadata (Datawatcher objects)
EntityOtherPlayerMP
WorldClient.addEntityToWorld()
Packet22Collect
Collect an item from the ground
EntityLivingBase
.onItemPickup()

handleCollect()
Removes the EntityItem, plays a sound effect, renders the pickup effect.  Does not actually give an item to the entity.
WorldClient()
EffectRenderer()
Packet23VehicleSpawn
Spawns a non-living Entity (boat, fireball, firework, etc)
EntityTrackerEntry
.getPacketForThisEntity()
FMLNetworkHandler
.getEntitySpawningPacket()
handleVehicleSpawn()
Create the Entity, set position, pitch & yaw.  If thrown, set velocity.
WorldClient.addEntityToWorld()
Packet24MobSpawn
Spawn a mob
EntityTrackerEntry
.getPacketForThisEntity()
FMLNetworkHandler.
getEntitySpawningPacket()
handleMobSpawn()
Create the Entity, set position, pitch & yaws, and other metadata (Datawatcher objects).
WorldClient.addEntityToWorld()
Packet25EntityPainting
EntityTrackerEntry
.getPacketForThisEntity()
handleEntityPainting()
Create a painting
WorldClient.addEntityToWorld()
Packet26EntityXPOrb
EntityTrackerEntry
.getPacketForThisEntity()
handleEntityExpOrb()
Create an XP orb.
WorldClient.addEntityToWorld()
Packet28EntityVelocity
EntityTrackerEntry
.sendLocationToAllClients()
handleEntityVelocity()
Change the Entity’s velocity
Entity.setVelocity()
Packet29DestroyEntity
Remove one or more entities from client world, i.e. client doesn’t need to track them anymore.
EntityPlayerMP.onUpdate()
handleDestroyEntity()

WorldClient.removeEntityFromWorld
Packet30Entity,
Packet31RelEntityMove,
Packet32EntityLook,
Packet33RelEntityMoveLook
Tell the client the relative movement and/or yaw+pitch of the entity.

EntityTrackerEntry
.sendLocationToAllClients()

.handleEntity()
Update position (based on relative movement) and/or yaw/pitch.
Entity.setPositionAndRotation2()
Packet34EntityTeleport
Move the Entity to the specified position, yaw+pitch
EntityTrackerEntry
.sendLocationToAllClients()
Performs teleport instead of relative movement: once every 20 seconds, if riding, or if movement is too big.
.handleEntityTeleport()
Set entity position to the specified position, yaw+pitch
Entity.setPositionAndRotation2()
Packet35EntityHeadRotation
EntityTrackerEntry
.sendLocationToAllClients()
.handleEntityHeadRotation()
Sets the entity’s head to the given yaw
Entity. setRotationYawHead
Packet38EntityStatus
2 = hurt, 3 = dead
EntityPlayerMP.onItemUseFinish()
WorldServer.setEntityState()
.handleEntityStatus()
calls Entity.handleHealthUpdate(), which plays appropriate sound and calls appropriate client method
Entity
.attackEntityFrom()
.onDeath()
Packet39AttachEntity
Sends mounting / leashing info for horse, boat, etc.
EntityPlayerMP.mountEntity
EntityTrackerEntry
EntityLiving
.handleAttachEntity()
mounts / leashes or unmounts / unleashes entity – horse, boat, cart, etc
EntityLiving
EntityBoat
Packet40EntityMetadata
Copy all changed metadata (WatchedObjects) to client (and optionally, clear the ‘changed’ flag .watched for each)
EntityTrackerEntry
.handleEntityMetadata()
Transmit all metadata for the entity that has been changed (‘.watched’ flag is true).  The ‘.watched’ flag for each is optionally cleared when the packet is created.
Entity.DataWatcher
.updateWatchedObjectsFromList
Packet41EntityEffect
Apply the potion effect to the entity
EntityTrackerEntry
EntityPlayerMP
ServerConfigurationManager
.handleEntityEffect()
Apply the potion effect to the entity
EntityLivingBase.addPotionEffect()
Packet42RemoveEntityEffect
Remove a potion effect from the entity
EntityPlayerMP
.handleRemoveEntityEffect()
EntityLivingBase. removePotionEffectClient
Packet43Experience
Set player experience
EntityPlayerMP
ServerConfigurationManager
.handleExperience()
sets the client player experience & level
EntityClientPlayerMP.setXPstats
Packet44UpdateAttributes
Send all Attributes for this entity to the client.
EntityTrackerEntry
.handleUpdateAttributes()
set the attributes of the client entity
EntityLivingBase.getAttributeMap() (the elements in the map are overwritten).
Packet200Statistic
Send statistics (achievement, distance walked, or similar)
EntityPlayerMP
.handleStatistic()
EntityClientPlayerMP
.incrementStat
Packet201PlayerInfo
Send network info about a player to client (name, connected?, ping)
ServerConfigurationManager
.handlePlayerInfo()
NetClientHandler
Packet202PlayerAbilities
Inform the client of the player’s abilities (can fly, walk speed, etc)
EntityPlayerMP
ServerConfigurationManager
.handlePlayerAbilities()
NB - .allowEdit is ignored

EntityClientPlayerMP

There are also two FMLpackets used for custom entities:

Typical Server origin
FMLClientHandler (Client processing)
Called by Client during processing
EntitySpawnPacket
FMLNetworkHandler
.getEntitySpawningPacket
(from EntityTrackerEntry)
EntitySpawnPacket.execute()
FMLClientHandler
.spawnEntityIntoClientWorld()
EntitySpawnAdjustmentPacket
FMLNetworkHandler
.makeEntitySpawnAdjustment
(from EntityTrackerEntry)
EntitySpawnAdjustmentPacket.execute()
FMLClientHandler
.adjustEntityLocationOnClient()