    001package net.minecraft.client.renderer.texture;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.Minecraft;
    006import net.minecraft.util.ChunkCoordinates;
    007import net.minecraft.world.World;
    008
    009@SideOnly(Side.CLIENT)
    010public class TextureCompass extends TextureStitched
    011{
    012    public static TextureCompass field_94243_h;
    013    public double field_94244_i;
    014    public double field_94242_j;
    015
    016    public TextureCompass()
    017    {
    018        super("compass");
    019        field_94243_h = this;
    020    }
    021
    022    public void func_94219_l()
    023    {
    024        Minecraft minecraft = Minecraft.getMinecraft();
    025
    026        if (minecraft.theWorld != null && minecraft.thePlayer != null)
    027        {
    028            this.func_94241_a(minecraft.theWorld, minecraft.thePlayer.posX, minecraft.thePlayer.posZ, (double)minecraft.thePlayer.rotationYaw, false, false);
    029        }
    030        else
    031        {
    032            this.func_94241_a((World)null, 0.0D, 0.0D, 0.0D, true, false);
    033        }
    034    }
    035
    036    public void func_94241_a(World par1World, double par2, double par4, double par6, boolean par8, boolean par9)
    037    {
    038        double d3 = 0.0D;
    039
    040        if (par1World != null && !par8)
    041        {
    042            ChunkCoordinates chunkcoordinates = par1World.getSpawnPoint();
    043            double d4 = (double)chunkcoordinates.posX - par2;
    044            double d5 = (double)chunkcoordinates.posZ - par4;
    045            par6 %= 360.0D;
    046            d3 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4));
    047
    048            if (!par1World.provider.isSurfaceWorld())
    049            {
    050                d3 = Math.random() * Math.PI * 2.0D;
    051            }
    052        }
    053
    054        if (par9)
    055        {
    056            this.field_94244_i = d3;
    057        }
    058        else
    059        {
    060            double d6;
    061
    062            for (d6 = d3 - this.field_94244_i; d6 < -Math.PI; d6 += (Math.PI * 2D))
    063            {
    064                ;
    065            }
    066
    067            while (d6 >= Math.PI)
    068            {
    069                d6 -= (Math.PI * 2D);
    070            }
    071
    072            if (d6 < -1.0D)
    073            {
    074                d6 = -1.0D;
    075            }
    076
    077            if (d6 > 1.0D)
    078            {
    079                d6 = 1.0D;
    080            }
    081
    082            this.field_94242_j += d6 * 0.1D;
    083            this.field_94242_j *= 0.8D;
    084            this.field_94244_i += this.field_94242_j;
    085        }
    086
    087        int i;
    088
    089        for (i = (int)((this.field_94244_i / (Math.PI * 2D) + 1.0D) * (double)this.field_94226_b.size()) % this.field_94226_b.size(); i < 0; i = (i + this.field_94226_b.size()) % this.field_94226_b.size())
    090        {
    091            ;
    092        }
    093
    094        if (i != this.field_94222_f)
    095        {
    096            this.field_94222_f = i;
    097            this.field_94228_a.func_94281_a(this.field_94224_d, this.field_94225_e, (Texture)this.field_94226_b.get(this.field_94222_f), this.field_94227_c);
    098        }
    099    }
    100}