    001package net.minecraft.network.packet;
    002
    003import java.io.DataInputStream;
    004import java.io.DataOutputStream;
    005import java.io.IOException;
    006import net.minecraft.entity.Entity;
    007import net.minecraft.util.MathHelper;
    008
    009public class Packet34EntityTeleport extends Packet
    010{
    011    /** ID of the entity. */
    012    public int entityId;
    013
    014    /** X position of the entity. */
    015    public int xPosition;
    016
    017    /** Y position of the entity. */
    018    public int yPosition;
    019
    020    /** Z position of the entity. */
    021    public int zPosition;
    022
    023    /** Yaw of the entity. */
    024    public byte yaw;
    025
    026    /** Pitch of the entity. */
    027    public byte pitch;
    028
    029    public Packet34EntityTeleport() {}
    030
    031    public Packet34EntityTeleport(Entity par1Entity)
    032    {
    033        this.entityId = par1Entity.entityId;
    034        this.xPosition = MathHelper.floor_double(par1Entity.posX * 32.0D);
    035        this.yPosition = MathHelper.floor_double(par1Entity.posY * 32.0D);
    036        this.zPosition = MathHelper.floor_double(par1Entity.posZ * 32.0D);
    037        this.yaw = (byte)((int)(par1Entity.rotationYaw * 256.0F / 360.0F));
    038        this.pitch = (byte)((int)(par1Entity.rotationPitch * 256.0F / 360.0F));
    039    }
    040
    041    public Packet34EntityTeleport(int par1, int par2, int par3, int par4, byte par5, byte par6)
    042    {
    043        this.entityId = par1;
    044        this.xPosition = par2;
    045        this.yPosition = par3;
    046        this.zPosition = par4;
    047        this.yaw = par5;
    048        this.pitch = par6;
    049    }
    050
    051    /**
    052     * Abstract. Reads the raw packet data from the data stream.
    053     */
    054    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    055    {
    056        this.entityId = par1DataInputStream.readInt();
    057        this.xPosition = par1DataInputStream.readInt();
    058        this.yPosition = par1DataInputStream.readInt();
    059        this.zPosition = par1DataInputStream.readInt();
    060        this.yaw = (byte)par1DataInputStream.read();
    061        this.pitch = (byte)par1DataInputStream.read();
    062    }
    063
    064    /**
    065     * Abstract. Writes the raw packet data to the data stream.
    066     */
    067    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    068    {
    069        par1DataOutputStream.writeInt(this.entityId);
    070        par1DataOutputStream.writeInt(this.xPosition);
    071        par1DataOutputStream.writeInt(this.yPosition);
    072        par1DataOutputStream.writeInt(this.zPosition);
    073        par1DataOutputStream.write(this.yaw);
    074        par1DataOutputStream.write(this.pitch);
    075    }
    076
    077    /**
    078     * Passes this Packet on to the NetHandler for processing.
    079     */
    080    public void processPacket(NetHandler par1NetHandler)
    081    {
    082        par1NetHandler.handleEntityTeleport(this);
    083    }
    084
    085    /**
    086     * Abstract. Return the size of the packet (not counting the header).
    087     */
    088    public int getPacketSize()
    089    {
    090        return 34;
    091    }
    092
    093    /**
    094     * only false for the abstract Packet class, all real packets return true
    095     */
    096    public boolean isRealPacket()
    097    {
    098        return true;
    099    }
    100
    101    /**
    102     * eg return packet30entity.entityId == entityId; WARNING : will throw if you compare a packet to a different packet
    103     * class
    104     */
    105    public boolean containsSameEntityIDAs(Packet par1Packet)
    106    {
    107        Packet34EntityTeleport packet34entityteleport = (Packet34EntityTeleport)par1Packet;
    108        return packet34entityteleport.entityId == this.entityId;
    109    }
    110}