    001    package net.minecraft.client.renderer;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.util.Comparator;
    006    import net.minecraft.entity.EntityLiving;
    007
    008    @SideOnly(Side.CLIENT)
    009    public 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 var3 = (double)par1WorldRenderer.distanceToEntitySquared(this.baseEntity);
    032                double var5 = (double)par2WorldRenderer.distanceToEntitySquared(this.baseEntity);
    033                return var3 < var5 ? 1 : (var3 > var5 ? -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    }