    001package net.minecraft.world.gen;
    002
    003import java.util.ArrayList;
    004import java.util.HashMap;
    005import java.util.Iterator;
    006import java.util.List;
    007import java.util.Map;
    008import java.util.Map.Entry;
    009import net.minecraft.block.Block;
    010import net.minecraft.util.MathHelper;
    011import net.minecraft.world.biome.BiomeGenBase;
    012
    013public class FlatGeneratorInfo
    014{
    015    /** List of layers on this preset. */
    016    private final List flatLayers = new ArrayList();
    017
    018    /** List of world features enabled on this preset. */
    019    private final Map worldFeatures = new HashMap();
    020    private int biomeToUse = 0;
    021
    022    /**
    023     * Return the biome used on this preset.
    024     */
    025    public int getBiome()
    026    {
    027        return this.biomeToUse;
    028    }
    029
    030    /**
    031     * Set the biome used on this preset.
    032     */
    033    public void setBiome(int par1)
    034    {
    035        this.biomeToUse = par1;
    036    }
    037
    038    /**
    039     * Return the list of world features enabled on this preset.
    040     */
    041    public Map getWorldFeatures()
    042    {
    043        return this.worldFeatures;
    044    }
    045
    046    /**
    047     * Return the list of layers on this preset.
    048     */
    049    public List getFlatLayers()
    050    {
    051        return this.flatLayers;
    052    }
    053
    054    public void func_82645_d()
    055    {
    056        int i = 0;
    057        FlatLayerInfo flatlayerinfo;
    058
    059        for (Iterator iterator = this.flatLayers.iterator(); iterator.hasNext(); i += flatlayerinfo.getLayerCount())
    060        {
    061            flatlayerinfo = (FlatLayerInfo)iterator.next();
    062            flatlayerinfo.setMinY(i);
    063        }
    064    }
    065
    066    public String toString()
    067    {
    068        StringBuilder stringbuilder = new StringBuilder();
    069        stringbuilder.append(2);
    070        stringbuilder.append(";");
    071        int i;
    072
    073        for (i = 0; i < this.flatLayers.size(); ++i)
    074        {
    075            if (i > 0)
    076            {
    077                stringbuilder.append(",");
    078            }
    079
    080            stringbuilder.append(((FlatLayerInfo)this.flatLayers.get(i)).toString());
    081        }
    082
    083        stringbuilder.append(";");
    084        stringbuilder.append(this.biomeToUse);
    085
    086        if (!this.worldFeatures.isEmpty())
    087        {
    088            stringbuilder.append(";");
    089            i = 0;
    090            Iterator iterator = this.worldFeatures.entrySet().iterator();
    091
    092            while (iterator.hasNext())
    093            {
    094                Entry entry = (Entry)iterator.next();
    095
    096                if (i++ > 0)
    097                {
    098                    stringbuilder.append(",");
    099                }
    100
    101                stringbuilder.append(((String)entry.getKey()).toLowerCase());
    102                Map map = (Map)entry.getValue();
    103
    104                if (!map.isEmpty())
    105                {
    106                    stringbuilder.append("(");
    107                    int j = 0;
    108                    Iterator iterator1 = map.entrySet().iterator();
    109
    110                    while (iterator1.hasNext())
    111                    {
    112                        Entry entry1 = (Entry)iterator1.next();
    113
    114                        if (j++ > 0)
    115                        {
    116                            stringbuilder.append(" ");
    117                        }
    118
    119                        stringbuilder.append((String)entry1.getKey());
    120                        stringbuilder.append("=");
    121                        stringbuilder.append((String)entry1.getValue());
    122                    }
    123
    124                    stringbuilder.append(")");
    125                }
    126            }
    127        }
    128        else
    129        {
    130            stringbuilder.append(";");
    131        }
    132
    133        return stringbuilder.toString();
    134    }
    135
    136    private static FlatLayerInfo func_82646_a(String par0Str, int par1)
    137    {
    138        String[] astring = par0Str.split("x", 2);
    139        int j = 1;
    140        int k = 0;
    141
    142        if (astring.length == 2)
    143        {
    144            try
    145            {
    146                j = Integer.parseInt(astring[0]);
    147
    148                if (par1 + j >= 256)
    149                {
    150                    j = 256 - par1;
    151                }
    152
    153                if (j < 0)
    154                {
    155                    j = 0;
    156                }
    157            }
    158            catch (Throwable throwable)
    159            {
    160                return null;
    161            }
    162        }
    163
    164        int l;
    165
    166        try
    167        {
    168            String s1 = astring[astring.length - 1];
    169            astring = s1.split(":", 2);
    170            l = Integer.parseInt(astring[0]);
    171
    172            if (astring.length > 1)
    173            {
    174                k = Integer.parseInt(astring[1]);
    175            }
    176
    177            if (Block.blocksList[l] == null)
    178            {
    179                l = 0;
    180                k = 0;
    181            }
    182
    183            if (k < 0 || k > 15)
    184            {
    185                k = 0;
    186            }
    187        }
    188        catch (Throwable throwable1)
    189        {
    190            return null;
    191        }
    192
    193        FlatLayerInfo flatlayerinfo = new FlatLayerInfo(j, l, k);
    194        flatlayerinfo.setMinY(par1);
    195        return flatlayerinfo;
    196    }
    197
    198    private static List func_82652_b(String par0Str)
    199    {
    200        if (par0Str != null && par0Str.length() >= 1)
    201        {
    202            ArrayList arraylist = new ArrayList();
    203            String[] astring = par0Str.split(",");
    204            int i = 0;
    205            String[] astring1 = astring;
    206            int j = astring.length;
    207
    208            for (int k = 0; k < j; ++k)
    209            {
    210                String s1 = astring1[k];
    211                FlatLayerInfo flatlayerinfo = func_82646_a(s1, i);
    212
    213                if (flatlayerinfo == null)
    214                {
    215                    return null;
    216                }
    217
    218                arraylist.add(flatlayerinfo);
    219                i += flatlayerinfo.getLayerCount();
    220            }
    221
    222            return arraylist;
    223        }
    224        else
    225        {
    226            return null;
    227        }
    228    }
    229
    230    public static FlatGeneratorInfo createFlatGeneratorFromString(String par0Str)
    231    {
    232        if (par0Str == null)
    233        {
    234            return getDefaultFlatGenerator();
    235        }
    236        else
    237        {
    238            String[] astring = par0Str.split(";", -1);
    239            int i = astring.length == 1 ? 0 : MathHelper.parseIntWithDefault(astring[0], 0);
    240
    241            if (i >= 0 && i <= 2)
    242            {
    243                FlatGeneratorInfo flatgeneratorinfo = new FlatGeneratorInfo();
    244                int j = astring.length == 1 ? 0 : 1;
    245                List list = func_82652_b(astring[j++]);
    246
    247                if (list != null && !list.isEmpty())
    248                {
    249                    flatgeneratorinfo.getFlatLayers().addAll(list);
    250                    flatgeneratorinfo.func_82645_d();
    251                    int k = BiomeGenBase.plains.biomeID;
    252
    253                    if (i > 0 && astring.length > j)
    254                    {
    255                        k = MathHelper.parseIntWithDefault(astring[j++], k);
    256                    }
    257
    258                    flatgeneratorinfo.setBiome(k);
    259
    260                    if (i > 0 && astring.length > j)
    261                    {
    262                        String[] astring1 = astring[j++].toLowerCase().split(",");
    263                        String[] astring2 = astring1;
    264                        int l = astring1.length;
    265
    266                        for (int i1 = 0; i1 < l; ++i1)
    267                        {
    268                            String s1 = astring2[i1];
    269                            String[] astring3 = s1.split("\\(", 2);
    270                            HashMap hashmap = new HashMap();
    271
    272                            if (astring3[0].length() > 0)
    273                            {
    274                                flatgeneratorinfo.getWorldFeatures().put(astring3[0], hashmap);
    275
    276                                if (astring3.length > 1 && astring3[1].endsWith(")") && astring3[1].length() > 1)
    277                                {
    278                                    String[] astring4 = astring3[1].substring(0, astring3[1].length() - 1).split(" ");
    279
    280                                    for (int j1 = 0; j1 < astring4.length; ++j1)
    281                                    {
    282                                        String[] astring5 = astring4[j1].split("=", 2);
    283
    284                                        if (astring5.length == 2)
    285                                        {
    286                                            hashmap.put(astring5[0], astring5[1]);
    287                                        }
    288                                    }
    289                                }
    290                            }
    291                        }
    292                    }
    293                    else
    294                    {
    295                        flatgeneratorinfo.getWorldFeatures().put("village", new HashMap());
    296                    }
    297
    298                    return flatgeneratorinfo;
    299                }
    300                else
    301                {
    302                    return getDefaultFlatGenerator();
    303                }
    304            }
    305            else
    306            {
    307                return getDefaultFlatGenerator();
    308            }
    309        }
    310    }
    311
    312    public static FlatGeneratorInfo getDefaultFlatGenerator()
    313    {
    314        FlatGeneratorInfo flatgeneratorinfo = new FlatGeneratorInfo();
    315        flatgeneratorinfo.setBiome(BiomeGenBase.plains.biomeID);
    316        flatgeneratorinfo.getFlatLayers().add(new FlatLayerInfo(1, Block.bedrock.blockID));
    317        flatgeneratorinfo.getFlatLayers().add(new FlatLayerInfo(2, Block.dirt.blockID));
    318        flatgeneratorinfo.getFlatLayers().add(new FlatLayerInfo(1, Block.grass.blockID));
    319        flatgeneratorinfo.func_82645_d();
    320        flatgeneratorinfo.getWorldFeatures().put("village", new HashMap());
    321        return flatgeneratorinfo;
    322    }
    323}