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 d0 = (double)par1WorldRenderer.posXPlus + this.entityPosX;
033        double d1 = (double)par1WorldRenderer.posYPlus + this.entityPosY;
034        double d2 = (double)par1WorldRenderer.posZPlus + this.entityPosZ;
035        double d3 = (double)par2WorldRenderer.posXPlus + this.entityPosX;
036        double d4 = (double)par2WorldRenderer.posYPlus + this.entityPosY;
037        double d5 = (double)par2WorldRenderer.posZPlus + this.entityPosZ;
038        return (int)((d0 * d0 + d1 * d1 + d2 * d2 - (d3 * d3 + d4 * d4 + d5 * d5)) * 1024.0D);
039    }
040
041    public int compare(Object par1Obj, Object par2Obj)
042    {
043        return this.sortByDistanceToEntity((WorldRenderer)par1Obj, (WorldRenderer)par2Obj);
044    }
045}