001package net.minecraft.client.renderer.texture;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.util.ArrayList;
006import java.util.Iterator;
007import java.util.List;
008
009@SideOnly(Side.CLIENT)
010public class StitchSlot
011{
012    public final int originX;
013    public final int originY;
014    public final int width;
015    public final int height;
016    private List subSlots;
017    private StitchHolder holder;
018
019    public StitchSlot(int par1, int par2, int par3, int par4)
020    {
021        this.originX = par1;
022        this.originY = par2;
023        this.width = par3;
024        this.height = par4;
025    }
026
027    public StitchHolder getStitchHolder()
028    {
029        return this.holder;
030    }
031
032    public int getOriginX()
033    {
034        return this.originX;
035    }
036
037    public int getOriginY()
038    {
039        return this.originY;
040    }
041
042    public boolean func_94182_a(StitchHolder par1StitchHolder)
043    {
044        if (this.holder != null)
045        {
046            return false;
047        }
048        else
049        {
050            int i = par1StitchHolder.getWidth();
051            int j = par1StitchHolder.getHeight();
052
053            if (i <= this.width && j <= this.height)
054            {
055                if (i == this.width && j == this.height)
056                {
057                    this.holder = par1StitchHolder;
058                    return true;
059                }
060                else
061                {
062                    if (this.subSlots == null)
063                    {
064                        this.subSlots = new ArrayList(1);
065                        this.subSlots.add(new StitchSlot(this.originX, this.originY, i, j));
066                        int k = this.width - i;
067                        int l = this.height - j;
068
069                        if (l > 0 && k > 0)
070                        {
071                            int i1 = Math.max(this.height, k);
072                            int j1 = Math.max(this.width, l);
073
074                            if (i1 >= j1)
075                            {
076                                this.subSlots.add(new StitchSlot(this.originX, this.originY + j, i, l));
077                                this.subSlots.add(new StitchSlot(this.originX + i, this.originY, k, this.height));
078                            }
079                            else
080                            {
081                                this.subSlots.add(new StitchSlot(this.originX + i, this.originY, k, j));
082                                this.subSlots.add(new StitchSlot(this.originX, this.originY + j, this.width, l));
083                            }
084                        }
085                        else if (k == 0)
086                        {
087                            this.subSlots.add(new StitchSlot(this.originX, this.originY + j, i, l));
088                        }
089                        else if (l == 0)
090                        {
091                            this.subSlots.add(new StitchSlot(this.originX + i, this.originY, k, j));
092                        }
093                    }
094
095                    Iterator iterator = this.subSlots.iterator();
096                    StitchSlot stitchslot;
097
098                    do
099                    {
100                        if (!iterator.hasNext())
101                        {
102                            return false;
103                        }
104
105                        stitchslot = (StitchSlot)iterator.next();
106                    }
107                    while (!stitchslot.func_94182_a(par1StitchHolder));
108
109                    return true;
110                }
111            }
112            else
113            {
114                return false;
115            }
116        }
117    }
118
119    /**
120     * Gets the slot and all its subslots
121     */
122    public void getAllStitchSlots(List par1List)
123    {
124        if (this.holder != null)
125        {
126            par1List.add(this);
127        }
128        else if (this.subSlots != null)
129        {
130            Iterator iterator = this.subSlots.iterator();
131
132            while (iterator.hasNext())
133            {
134                StitchSlot stitchslot = (StitchSlot)iterator.next();
135                stitchslot.getAllStitchSlots(par1List);
136            }
137        }
138    }
139
140    public String toString()
141    {
142        return "Slot{originX=" + this.originX + ", originY=" + this.originY + ", width=" + this.width + ", height=" + this.height + ", texture=" + this.holder + ", subSlots=" + this.subSlots + '}';
143    }
144}