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.Entity;
007    import net.minecraft.util.MathHelper;
008    
009    public class Packet23VehicleSpawn extends Packet
010    {
011        /** Entity ID of the object. */
012        public int entityId;
013    
014        /** The X position of the object. */
015        public int xPosition;
016    
017        /** The Y position of the object. */
018        public int yPosition;
019    
020        /** The Z position of the object. */
021        public int zPosition;
022    
023        /**
024         * Not sent if the thrower entity ID is 0. The speed of this fireball along the X axis.
025         */
026        public int speedX;
027    
028        /**
029         * Not sent if the thrower entity ID is 0. The speed of this fireball along the Y axis.
030         */
031        public int speedY;
032    
033        /**
034         * Not sent if the thrower entity ID is 0. The speed of this fireball along the Z axis.
035         */
036        public int speedZ;
037        public int field_92025_h;
038        public int field_92026_i;
039    
040        /** The type of object. */
041        public int type;
042    
043        /** 0 if not a fireball. Otherwise, this is the Entity ID of the thrower. */
044        public int throwerEntityId;
045    
046        public Packet23VehicleSpawn() {}
047    
048        public Packet23VehicleSpawn(Entity par1Entity, int par2)
049        {
050            this(par1Entity, par2, 0);
051        }
052    
053        public Packet23VehicleSpawn(Entity par1Entity, int par2, int par3)
054        {
055            this.entityId = par1Entity.entityId;
056            this.xPosition = MathHelper.floor_double(par1Entity.posX * 32.0D);
057            this.yPosition = MathHelper.floor_double(par1Entity.posY * 32.0D);
058            this.zPosition = MathHelper.floor_double(par1Entity.posZ * 32.0D);
059            this.field_92025_h = MathHelper.floor_float(par1Entity.rotationPitch * 256.0F / 360.0F);
060            this.field_92026_i = MathHelper.floor_float(par1Entity.rotationYaw * 256.0F / 360.0F);
061            this.type = par2;
062            this.throwerEntityId = par3;
063    
064            if (par3 > 0)
065            {
066                double var4 = par1Entity.motionX;
067                double var6 = par1Entity.motionY;
068                double var8 = par1Entity.motionZ;
069                double var10 = 3.9D;
070    
071                if (var4 < -var10)
072                {
073                    var4 = -var10;
074                }
075    
076                if (var6 < -var10)
077                {
078                    var6 = -var10;
079                }
080    
081                if (var8 < -var10)
082                {
083                    var8 = -var10;
084                }
085    
086                if (var4 > var10)
087                {
088                    var4 = var10;
089                }
090    
091                if (var6 > var10)
092                {
093                    var6 = var10;
094                }
095    
096                if (var8 > var10)
097                {
098                    var8 = var10;
099                }
100    
101                this.speedX = (int)(var4 * 8000.0D);
102                this.speedY = (int)(var6 * 8000.0D);
103                this.speedZ = (int)(var8 * 8000.0D);
104            }
105        }
106    
107        /**
108         * Abstract. Reads the raw packet data from the data stream.
109         */
110        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
111        {
112            this.entityId = par1DataInputStream.readInt();
113            this.type = par1DataInputStream.readByte();
114            this.xPosition = par1DataInputStream.readInt();
115            this.yPosition = par1DataInputStream.readInt();
116            this.zPosition = par1DataInputStream.readInt();
117            this.field_92025_h = par1DataInputStream.readByte();
118            this.field_92026_i = par1DataInputStream.readByte();
119            this.throwerEntityId = par1DataInputStream.readInt();
120    
121            if (this.throwerEntityId > 0)
122            {
123                this.speedX = par1DataInputStream.readShort();
124                this.speedY = par1DataInputStream.readShort();
125                this.speedZ = par1DataInputStream.readShort();
126            }
127        }
128    
129        /**
130         * Abstract. Writes the raw packet data to the data stream.
131         */
132        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
133        {
134            par1DataOutputStream.writeInt(this.entityId);
135            par1DataOutputStream.writeByte(this.type);
136            par1DataOutputStream.writeInt(this.xPosition);
137            par1DataOutputStream.writeInt(this.yPosition);
138            par1DataOutputStream.writeInt(this.zPosition);
139            par1DataOutputStream.writeByte(this.field_92025_h);
140            par1DataOutputStream.writeByte(this.field_92026_i);
141            par1DataOutputStream.writeInt(this.throwerEntityId);
142    
143            if (this.throwerEntityId > 0)
144            {
145                par1DataOutputStream.writeShort(this.speedX);
146                par1DataOutputStream.writeShort(this.speedY);
147                par1DataOutputStream.writeShort(this.speedZ);
148            }
149        }
150    
151        /**
152         * Passes this Packet on to the NetHandler for processing.
153         */
154        public void processPacket(NetHandler par1NetHandler)
155        {
156            par1NetHandler.handleVehicleSpawn(this);
157        }
158    
159        /**
160         * Abstract. Return the size of the packet (not counting the header).
161         */
162        public int getPacketSize()
163        {
164            return 21 + this.throwerEntityId > 0 ? 6 : 0;
165        }
166    }