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