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