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 SPacketEntityStatus implements Packet<IClientPlayer>
{
    private int entityId;
    private byte logicOpcode;

    public SPacketEntityStatus()
    {
    }

    public SPacketEntityStatus(Entity entityIn, byte opCodeIn)
    {
        this.entityId = entityIn.getId();
        this.logicOpcode = opCodeIn;
    }

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

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

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

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

    public byte getOpCode()
    {
        return this.logicOpcode;
    }
}
