net.minecraft.network.packet

## Class Packet

- java.lang.Object
- - net.minecraft.network.packet.Packet

- Direct Known Subclasses:
    Packet0KeepAlive, Packet100OpenWindow, Packet101CloseWindow, Packet102WindowClick, Packet103SetSlot, Packet104WindowItems, Packet105UpdateProgressbar, Packet106Transaction, Packet107CreativeSetSlot, Packet108EnchantItem, Packet10Flying, Packet130UpdateSign, Packet131MapData, Packet132TileEntityData, Packet133TileEditorOpen, Packet14BlockDig, Packet15Place, Packet16BlockItemSwitch, Packet17Sleep, Packet18Animation, Packet19EntityAction, Packet1Login, Packet200Statistic, Packet201PlayerInfo, Packet202PlayerAbilities, Packet203AutoComplete, Packet204ClientInfo, Packet205ClientCommand, Packet206SetObjective, Packet207SetScore, Packet208SetDisplayObjective, Packet209SetPlayerTeam, Packet20NamedEntitySpawn, Packet22Collect, Packet23VehicleSpawn, Packet24MobSpawn, Packet250CustomPayload, Packet252SharedKey, Packet253ServerAuthData, Packet254ServerPing, Packet255KickDisconnect, Packet25EntityPainting, Packet26EntityExpOrb, Packet27PlayerInput, Packet28EntityVelocity, Packet29DestroyEntity, Packet2ClientProtocol, Packet30Entity, Packet34EntityTeleport, Packet35EntityHeadRotation, Packet38EntityStatus, Packet39AttachEntity, Packet3Chat, Packet40EntityMetadata, Packet41EntityEffect, Packet42RemoveEntityEffect, Packet43Experience, Packet44UpdateAttributes, Packet4UpdateTime, Packet51MapChunk, Packet52MultiBlockChange, Packet53BlockChange, Packet54PlayNoteBlock, Packet55BlockDestroy, Packet56MapChunks, Packet5PlayerInventory, Packet60Explosion, Packet61DoorChange, Packet62LevelSound, Packet63WorldParticles, Packet6SpawnPosition, Packet70GameEvent, Packet71Weather, Packet7UseEntity, Packet8UpdateHealth, Packet9Respawn

      public abstract class Packet
      extends Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `long` | `creationTimeMillis` the system time in milliseconds when this packet was created.
    `boolean` | `isChunkDataPacket` Only true for Packet51MapChunk, Packet52MultiBlockChange, Packet53BlockChange and Packet59ComplexEntity.
    `static IntHashMap` | `packetIdToClassMap` Maps packet id to packet class
    `static long` | `receivedID`
    `static long` | `receivedSize`
    `static long` | `sentID` Assumed to be sequential by the profiler.
    `static long` | `sentSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Packet()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addIdClassMapping(int par0, boolean par1, boolean par2, Class par3Class)` Adds a two way mapping between the packet ID and packet class.
    `boolean` | `canProcessAsync()` If this returns true, the packet may be processed on any thread; otherwise it is queued for the main thread to handle.
    `boolean` | `containsSameEntityIDAs(Packet par1Packet)` eg return packet30entity.entityId == entityId; WARNING : will throw if you compare a packet to a different packet class
    `static Packet` | `getNewPacket(ILogAgent par0ILogAgent, int par1)` Returns a new instance of the specified Packet class.
    `int` | `getPacketId()` Returns the ID of this packet.
    `abstract int` | `getPacketSize()` Abstract.
    `boolean` | `isRealPacket()` only false for the abstract Packet class, all real packets return true
    `abstract void` | `processPacket(NetHandler nethandler)` Passes this Packet on to the NetHandler for processing.
    `static byte[]` | `readBytesFromStream(DataInput par0DataInput)` the first short in the stream indicates the number of bytes to read
    `static ItemStack` | `readItemStack(DataInput par0DataInput)` Reads a ItemStack from the InputStream
    `static NBTTagCompound` | `readNBTTagCompound(DataInput par0DataInput)` Reads a compressed NBTTagCompound from the InputStream
    `static Packet` | `readPacket(ILogAgent par0ILogAgent, DataInput par1DataInput, boolean par2, Socket par3Socket)` Read a packet, prefixed by its ID, from the data stream.
    `abstract void` | `readPacketData(DataInput datainput)` Abstract.
    `static String` | `readString(DataInput par0DataInput, int par1)` Reads a string from a packet
    `String` | `toString()`
    `static void` | `writeByteArray(DataOutput par0DataOutput, byte[] par1ArrayOfByte)` Writes a byte array to the DataOutputStream
    `static void` | `writeItemStack(ItemStack par0ItemStack, DataOutput par1DataOutput)` Writes the ItemStack's ID (short), then size (byte), then damage.
    `static void` | `writePacket(Packet par0Packet, DataOutput par1DataOutput)` Writes a packet, prefixed by its ID, to the data stream.
    `abstract void` | `writePacketData(DataOutput dataoutput)` Abstract.
    `static void` | `writeString(String par0Str, DataOutput par1DataOutput)` Writes a String to the DataOutputStream

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### packetIdToClassMap

          public static IntHashMap packetIdToClassMap

      Maps packet id to packet class

    - #### creationTimeMillis

          public final long creationTimeMillis

      the system time in milliseconds when this packet was created.

    - #### receivedID

          public static long receivedID

    - #### receivedSize

          public static long receivedSize

    - #### sentID

          public static long sentID

      Assumed to be sequential by the profiler.

    - #### sentSize

          public static long sentSize

    - #### isChunkDataPacket

          public boolean isChunkDataPacket

      Only true for Packet51MapChunk, Packet52MultiBlockChange, Packet53BlockChange and Packet59ComplexEntity. Used to separate them into a different send queue.

  - ### Constructor Detail

    - #### Packet

          public Packet()

  - ### Method Detail

    - #### addIdClassMapping

          public static void addIdClassMapping(int par0,
                               boolean par1,
                               boolean par2,
                               Class par3Class)

      Adds a two way mapping between the packet ID and packet class.

    - #### getNewPacket

          public static Packet getNewPacket(ILogAgent par0ILogAgent,
                            int par1)

      Returns a new instance of the specified Packet class.

    - #### writeByteArray

          public static void writeByteArray(DataOutput par0DataOutput,
                            byte[] par1ArrayOfByte)
                                     throws IOException

      Writes a byte array to the DataOutputStream
      Throws:
        `IOException`

    - #### readBytesFromStream

          public static byte[] readBytesFromStream(DataInput par0DataInput)
                                            throws IOException

      the first short in the stream indicates the number of bytes to read
      Throws:
        `IOException`

    - #### getPacketId

          public final int getPacketId()

      Returns the ID of this packet.

    - #### readPacket

          public static Packet readPacket(ILogAgent par0ILogAgent,
                          DataInput par1DataInput,
                          boolean par2,
                          Socket par3Socket)
                                   throws IOException

      Read a packet, prefixed by its ID, from the data stream.
      Throws:
        `IOException`

    - #### writePacket

          public static void writePacket(Packet par0Packet,
                         DataOutput par1DataOutput)
                                  throws IOException

      Writes a packet, prefixed by its ID, to the data stream.
      Throws:
        `IOException`

    - #### writeString

          public static void writeString(String par0Str,
                         DataOutput par1DataOutput)
                                  throws IOException

      Writes a String to the DataOutputStream
      Throws:
        `IOException`

    - #### readString

          public static String readString(DataInput par0DataInput,
                          int par1)
                                   throws IOException

      Reads a string from a packet
      Throws:
        `IOException`

    - #### readPacketData

          public abstract void readPacketData(DataInput datainput)
                                       throws IOException

      Abstract. Reads the raw packet data from the data stream.
      Throws:
        `IOException`

    - #### writePacketData

          public abstract void writePacketData(DataOutput dataoutput)
                                        throws IOException

      Abstract. Writes the raw packet data to the data stream.
      Throws:
        `IOException`

    - #### processPacket

          public abstract void processPacket(NetHandler nethandler)

      Passes this Packet on to the NetHandler for processing.

    - #### getPacketSize

          public abstract int getPacketSize()

      Abstract. Return the size of the packet (not counting the header).

    - #### isRealPacket

          public boolean isRealPacket()

      only false for the abstract Packet class, all real packets return true

    - #### containsSameEntityIDAs

          public boolean containsSameEntityIDAs(Packet par1Packet)

      eg return packet30entity.entityId == entityId; WARNING : will throw if you compare a packet to a different packet class

    - #### canProcessAsync

          public boolean canProcessAsync()

      If this returns true, the packet may be processed on any thread; otherwise it is queued for the main thread to handle.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### readItemStack

          public static ItemStack readItemStack(DataInput par0DataInput)
                                         throws IOException

      Reads a ItemStack from the InputStream
      Throws:
        `IOException`

    - #### writeItemStack

          public static void writeItemStack(ItemStack par0ItemStack,
                            DataOutput par1DataOutput)
                                     throws IOException

      Writes the ItemStack's ID (short), then size (byte), then damage. (short)
      Throws:
        `IOException`

    - #### readNBTTagCompound

          public static NBTTagCompound readNBTTagCompound(DataInput par0DataInput)
                                                   throws IOException

      Reads a compressed NBTTagCompound from the InputStream
      Throws:
        `IOException`