    001package net.minecraft.client.renderer;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.Comparator;
    006import net.minecraft.entity.Entity;
    007
    008@SideOnly(Side.CLIENT)
    009public class EntitySorter implements Comparator
    010{
    011    /** Entity position X */
    012    private double entityPosX;
    013
    014    /** Entity position Y */
    015    private double entityPosY;
    016
    017    /** Entity position Z */
    018    private double entityPosZ;
    019
    020    public EntitySorter(Entity par1Entity)
    021    {
    022        this.entityPosX = -par1Entity.posX;
    023        this.entityPosY = -par1Entity.posY;
    024        this.entityPosZ = -par1Entity.posZ;
    025    }
    026
    027    /**
    028     * Sorts the two world renderers according to their distance to a given entity.
    029     */
    030    public int sortByDistanceToEntity(WorldRenderer par1WorldRenderer, WorldRenderer par2WorldRenderer)
    031    {
    032        double var3 = (double)par1WorldRenderer.posXPlus + this.entityPosX;
    033        double var5 = (double)par1WorldRenderer.posYPlus + this.entityPosY;
    034        double var7 = (double)par1WorldRenderer.posZPlus + this.entityPosZ;
    035        double var9 = (double)par2WorldRenderer.posXPlus + this.entityPosX;
    036        double var11 = (double)par2WorldRenderer.posYPlus + this.entityPosY;
    037        double var13 = (double)par2WorldRenderer.posZPlus + this.entityPosZ;
    038        return (int)((var3 * var3 + var5 * var5 + var7 * var7 - (var9 * var9 + var11 * var11 + var13 * var13)) * 1024.0D);
    039    }
    040
    041    public int compare(Object par1Obj, Object par2Obj)
    042    {
    043        return this.sortByDistanceToEntity((WorldRenderer)par1Obj, (WorldRenderer)par2Obj);
    044    }
    045}