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 SPacketEntity implements Packet<IClientPlayer>
{
    protected int entityId;
    protected byte posX;
    protected byte posY;
    protected byte posZ;
    protected byte yaw;
    protected byte pitch;
    protected boolean onGround;
    protected boolean rotation;

    public SPacketEntity()
    {
    }

    public SPacketEntity(int entityIdIn)
    {
        this.entityId = entityIdIn;
    }

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

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

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

    public String toString()
    {
        return "Entity_" + super.toString();
    }

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

    public byte getPosX()
    {
        return this.posX;
    }

    public byte getPosY()
    {
        return this.posY;
    }

    public byte getPosZ()
    {
        return this.posZ;
    }

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

    public byte getPitch()
    {
        return this.pitch;
    }

    public boolean hasRotations()
    {
        return this.rotation;
    }

    public boolean getOnGround()
    {
        return this.onGround;
    }
}
