001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005 import java.io.DataInputStream;
006 import java.io.DataOutputStream;
007 import java.io.IOException;
008 import java.util.List;
009
010 public class Packet20NamedEntitySpawn extends Packet
011 {
012 /** The entity ID, in this case it's the player ID. */
013 public int entityId;
014
015 /** The player's name. */
016 public String name;
017
018 /** The player's X position. */
019 public int xPosition;
020
021 /** The player's Y position. */
022 public int yPosition;
023
024 /** The player's Z position. */
025 public int zPosition;
026
027 /** The player's rotation. */
028 public byte rotation;
029
030 /** The player's pitch. */
031 public byte pitch;
032
033 /** The current item the player is holding. */
034 public int currentItem;
035 private DataWatcher metadata;
036 private List field_73517_j;
037
038 public Packet20NamedEntitySpawn() {}
039
040 public Packet20NamedEntitySpawn(EntityPlayer par1EntityPlayer)
041 {
042 this.entityId = par1EntityPlayer.entityId;
043 this.name = par1EntityPlayer.username;
044 this.xPosition = MathHelper.floor_double(par1EntityPlayer.posX * 32.0D);
045 this.yPosition = MathHelper.floor_double(par1EntityPlayer.posY * 32.0D);
046 this.zPosition = MathHelper.floor_double(par1EntityPlayer.posZ * 32.0D);
047 this.rotation = (byte)((int)(par1EntityPlayer.rotationYaw * 256.0F / 360.0F));
048 this.pitch = (byte)((int)(par1EntityPlayer.rotationPitch * 256.0F / 360.0F));
049 ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();
050 this.currentItem = var2 == null ? 0 : var2.itemID;
051 this.metadata = par1EntityPlayer.getDataWatcher();
052 }
053
054 /**
055 * Abstract. Reads the raw packet data from the data stream.
056 */
057 public void readPacketData(DataInputStream par1DataInputStream) throws IOException
058 {
059 this.entityId = par1DataInputStream.readInt();
060 this.name = readString(par1DataInputStream, 16);
061 this.xPosition = par1DataInputStream.readInt();
062 this.yPosition = par1DataInputStream.readInt();
063 this.zPosition = par1DataInputStream.readInt();
064 this.rotation = par1DataInputStream.readByte();
065 this.pitch = par1DataInputStream.readByte();
066 this.currentItem = par1DataInputStream.readShort();
067 this.field_73517_j = DataWatcher.readWatchableObjects(par1DataInputStream);
068 }
069
070 /**
071 * Abstract. Writes the raw packet data to the data stream.
072 */
073 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
074 {
075 par1DataOutputStream.writeInt(this.entityId);
076 writeString(this.name, par1DataOutputStream);
077 par1DataOutputStream.writeInt(this.xPosition);
078 par1DataOutputStream.writeInt(this.yPosition);
079 par1DataOutputStream.writeInt(this.zPosition);
080 par1DataOutputStream.writeByte(this.rotation);
081 par1DataOutputStream.writeByte(this.pitch);
082 par1DataOutputStream.writeShort(this.currentItem);
083 this.metadata.writeWatchableObjects(par1DataOutputStream);
084 }
085
086 /**
087 * Passes this Packet on to the NetHandler for processing.
088 */
089 public void processPacket(NetHandler par1NetHandler)
090 {
091 par1NetHandler.handleNamedEntitySpawn(this);
092 }
093
094 /**
095 * Abstract. Return the size of the packet (not counting the header).
096 */
097 public int getPacketSize()
098 {
099 return 28;
100 }
101
102 @SideOnly(Side.CLIENT)
103 public List func_73509_c()
104 {
105 if (this.field_73517_j == null)
106 {
107 this.field_73517_j = this.metadata.func_75685_c();
108 }
109
110 return this.field_73517_j;
111 }
112 }