001 package net.minecraft.network.packet;
002
003 import java.io.DataInputStream;
004 import java.io.DataOutputStream;
005 import java.io.IOException;
006 import net.minecraft.entity.item.EntityItem;
007 import net.minecraft.item.ItemStack;
008 import net.minecraft.util.MathHelper;
009
010 public class Packet21PickupSpawn extends Packet
011 {
012 /** Unique entity ID. */
013 public int entityId;
014
015 /** The item X position. */
016 public int xPosition;
017
018 /** The item Y position. */
019 public int yPosition;
020
021 /** The item Z position. */
022 public int zPosition;
023
024 /** The item rotation. */
025 public byte rotation;
026
027 /** The item pitch. */
028 public byte pitch;
029
030 /** The item roll. */
031 public byte roll;
032 public ItemStack itemID;
033
034 public Packet21PickupSpawn() {}
035
036 public Packet21PickupSpawn(EntityItem par1EntityItem)
037 {
038 this.entityId = par1EntityItem.entityId;
039 this.itemID = par1EntityItem.item.copy();
040 this.xPosition = MathHelper.floor_double(par1EntityItem.posX * 32.0D);
041 this.yPosition = MathHelper.floor_double(par1EntityItem.posY * 32.0D);
042 this.zPosition = MathHelper.floor_double(par1EntityItem.posZ * 32.0D);
043 this.rotation = (byte)((int)(par1EntityItem.motionX * 128.0D));
044 this.pitch = (byte)((int)(par1EntityItem.motionY * 128.0D));
045 this.roll = (byte)((int)(par1EntityItem.motionZ * 128.0D));
046 }
047
048 /**
049 * Abstract. Reads the raw packet data from the data stream.
050 */
051 public void readPacketData(DataInputStream par1DataInputStream) throws IOException
052 {
053 this.entityId = par1DataInputStream.readInt();
054 this.itemID = readItemStack(par1DataInputStream);
055 this.xPosition = par1DataInputStream.readInt();
056 this.yPosition = par1DataInputStream.readInt();
057 this.zPosition = par1DataInputStream.readInt();
058 this.rotation = par1DataInputStream.readByte();
059 this.pitch = par1DataInputStream.readByte();
060 this.roll = par1DataInputStream.readByte();
061 }
062
063 /**
064 * Abstract. Writes the raw packet data to the data stream.
065 */
066 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
067 {
068 par1DataOutputStream.writeInt(this.entityId);
069 writeItemStack(this.itemID, par1DataOutputStream);
070 par1DataOutputStream.writeInt(this.xPosition);
071 par1DataOutputStream.writeInt(this.yPosition);
072 par1DataOutputStream.writeInt(this.zPosition);
073 par1DataOutputStream.writeByte(this.rotation);
074 par1DataOutputStream.writeByte(this.pitch);
075 par1DataOutputStream.writeByte(this.roll);
076 }
077
078 /**
079 * Passes this Packet on to the NetHandler for processing.
080 */
081 public void processPacket(NetHandler par1NetHandler)
082 {
083 par1NetHandler.handlePickupSpawn(this);
084 }
085
086 /**
087 * Abstract. Return the size of the packet (not counting the header).
088 */
089 public int getPacketSize()
090 {
091 return 24;
092 }
093 }