    001package net.minecraft.network.packet;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.io.DataInputStream;
    006import java.io.DataOutputStream;
    007import java.io.IOException;
    008import net.minecraft.potion.PotionEffect;
    009
    010public class Packet41EntityEffect extends Packet
    011{
    012    public int entityId;
    013    public byte effectId;
    014
    015    /** The effect's amplifier. */
    016    public byte effectAmplifier;
    017    public short duration;
    018
    019    public Packet41EntityEffect() {}
    020
    021    public Packet41EntityEffect(int par1, PotionEffect par2PotionEffect)
    022    {
    023        this.entityId = par1;
    024        this.effectId = (byte)(par2PotionEffect.getPotionID() & 255);
    025        this.effectAmplifier = (byte)(par2PotionEffect.getAmplifier() & 255);
    026
    027        if (par2PotionEffect.getDuration() > 32767)
    028        {
    029            this.duration = 32767;
    030        }
    031        else
    032        {
    033            this.duration = (short)par2PotionEffect.getDuration();
    034        }
    035    }
    036
    037    /**
    038     * Abstract. Reads the raw packet data from the data stream.
    039     */
    040    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    041    {
    042        this.entityId = par1DataInputStream.readInt();
    043        this.effectId = par1DataInputStream.readByte();
    044        this.effectAmplifier = par1DataInputStream.readByte();
    045        this.duration = par1DataInputStream.readShort();
    046    }
    047
    048    /**
    049     * Abstract. Writes the raw packet data to the data stream.
    050     */
    051    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    052    {
    053        par1DataOutputStream.writeInt(this.entityId);
    054        par1DataOutputStream.writeByte(this.effectId);
    055        par1DataOutputStream.writeByte(this.effectAmplifier);
    056        par1DataOutputStream.writeShort(this.duration);
    057    }
    058
    059    /**
    060     * Passes this Packet on to the NetHandler for processing.
    061     */
    062    public void processPacket(NetHandler par1NetHandler)
    063    {
    064        par1NetHandler.handleEntityEffect(this);
    065    }
    066
    067    /**
    068     * Abstract. Return the size of the packet (not counting the header).
    069     */
    070    public int getPacketSize()
    071    {
    072        return 8;
    073    }
    074
    075    @SideOnly(Side.CLIENT)
    076
    077    /**
    078     * Returns true if duration is at maximum, false otherwise.
    079     */
    080    public boolean isDurationMax()
    081    {
    082        return this.duration == 32767;
    083    }
    084
    085    /**
    086     * only false for the abstract Packet class, all real packets return true
    087     */
    088    public boolean isRealPacket()
    089    {
    090        return true;
    091    }
    092
    093    /**
    094     * eg return packet30entity.entityId == entityId; WARNING : will throw if you compare a packet to a different packet
    095     * class
    096     */
    097    public boolean containsSameEntityIDAs(Packet par1Packet)
    098    {
    099        Packet41EntityEffect packet41entityeffect = (Packet41EntityEffect)par1Packet;
    100        return packet41entityeffect.entityId == this.entityId && packet41entityeffect.effectId == this.effectId;
    101    }
    102}