Monday 7 October 2013

Server Packets: Changes to the World / Blocks

Packets used to inform the client about changes to the world / blocks.  These are sent by a variety of different callers, in particular
  •         PlayerInstance (for changes to blocks or chunks)
  •         WorldServer
  •         WorldManager (for animation and sound effects)
They are nearly all processed by WorldClient.



Typical server origin
NetClientHandler (Client processing)
Called by Client during processing
Packet51MapChunk
Send an entire chunk to the client.
PlayerInstance
.sendChunkUpdate (if many modified blocks)
.handleMapChunk()
Performs full chunk update of blocks, metadata, light levels, and optionally biome data.
WorldClient
Packet52MultiBlockChange
Send a number of changed blocks (with metadata) at once.
PlayerInstance
.sendChunkUpdate  (for modified blocks)
.handleMultiBlockChange()
Change all of the blocks listed in the packet – all must be within a single stack of 16 chunks high (y = 0-256)
WorldClient
Packet53BlockChange
Change a single block+metadata
ItemInWorldManager
PlayerInstance
NetServerHandler (packet 14 & 15)

.handleBlockChange()

WorldClient
Packet54PlayNoteBlock
Trigger a BlockEvent on the client (eg play a note, extend/retract a piston)
WorldServer
.sendAndApplyBlockEvents
.handleBlockEvent()
WorldClient. addBlockEvent
Packet55BlockDestroy
Tell the client to show a block destruction animation.
WorldManager
.destroyBlockPartially
.handleBlockDestroy()
Doesn’t actually destroy the block, just creates a DestroyBlockProgress at the specified [x,y,z] to control the animation.
WorldClient
.destroyBlockInWorldPartially
Packet56MapChunks
Send multiple chunks to the client.
EntityPlayerMP
. onUpdate()
.handleMapChunks()
Performs full chunk update of blocks, metadata, light levels, and optionally biome data.
WorldClient
Packet60Explosion
WorldServer.newExplosion
.handleExplosion()
Performs the explosion on the client (sound, move player, destroy blocks, item drop, etc)
Explosion (on WorldClient)
Packet61DoorChange
Play a sound on the client
WorldManager
.playAuxSFX
.broadcastSound
.handleDoorChange()
appears limited to one or two specific sounds only
WorldClient
.playAuxSFX
.playBroadcastSound
Packet62LevelSound

WorldManager
CommandPlaySound
.handleLevelSound()
WorldClient
.playSound
Packet63WorldParticles
Spawn particles on the client
Appears to be unused
.handleWorldParticles()
WorldClient
.spawnParticle
Packet70GameEvent
Sends various game events to client
EntityPlayerMP
WorldServer
EntityArrow
ServerConfigurationManager
.handleGameEvent()
Chat message, raining on/off, game type (survival etc), show “game won” screen, demo mode (?), play a hit sound (by arrow)
WorldClient
EntityClientPlayerMP
+ several others
Packet71Weather
Lightning strike
WorldServer
.handleWeather()
WorldClient
Packet130UpdateSign
Tells the client the text on a sign.
PlayerInstance
EntityPlayerMP

.handleUpdateSign()
TileEntitySign
Packet131MapData
Sends the data for the current map to the client, if the player is currently looking at the map in their hands.
Also hijacked by Forge for sending other non-map data?
EntityPlayerMP
   ItemMap
PacketDispatcher
.getTinyPacket
.handleMapData()
FMLNetworkHandler
.handlePacket131Packet
--->ItemMap.getMPMapData (vanilla)
Or
NetworkRegistry.handleTinyPacket

Packet132TileEntityData
Updates a TileEntity with new data, eg
TileEntityMobSpawner
TileEntityBeacon

Several TileEntityXXXX
. getDescriptionPacket

(Name is misleading)
.handleTileEntityData()
Retrieves the TileEntity at the given [x,y,z]  and calls.readFromNBT (selected vanilla) or .onDataPacket (all others)
TileEntity
.readFromNBT
.onDataPacket  (FORGE)