    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        private double field_76868_i;
    020        private double field_76866_j;
    021
    022        public TextureCompassFX(Minecraft par1Minecraft)
    023        {
    024            super(Item.compass.getIconFromDamage(0));
    025            this.mc = par1Minecraft;
    026            this.tileImage = 1;
    027            setup();
    028        }
    029        @Override
    030        public void setup()
    031        {
    032            super.setup();
    033            compassIconImageData = new int[tileSizeSquare];
    034            try
    035            {
    036                BufferedImage var2 = ImageIO.read(mc.texturePackList.getSelectedTexturePack().getResourceAsStream("/gui/items.png"));
    037                int var3 = this.iconIndex % 16 * tileSizeBase;
    038                int var4 = this.iconIndex / 16 * tileSizeBase;
    039                var2.getRGB(var3, var4, tileSizeBase, tileSizeBase, this.compassIconImageData, 0, tileSizeBase);
    040            }
    041            catch (IOException var5)
    042            {
    043                var5.printStackTrace();
    044            }
    045        }
    046
    047        public void onTick()
    048        {
    049            for (int var1 = 0; var1 < tileSizeSquare; ++var1)
    050            {
    051                int var2 = this.compassIconImageData[var1] >> 24 & 255;
    052                int var3 = this.compassIconImageData[var1] >> 16 & 255;
    053                int var4 = this.compassIconImageData[var1] >> 8 & 255;
    054                int var5 = this.compassIconImageData[var1] >> 0 & 255;
    055
    056                if (this.anaglyphEnabled)
    057                {
    058                    int var6 = (var3 * 30 + var4 * 59 + var5 * 11) / 100;
    059                    int var7 = (var3 * 30 + var4 * 70) / 100;
    060                    int var8 = (var3 * 30 + var5 * 70) / 100;
    061                    var3 = var6;
    062                    var4 = var7;
    063                    var5 = var8;
    064                }
    065
    066                this.imageData[var1 * 4 + 0] = (byte)var3;
    067                this.imageData[var1 * 4 + 1] = (byte)var4;
    068                this.imageData[var1 * 4 + 2] = (byte)var5;
    069                this.imageData[var1 * 4 + 3] = (byte)var2;
    070            }
    071
    072            double var20 = 0.0D;
    073
    074            if (this.mc.theWorld != null && this.mc.thePlayer != null)
    075            {
    076                ChunkCoordinates var21 = this.mc.theWorld.getSpawnPoint();
    077                double var23 = (double)var21.posX - this.mc.thePlayer.posX;
    078                double var25 = (double)var21.posZ - this.mc.thePlayer.posZ;
    079                var20 = (double)(this.mc.thePlayer.rotationYaw - 90.0F) * Math.PI / 180.0D - Math.atan2(var25, var23);
    080
    081                if (!this.mc.theWorld.provider.isSurfaceWorld())
    082                {
    083                    var20 = Math.random() * Math.PI * 2.0D;
    084                }
    085            }
    086
    087            double var22;
    088
    089            for (var22 = var20 - this.field_76868_i; var22 < -Math.PI; var22 += (Math.PI * 2D))
    090            {
    091                ;
    092            }
    093
    094            while (var22 >= Math.PI)
    095            {
    096                var22 -= (Math.PI * 2D);
    097            }
    098
    099            if (var22 < -1.0D)
    100            {
    101                var22 = -1.0D;
    102            }
    103
    104            if (var22 > 1.0D)
    105            {
    106                var22 = 1.0D;
    107            }
    108
    109            this.field_76866_j += var22 * 0.1D;
    110            this.field_76866_j *= 0.8D;
    111            this.field_76868_i += this.field_76866_j;
    112            double var24 = Math.sin(this.field_76868_i);
    113            double var26 = Math.cos(this.field_76868_i);
    114            int var9;
    115            int var10;
    116            int var11;
    117            int var12;
    118            int var13;
    119            int var14;
    120            int var15;
    121            int var17;
    122            short var16;
    123            int var19;
    124            int var18;
    125
    126            for (var9 = -(tileSizeBase >> 2); var9 <= (tileSizeBase >> 2); ++var9)
    127            {
    128                var10 = (int)((tileSizeBase >> 1) + 0.5D + var26 * (double)var9 * 0.3D);
    129                var11 = (int)((tileSizeBase >> 1) - 0.5D - var24 * (double)var9 * 0.3D * 0.5D);
    130                var12 = var11 * tileSizeBase + var10;
    131                var13 = 100;
    132                var14 = 100;
    133                var15 = 100;
    134                var16 = 255;
    135
    136                if (this.anaglyphEnabled)
    137                {
    138                    var17 = (var13 * 30 + var14 * 59 + var15 * 11) / 100;
    139                    var18 = (var13 * 30 + var14 * 70) / 100;
    140                    var19 = (var13 * 30 + var15 * 70) / 100;
    141                    var13 = var17;
    142                    var14 = var18;
    143                    var15 = var19;
    144                }
    145
    146                this.imageData[var12 * 4 + 0] = (byte)var13;
    147                this.imageData[var12 * 4 + 1] = (byte)var14;
    148                this.imageData[var12 * 4 + 2] = (byte)var15;
    149                this.imageData[var12 * 4 + 3] = (byte)var16;
    150            }
    151
    152            for (var9 = -(tileSizeBase>>2); var9 <= tileSizeBase; ++var9)
    153            {
    154                var10 = (int)((tileSizeBase >> 1) + 0.5D + var24 * (double)var9 * 0.3D);
    155                var11 = (int)((tileSizeBase >> 1) - 0.5D + var26 * (double)var9 * 0.3D * 0.5D);
    156                var12 = var11 * tileSizeBase + var10;
    157                var13 = var9 >= 0 ? 255 : 100;
    158                var14 = var9 >= 0 ? 20 : 100;
    159                var15 = var9 >= 0 ? 20 : 100;
    160                var16 = 255;
    161
    162                if (this.anaglyphEnabled)
    163                {
    164                    var17 = (var13 * 30 + var14 * 59 + var15 * 11) / 100;
    165                    var18 = (var13 * 30 + var14 * 70) / 100;
    166                    var19 = (var13 * 30 + var15 * 70) / 100;
    167                    var13 = var17;
    168                    var14 = var18;
    169                    var15 = var19;
    170                }
    171
    172                this.imageData[var12 * 4 + 0] = (byte)var13;
    173                this.imageData[var12 * 4 + 1] = (byte)var14;
    174                this.imageData[var12 * 4 + 2] = (byte)var15;
    175                this.imageData[var12 * 4 + 3] = (byte)var16;
    176            }
    177        }
    178    }