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