    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
    038        /** The type of object. */
    039        public int type;
    040
    041        /** 0 if not a fireball. Otherwise, this is the Entity ID of the thrower. */
    042        public int throwerEntityId;
    043
    044        public Packet23VehicleSpawn() {}
    045
    046        public Packet23VehicleSpawn(Entity par1Entity, int par2)
    047        {
    048            this(par1Entity, par2, 0);
    049        }
    050
    051        public Packet23VehicleSpawn(Entity par1Entity, int par2, int par3)
    052        {
    053            this.entityId = par1Entity.entityId;
    054            this.xPosition = MathHelper.floor_double(par1Entity.posX * 32.0D);
    055            this.yPosition = MathHelper.floor_double(par1Entity.posY * 32.0D);
    056            this.zPosition = MathHelper.floor_double(par1Entity.posZ * 32.0D);
    057            this.type = par2;
    058            this.throwerEntityId = par3;
    059
    060            if (par3 > 0)
    061            {
    062                double var4 = par1Entity.motionX;
    063                double var6 = par1Entity.motionY;
    064                double var8 = par1Entity.motionZ;
    065                double var10 = 3.9D;
    066
    067                if (var4 < -var10)
    068                {
    069                    var4 = -var10;
    070                }
    071
    072                if (var6 < -var10)
    073                {
    074                    var6 = -var10;
    075                }
    076
    077                if (var8 < -var10)
    078                {
    079                    var8 = -var10;
    080                }
    081
    082                if (var4 > var10)
    083                {
    084                    var4 = var10;
    085                }
    086
    087                if (var6 > var10)
    088                {
    089                    var6 = var10;
    090                }
    091
    092                if (var8 > var10)
    093                {
    094                    var8 = var10;
    095                }
    096
    097                this.speedX = (int)(var4 * 8000.0D);
    098                this.speedY = (int)(var6 * 8000.0D);
    099                this.speedZ = (int)(var8 * 8000.0D);
    100            }
    101        }
    102
    103        /**
    104         * Abstract. Reads the raw packet data from the data stream.
    105         */
    106        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    107        {
    108            this.entityId = par1DataInputStream.readInt();
    109            this.type = par1DataInputStream.readByte();
    110            this.xPosition = par1DataInputStream.readInt();
    111            this.yPosition = par1DataInputStream.readInt();
    112            this.zPosition = par1DataInputStream.readInt();
    113            this.throwerEntityId = par1DataInputStream.readInt();
    114
    115            if (this.throwerEntityId > 0)
    116            {
    117                this.speedX = par1DataInputStream.readShort();
    118                this.speedY = par1DataInputStream.readShort();
    119                this.speedZ = par1DataInputStream.readShort();
    120            }
    121        }
    122
    123        /**
    124         * Abstract. Writes the raw packet data to the data stream.
    125         */
    126        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    127        {
    128            par1DataOutputStream.writeInt(this.entityId);
    129            par1DataOutputStream.writeByte(this.type);
    130            par1DataOutputStream.writeInt(this.xPosition);
    131            par1DataOutputStream.writeInt(this.yPosition);
    132            par1DataOutputStream.writeInt(this.zPosition);
    133            par1DataOutputStream.writeInt(this.throwerEntityId);
    134
    135            if (this.throwerEntityId > 0)
    136            {
    137                par1DataOutputStream.writeShort(this.speedX);
    138                par1DataOutputStream.writeShort(this.speedY);
    139                par1DataOutputStream.writeShort(this.speedZ);
    140            }
    141        }
    142
    143        /**
    144         * Passes this Packet on to the NetHandler for processing.
    145         */
    146        public void processPacket(NetHandler par1NetHandler)
    147        {
    148            par1NetHandler.handleVehicleSpawn(this);
    149        }
    150
    151        /**
    152         * Abstract. Return the size of the packet (not counting the header).
    153         */
    154        public int getPacketSize()
    155        {
    156            return 21 + this.throwerEntityId > 0 ? 6 : 0;
    157        }
    158    }