    001    package net.minecraft.client.renderer.texturefx;
    002
    003    import cpw.mods.fml.client.FMLTextureFX;
    004    import cpw.mods.fml.common.Side;
    005    import cpw.mods.fml.common.asm.SideOnly;
    006
    007    import java.awt.Graphics2D;
    008    import java.awt.image.BufferedImage;
    009    import java.awt.image.ImageObserver;
    010    import java.io.IOException;
    011    import java.util.logging.Level;
    012
    013    import javax.imageio.ImageIO;
    014    import net.minecraft.client.Minecraft;
    015    import net.minecraft.item.Item;
    016
    017    @SideOnly(Side.CLIENT)
    018    public class TextureWatchFX extends FMLTextureFX
    019    {
    020        /**
    021         * Holds the game instance to retrieve information like world provider and time.
    022         */
    023        private Minecraft mc;
    024
    025        /** Holds the image of the watch from items.png in rgb format. */
    026        private int[] watchIconImageData = new int[256];
    027
    028        /** Holds the image of the dial.png in rgb format. */
    029        private int[] dialImageData = new int[256];
    030        private double field_76861_j;
    031        private double field_76862_k;
    032
    033        public TextureWatchFX(Minecraft par1Minecraft)
    034        {
    035            super(Item.pocketSundial.getIconFromDamage(0));
    036            this.mc = par1Minecraft;
    037            this.tileImage = 1;
    038            setup();
    039        }
    040
    041        @Override
    042        public void setup()
    043        {
    044            super.setup();
    045            watchIconImageData = new int[tileSizeSquare];
    046            dialImageData = 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.watchIconImageData, 0, tileSizeBase);
    054                var2 = ImageIO.read(mc.texturePackList.getSelectedTexturePack().getResourceAsStream("/misc/dial.png"));
    055                if (var2.getWidth() != tileSizeBase)
    056                {
    057                    BufferedImage tmp = new BufferedImage(tileSizeBase, tileSizeBase, 6);
    058                    Graphics2D gfx = tmp.createGraphics();
    059                    gfx.drawImage(var2, 0, 0, tileSizeBase, tileSizeBase, 0, 0, var2.getWidth(), var2.getHeight(), (ImageObserver)null);
    060                    gfx.dispose();
    061                    var2 = tmp;
    062                }
    063
    064                var2.getRGB(0, 0, tileSizeBase, tileSizeBase, this.dialImageData, 0, tileSizeBase);
    065            }
    066            catch (Exception var5)
    067            {
    068                var5.printStackTrace();
    069                log.log(Level.WARNING, String.format("A problem occurred with the watch texture: animation will be disabled"), var5);
    070                setErrored(true);
    071            }
    072        }
    073
    074        public void onTick()
    075        {
    076            double var1 = 0.0D;
    077
    078            if (this.mc.theWorld != null && this.mc.thePlayer != null)
    079            {
    080                float var3 = this.mc.theWorld.getCelestialAngle(1.0F);
    081                var1 = (double)(-var3 * (float)Math.PI * 2.0F);
    082
    083                if (!this.mc.theWorld.provider.isSurfaceWorld())
    084                {
    085                    var1 = Math.random() * Math.PI * 2.0D;
    086                }
    087            }
    088
    089            double var22;
    090
    091            for (var22 = var1 - this.field_76861_j; var22 < -Math.PI; var22 += (Math.PI * 2D))
    092            {
    093                ;
    094            }
    095
    096            while (var22 >= Math.PI)
    097            {
    098                var22 -= (Math.PI * 2D);
    099            }
    100
    101            if (var22 < -1.0D)
    102            {
    103                var22 = -1.0D;
    104            }
    105
    106            if (var22 > 1.0D)
    107            {
    108                var22 = 1.0D;
    109            }
    110
    111            this.field_76862_k += var22 * 0.1D;
    112            this.field_76862_k *= 0.8D;
    113            this.field_76861_j += this.field_76862_k;
    114            double var5 = Math.sin(this.field_76861_j);
    115            double var7 = Math.cos(this.field_76861_j);
    116
    117            for (int var9 = 0; var9 < tileSizeSquare; ++var9)
    118            {
    119                int var10 = this.watchIconImageData[var9] >> 24 & 255;
    120                int var11 = this.watchIconImageData[var9] >> 16 & 255;
    121                int var12 = this.watchIconImageData[var9] >> 8 & 255;
    122                int var13 = this.watchIconImageData[var9] >> 0 & 255;
    123
    124                if (var11 == var13 && var12 == 0 && var13 > 0)
    125                {
    126                    double var14 = -((double)(var9 % tileSizeBase) / tileSizeMask - 0.5D);
    127                    double var16 = (double)(var9 / tileSizeBase) / tileSizeMask - 0.5D;
    128                    int var18 = var11;
    129                    int var19 = (int)((var14 * var7 + var16 * var5 + 0.5D) * tileSizeBase);
    130                    int var20 = (int)((var16 * var7 - var14 * var5 + 0.5D) * tileSizeBase);
    131                    int var21 = (var19 & tileSizeMask) + (var20 & tileSizeMask) * tileSizeBase;
    132                    var10 = this.dialImageData[var21] >> 24 & 255;
    133                    var11 = (this.dialImageData[var21] >> 16 & 255) * var11 / 255;
    134                    var12 = (this.dialImageData[var21] >> 8 & 255) * var18 / 255;
    135                    var13 = (this.dialImageData[var21] >> 0 & 255) * var18 / 255;
    136                }
    137
    138                if (this.anaglyphEnabled)
    139                {
    140                    int var23 = (var11 * 30 + var12 * 59 + var13 * 11) / 100;
    141                    int var15 = (var11 * 30 + var12 * 70) / 100;
    142                    int var24 = (var11 * 30 + var13 * 70) / 100;
    143                    var11 = var23;
    144                    var12 = var15;
    145                    var13 = var24;
    146                }
    147
    148                this.imageData[var9 * 4 + 0] = (byte)var11;
    149                this.imageData[var9 * 4 + 1] = (byte)var12;
    150                this.imageData[var9 * 4 + 2] = (byte)var13;
    151                this.imageData[var9 * 4 + 3] = (byte)var10;
    152            }
    153        }
    154    }