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.EntityLiving;
007
008@SideOnly(Side.CLIENT)
009public class RenderSorter implements Comparator
010{
011    /** The entity (usually the player) that the camera is inside. */
012    private EntityLiving baseEntity;
013
014    public RenderSorter(EntityLiving par1EntityLiving)
015    {
016        this.baseEntity = par1EntityLiving;
017    }
018
019    public int doCompare(WorldRenderer par1WorldRenderer, WorldRenderer par2WorldRenderer)
020    {
021        if (par1WorldRenderer.isInFrustum && !par2WorldRenderer.isInFrustum)
022        {
023            return 1;
024        }
025        else if (par2WorldRenderer.isInFrustum && !par1WorldRenderer.isInFrustum)
026        {
027            return -1;
028        }
029        else
030        {
031            double d0 = (double)par1WorldRenderer.distanceToEntitySquared(this.baseEntity);
032            double d1 = (double)par2WorldRenderer.distanceToEntitySquared(this.baseEntity);
033            return d0 < d1 ? 1 : (d0 > d1 ? -1 : (par1WorldRenderer.chunkIndex < par2WorldRenderer.chunkIndex ? 1 : -1));
034        }
035    }
036
037    public int compare(Object par1Obj, Object par2Obj)
038    {
039        return this.doCompare((WorldRenderer)par1Obj, (WorldRenderer)par2Obj);
040    }
041}