    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 Packet24MobSpawn extends Packet
    011    {
    012        /** The entity ID. */
    013        public int entityId;
    014
    015        /** The type of mob. */
    016        public int type;
    017
    018        /** The X position of the entity. */
    019        public int xPosition;
    020
    021        /** The Y position of the entity. */
    022        public int yPosition;
    023
    024        /** The Z position of the entity. */
    025        public int zPosition;
    026        public int velocityX;
    027        public int velocityY;
    028        public int velocityZ;
    029
    030        /** The yaw of the entity. */
    031        public byte yaw;
    032
    033        /** The pitch of the entity. */
    034        public byte pitch;
    035
    036        /** The yaw of the entity's head. */
    037        public byte headYaw;
    038
    039        /** Indexed metadata for Mob, terminated by 0x7F */
    040        private DataWatcher metaData;
    041        private List metadata;
    042
    043        public Packet24MobSpawn() {}
    044
    045        public Packet24MobSpawn(EntityLiving par1EntityLiving)
    046        {
    047            this.entityId = par1EntityLiving.entityId;
    048            this.type = (byte)EntityList.getEntityID(par1EntityLiving);
    049            this.xPosition = par1EntityLiving.myEntitySize.multiplyBy32AndRound(par1EntityLiving.posX);
    050            this.yPosition = MathHelper.floor_double(par1EntityLiving.posY * 32.0D);
    051            this.zPosition = par1EntityLiving.myEntitySize.multiplyBy32AndRound(par1EntityLiving.posZ);
    052            this.yaw = (byte)((int)(par1EntityLiving.rotationYaw * 256.0F / 360.0F));
    053            this.pitch = (byte)((int)(par1EntityLiving.rotationPitch * 256.0F / 360.0F));
    054            this.headYaw = (byte)((int)(par1EntityLiving.rotationYawHead * 256.0F / 360.0F));
    055            double var2 = 3.9D;
    056            double var4 = par1EntityLiving.motionX;
    057            double var6 = par1EntityLiving.motionY;
    058            double var8 = par1EntityLiving.motionZ;
    059
    060            if (var4 < -var2)
    061            {
    062                var4 = -var2;
    063            }
    064
    065            if (var6 < -var2)
    066            {
    067                var6 = -var2;
    068            }
    069
    070            if (var8 < -var2)
    071            {
    072                var8 = -var2;
    073            }
    074
    075            if (var4 > var2)
    076            {
    077                var4 = var2;
    078            }
    079
    080            if (var6 > var2)
    081            {
    082                var6 = var2;
    083            }
    084
    085            if (var8 > var2)
    086            {
    087                var8 = var2;
    088            }
    089
    090            this.velocityX = (int)(var4 * 8000.0D);
    091            this.velocityY = (int)(var6 * 8000.0D);
    092            this.velocityZ = (int)(var8 * 8000.0D);
    093            this.metaData = par1EntityLiving.getDataWatcher();
    094        }
    095
    096        /**
    097         * Abstract. Reads the raw packet data from the data stream.
    098         */
    099        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    100        {
    101            this.entityId = par1DataInputStream.readInt();
    102            this.type = par1DataInputStream.readByte() & 255;
    103            this.xPosition = par1DataInputStream.readInt();
    104            this.yPosition = par1DataInputStream.readInt();
    105            this.zPosition = par1DataInputStream.readInt();
    106            this.yaw = par1DataInputStream.readByte();
    107            this.pitch = par1DataInputStream.readByte();
    108            this.headYaw = par1DataInputStream.readByte();
    109            this.velocityX = par1DataInputStream.readShort();
    110            this.velocityY = par1DataInputStream.readShort();
    111            this.velocityZ = par1DataInputStream.readShort();
    112            this.metadata = DataWatcher.readWatchableObjects(par1DataInputStream);
    113        }
    114
    115        /**
    116         * Abstract. Writes the raw packet data to the data stream.
    117         */
    118        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    119        {
    120            par1DataOutputStream.writeInt(this.entityId);
    121            par1DataOutputStream.writeByte(this.type & 255);
    122            par1DataOutputStream.writeInt(this.xPosition);
    123            par1DataOutputStream.writeInt(this.yPosition);
    124            par1DataOutputStream.writeInt(this.zPosition);
    125            par1DataOutputStream.writeByte(this.yaw);
    126            par1DataOutputStream.writeByte(this.pitch);
    127            par1DataOutputStream.writeByte(this.headYaw);
    128            par1DataOutputStream.writeShort(this.velocityX);
    129            par1DataOutputStream.writeShort(this.velocityY);
    130            par1DataOutputStream.writeShort(this.velocityZ);
    131            this.metaData.writeWatchableObjects(par1DataOutputStream);
    132        }
    133
    134        /**
    135         * Passes this Packet on to the NetHandler for processing.
    136         */
    137        public void processPacket(NetHandler par1NetHandler)
    138        {
    139            par1NetHandler.handleMobSpawn(this);
    140        }
    141
    142        /**
    143         * Abstract. Return the size of the packet (not counting the header).
    144         */
    145        public int getPacketSize()
    146        {
    147            return 26;
    148        }
    149
    150        @SideOnly(Side.CLIENT)
    151        public List getMetadata()
    152        {
    153            if (this.metadata == null)
    154            {
    155                this.metadata = this.metaData.func_75685_c();
    156            }
    157
    158            return this.metadata;
    159        }
    160    }