package common.packet;

import java.io.IOException;

import common.entity.Entity;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.world.World;

public class SPacketEntityHeadLook implements Packet<IClientPlayer>
{
    private int entityId;
    private byte yaw;

    public SPacketEntityHeadLook()
    {
    }

    public SPacketEntityHeadLook(Entity entityIn, byte p_i45214_2_)
    {
        this.entityId = entityIn.getId();
        this.yaw = p_i45214_2_;
    }

    /**
     * Reads the raw packet data from the data stream.
     */
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        this.entityId = buf.readVarInt();
        this.yaw = buf.readByte();
    }

    /**
     * Writes the raw packet data to the data stream.
     */
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeVarInt(this.entityId);
        buf.writeByte(this.yaw);
    }

    /**
     * Passes this Packet on to the NetHandler for processing.
     */
    public void processPacket(IClientPlayer handler)
    {
        handler.handleEntityHeadLook(this);
    }

    public Entity getEntity(World worldIn)
    {
        return worldIn.getEntityByID(this.entityId);
    }

    public byte getYaw()
    {
        return this.yaw;
    }
}
