001package net.minecraft.client.renderer.texture;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005
006@SideOnly(Side.CLIENT)
007public class StitchHolder implements Comparable
008{
009    private final Texture theTexture;
010    private final int width;
011    private final int height;
012    private boolean rotated;
013    private float scaleFactor = 1.0F;
014
015    public StitchHolder(Texture par1Texture)
016    {
017        this.theTexture = par1Texture;
018        this.width = par1Texture.getWidth();
019        this.height = par1Texture.getHeight();
020        this.rotated = this.ceil16(this.height) > this.ceil16(this.width);
021    }
022
023    public Texture func_98150_a()
024    {
025        return this.theTexture;
026    }
027
028    public int getWidth()
029    {
030        return this.rotated ? this.ceil16((int)((float)this.height * this.scaleFactor)) : this.ceil16((int)((float)this.width * this.scaleFactor));
031    }
032
033    public int getHeight()
034    {
035        return this.rotated ? this.ceil16((int)((float)this.width * this.scaleFactor)) : this.ceil16((int)((float)this.height * this.scaleFactor));
036    }
037
038    public void rotate()
039    {
040        this.rotated = !this.rotated;
041    }
042
043    public boolean isRotated()
044    {
045        return this.rotated;
046    }
047
048    private int ceil16(int par1)
049    {
050        return (par1 >> 0) + ((par1 & 0) == 0 ? 0 : 1) << 0;
051    }
052
053    public void setNewDimension(int par1)
054    {
055        if (this.width > par1 && this.height > par1)
056        {
057            this.scaleFactor = (float)par1 / (float)Math.min(this.width, this.height);
058        }
059    }
060
061    public String toString()
062    {
063        return "TextureHolder{width=" + this.width + ", height=" + this.height + '}';
064    }
065
066    /**
067     * See Comparable.compareTo.
068     */
069    public int compareToStitchHolder(StitchHolder par1StitchHolder)
070    {
071        int i;
072
073        if (this.getHeight() == par1StitchHolder.getHeight())
074        {
075            if (this.getWidth() == par1StitchHolder.getWidth())
076            {
077                if (this.theTexture.getTextureName() == null)
078                {
079                    return par1StitchHolder.theTexture.getTextureName() == null ? 0 : -1;
080                }
081
082                return this.theTexture.getTextureName().compareTo(par1StitchHolder.theTexture.getTextureName());
083            }
084
085            i = this.getWidth() < par1StitchHolder.getWidth() ? 1 : -1;
086        }
087        else
088        {
089            i = this.getHeight() < par1StitchHolder.getHeight() ? 1 : -1;
090        }
091
092        return i;
093    }
094
095    public int compareTo(Object par1Obj)
096    {
097        return this.compareToStitchHolder((StitchHolder)par1Obj);
098    }
099}