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    private final int field_94192_a;
013    private final int field_94190_b;
014    private final int field_94191_c;
015    private final int field_94188_d;
016    private List field_94189_e;
017    private StitchHolder field_94187_f;
018
019    public StitchSlot(int par1, int par2, int par3, int par4)
020    {
021        this.field_94192_a = par1;
022        this.field_94190_b = par2;
023        this.field_94191_c = par3;
024        this.field_94188_d = par4;
025    }
026
027    public StitchHolder func_94183_a()
028    {
029        return this.field_94187_f;
030    }
031
032    public int func_94186_b()
033    {
034        return this.field_94192_a;
035    }
036
037    public int func_94185_c()
038    {
039        return this.field_94190_b;
040    }
041
042    public boolean func_94182_a(StitchHolder par1StitchHolder)
043    {
044        if (this.field_94187_f != null)
045        {
046            return false;
047        }
048        else
049        {
050            int i = par1StitchHolder.func_94197_a();
051            int j = par1StitchHolder.func_94199_b();
052
053            if (i <= this.field_94191_c && j <= this.field_94188_d)
054            {
055                if (i == this.field_94191_c && j == this.field_94188_d)
056                {
057                    this.field_94187_f = par1StitchHolder;
058                    return true;
059                }
060                else
061                {
062                    if (this.field_94189_e == null)
063                    {
064                        this.field_94189_e = new ArrayList(1);
065                        this.field_94189_e.add(new StitchSlot(this.field_94192_a, this.field_94190_b, i, j));
066                        int k = this.field_94191_c - i;
067                        int l = this.field_94188_d - j;
068
069                        if (l > 0 && k > 0)
070                        {
071                            int i1 = Math.max(this.field_94188_d, k);
072                            int j1 = Math.max(this.field_94191_c, l);
073
074                            if (i1 >= j1)
075                            {
076                                this.field_94189_e.add(new StitchSlot(this.field_94192_a, this.field_94190_b + j, i, l));
077                                this.field_94189_e.add(new StitchSlot(this.field_94192_a + i, this.field_94190_b, k, this.field_94188_d));
078                            }
079                            else
080                            {
081                                this.field_94189_e.add(new StitchSlot(this.field_94192_a + i, this.field_94190_b, k, j));
082                                this.field_94189_e.add(new StitchSlot(this.field_94192_a, this.field_94190_b + j, this.field_94191_c, l));
083                            }
084                        }
085                        else if (k == 0)
086                        {
087                            this.field_94189_e.add(new StitchSlot(this.field_94192_a, this.field_94190_b + j, i, l));
088                        }
089                        else if (l == 0)
090                        {
091                            this.field_94189_e.add(new StitchSlot(this.field_94192_a + i, this.field_94190_b, k, j));
092                        }
093                    }
094
095                    Iterator iterator = this.field_94189_e.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    public void func_94184_a(List par1List)
120    {
121        if (this.field_94187_f != null)
122        {
123            par1List.add(this);
124        }
125        else if (this.field_94189_e != null)
126        {
127            Iterator iterator = this.field_94189_e.iterator();
128
129            while (iterator.hasNext())
130            {
131                StitchSlot stitchslot = (StitchSlot)iterator.next();
132                stitchslot.func_94184_a(par1List);
133            }
134        }
135    }
136
137    public String toString()
138    {
139        return "Slot{originX=" + this.field_94192_a + ", originY=" + this.field_94190_b + ", width=" + this.field_94191_c + ", height=" + this.field_94188_d + ", texture=" + this.field_94187_f + ", subSlots=" + this.field_94189_e + '}';
140    }
141}