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