    001package net.minecraft.client.renderer.texturefx;
    002
    003import cpw.mods.fml.client.FMLTextureFX;
    004import cpw.mods.fml.relauncher.Side;
    005import cpw.mods.fml.relauncher.SideOnly;
    006import java.awt.image.BufferedImage;
    007import java.io.IOException;
    008import javax.imageio.ImageIO;
    009import net.minecraft.client.Minecraft;
    010import net.minecraft.item.Item;
    011import net.minecraft.util.ChunkCoordinates;
    012
    013@SideOnly(Side.CLIENT)
    014public class TextureCompassFX extends FMLTextureFX
    015{
    016    /** A reference to the Minecraft object. */
    017    private Minecraft mc;
    018
    019    /** Holds the image of the compass from items.png in rgb format. */
    020    private int[] compassIconImageData = new int[256];
    021    public double field_76868_i;
    022    public double field_76866_j;
    023    public static TextureCompassFX instance;
    024    public static int stileSizeBase = 16;
    025    public static int stileSizeSquare = 256;
    026    public static int stileSizeMask = 15;
    027    public static int stileSizeSquareMask = 255;
    028
    029    public TextureCompassFX(Minecraft par1Minecraft)
    030    {
    031        super(Item.compass.getIconFromDamage(0));
    032        this.mc = par1Minecraft;
    033        this.tileImage = 1;
    034
    035        setup();
    036    }
    037
    038    @Override
    039    public void setup()
    040    {
    041        super.setup();
    042        stileSizeBase = tileSizeBase;
    043        stileSizeSquare = tileSizeSquare;
    044        stileSizeMask = tileSizeMask;
    045        stileSizeSquareMask = tileSizeSquareMask;
    046        compassIconImageData = new int[tileSizeSquare];
    047
    048        try
    049        {
    050            BufferedImage var2 = ImageIO.read(mc.texturePackList.getSelectedTexturePack().getResourceAsStream("/gui/items.png"));
    051            int var3 = this.iconIndex % 16 * tileSizeBase;
    052            int var4 = this.iconIndex / 16 * tileSizeBase;
    053            var2.getRGB(var3, var4, tileSizeBase, tileSizeBase, this.compassIconImageData, 0, tileSizeBase);
    054        }
    055        catch (IOException var5)
    056        {
    057            var5.printStackTrace();
    058        }
    059
    060        instance = this;
    061    }
    062
    063    public void onTick()
    064    {
    065        if (this.mc.theWorld != null && this.mc.thePlayer != null)
    066        {
    067            func_82390_a(this.mc.thePlayer.posX, this.mc.thePlayer.posZ, (double)this.mc.thePlayer.rotationYaw, false, false);
    068        }
    069        else
    070        {
    071            func_82390_a(0.0D, 0.0D, 0.0D, true, false);
    072        }
    073    }
    074
    075    public static void func_82390_a(double par0, double par2, double par4, boolean par6, boolean par7)
    076    {
    077        int[] var8 = instance.compassIconImageData;
    078        byte[] var9 = instance.imageData;
    079        int var17;
    080        int var16;
    081
    082        for (int var10 = 0; var10 < stileSizeSquare; ++var10)
    083        {
    084            int var11 = var8[var10] >> 24 & 255;
    085            int var12 = var8[var10] >> 16 & 255;
    086            int var13 = var8[var10] >> 8 & 255;
    087            int var14 = var8[var10] >> 0 & 255;
    088
    089            if (instance.anaglyphEnabled)
    090            {
    091                int var15 = (var12 * 30 + var13 * 59 + var14 * 11) / 100;
    092                var16 = (var12 * 30 + var13 * 70) / 100;
    093                var17 = (var12 * 30 + var14 * 70) / 100;
    094                var12 = var15;
    095                var13 = var16;
    096                var14 = var17;
    097            }
    098
    099            var9[var10 * 4 + 0] = (byte)var12;
    100            var9[var10 * 4 + 1] = (byte)var13;
    101            var9[var10 * 4 + 2] = (byte)var14;
    102            var9[var10 * 4 + 3] = (byte)var11;
    103        }
    104
    105        double var27 = 0.0D;
    106
    107        if (instance.mc.theWorld != null && !par6)
    108        {
    109            ChunkCoordinates var29 = instance.mc.theWorld.getSpawnPoint();
    110            double var28 = (double)var29.posX - par0;
    111            double var32 = (double)var29.posZ - par2;
    112            var27 = (par4 - 90.0D) * Math.PI / 180.0D - Math.atan2(var32, var28);
    113
    114            if (!instance.mc.theWorld.provider.isSurfaceWorld())
    115            {
    116                var27 = Math.random() * Math.PI * 2.0D;
    117            }
    118        }
    119
    120        double var30;
    121
    122        if (par7)
    123        {
    124            instance.field_76868_i = var27;
    125        }
    126        else
    127        {
    128            for (var30 = var27 - instance.field_76868_i; var30 < -Math.PI; var30 += (Math.PI * 2D))
    129            {
    130                ;
    131            }
    132
    133            while (var30 >= Math.PI)
    134            {
    135                var30 -= (Math.PI * 2D);
    136            }
    137
    138            if (var30 < -1.0D)
    139            {
    140                var30 = -1.0D;
    141            }
    142
    143            if (var30 > 1.0D)
    144            {
    145                var30 = 1.0D;
    146            }
    147
    148            instance.field_76866_j += var30 * 0.1D;
    149            instance.field_76866_j *= 0.8D;
    150            instance.field_76868_i += instance.field_76866_j;
    151        }
    152
    153        var30 = Math.sin(instance.field_76868_i);
    154        double var31 = Math.cos(instance.field_76868_i);
    155        int var19;
    156        int var18;
    157        int var21;
    158        int var20;
    159        short var23;
    160        int var22;
    161        int var25;
    162        int var24;
    163        int var26;
    164
    165        for (var16 = -(stileSizeBase >> 2); var16 <= (stileSizeBase >> 2); ++var16)
    166        {
    167            var17 = (int)((stileSizeBase >> 1) + 0.5D + var31 * (double)var16 * 0.3D);
    168            var18 = (int)((stileSizeBase >> 1) - 0.5D - var30 * (double)var16 * 0.3D * 0.5D);
    169            var19 = var18 * stileSizeBase + var17;
    170            var20 = 100;
    171            var21 = 100;
    172            var22 = 100;
    173            var23 = 255;
    174
    175            if (instance.anaglyphEnabled)
    176            {
    177                var24 = (var20 * 30 + var21 * 59 + var22 * 11) / 100;
    178                var25 = (var20 * 30 + var21 * 70) / 100;
    179                var26 = (var20 * 30 + var22 * 70) / 100;
    180                var20 = var24;
    181                var21 = var25;
    182                var22 = var26;
    183            }
    184
    185            var9[var19 * 4 + 0] = (byte)var20;
    186            var9[var19 * 4 + 1] = (byte)var21;
    187            var9[var19 * 4 + 2] = (byte)var22;
    188            var9[var19 * 4 + 3] = (byte)var23;
    189        }
    190
    191
    192        for (var16 = -(stileSizeBase>>2); var16 <= stileSizeBase; ++var16)
    193        {
    194            var17 = (int)((stileSizeBase >> 1) + 0.5D + var30 * (double)var16 * 0.3D);
    195            var18 = (int)((stileSizeBase >> 1) - 0.5D + var31 * (double)var16 * 0.3D * 0.5D);
    196            var19 = var18 * stileSizeBase + var17;
    197            var20 = var16 >= 0 ? 255 : 100;
    198            var21 = var16 >= 0 ? 20 : 100;
    199            var22 = var16 >= 0 ? 20 : 100;
    200            var23 = 255;
    201
    202            if (instance.anaglyphEnabled)
    203            {
    204                var24 = (var20 * 30 + var21 * 59 + var22 * 11) / 100;
    205                var25 = (var20 * 30 + var21 * 70) / 100;
    206                var26 = (var20 * 30 + var22 * 70) / 100;
    207                var20 = var24;
    208                var21 = var25;
    209                var22 = var26;
    210            }
    211
    212            var9[var19 * 4 + 0] = (byte)var20;
    213            var9[var19 * 4 + 1] = (byte)var21;
    214            var9[var19 * 4 + 2] = (byte)var22;
    215            var9[var19 * 4 + 3] = (byte)var23;
    216        }
    217    }
    218}