    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 field_82654_c = 0;
    021
    022    /**
    023     * Return the biome used on this preset.
    024     */
    025    public int getBiome()
    026    {
    027        return this.field_82654_c;
    028    }
    029
    030    /**
    031     * Set the biome used on this preset.
    032     */
    033    public void setBiome(int par1)
    034    {
    035        this.field_82654_c = 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 var1 = 0;
    057        FlatLayerInfo var3;
    058
    059        for (Iterator var2 = this.flatLayers.iterator(); var2.hasNext(); var1 += var3.getLayerCount())
    060        {
    061            var3 = (FlatLayerInfo)var2.next();
    062            var3.setMinY(var1);
    063        }
    064    }
    065
    066    public String toString()
    067    {
    068        StringBuilder var1 = new StringBuilder();
    069        var1.append(2);
    070        var1.append(";");
    071        int var2;
    072
    073        for (var2 = 0; var2 < this.flatLayers.size(); ++var2)
    074        {
    075            if (var2 > 0)
    076            {
    077                var1.append(",");
    078            }
    079
    080            var1.append(((FlatLayerInfo)this.flatLayers.get(var2)).toString());
    081        }
    082
    083        var1.append(";");
    084        var1.append(this.field_82654_c);
    085
    086        if (!this.worldFeatures.isEmpty())
    087        {
    088            var1.append(";");
    089            var2 = 0;
    090            Iterator var3 = this.worldFeatures.entrySet().iterator();
    091
    092            while (var3.hasNext())
    093            {
    094                Entry var4 = (Entry)var3.next();
    095
    096                if (var2++ > 0)
    097                {
    098                    var1.append(",");
    099                }
    100
    101                var1.append(((String)var4.getKey()).toLowerCase());
    102                Map var5 = (Map)var4.getValue();
    103
    104                if (!var5.isEmpty())
    105                {
    106                    var1.append("(");
    107                    int var6 = 0;
    108                    Iterator var7 = var5.entrySet().iterator();
    109
    110                    while (var7.hasNext())
    111                    {
    112                        Entry var8 = (Entry)var7.next();
    113
    114                        if (var6++ > 0)
    115                        {
    116                            var1.append(" ");
    117                        }
    118
    119                        var1.append((String)var8.getKey());
    120                        var1.append("=");
    121                        var1.append((String)var8.getValue());
    122                    }
    123
    124                    var1.append(")");
    125                }
    126            }
    127        }
    128        else
    129        {
    130            var1.append(";");
    131        }
    132
    133        return var1.toString();
    134    }
    135
    136    private static FlatLayerInfo func_82646_a(String par0Str, int par1)
    137    {
    138        String[] var2 = par0Str.split("x", 2);
    139        int var3 = 1;
    140        int var5 = 0;
    141
    142        if (var2.length == 2)
    143        {
    144            try
    145            {
    146                var3 = Integer.parseInt(var2[0]);
    147
    148                if (par1 + var3 >= 256)
    149                {
    150                    var3 = 256 - par1;
    151                }
    152
    153                if (var3 < 0)
    154                {
    155                    var3 = 0;
    156                }
    157            }
    158            catch (Throwable var7)
    159            {
    160                return null;
    161            }
    162        }
    163
    164        int var4;
    165
    166        try
    167        {
    168            String var6 = var2[var2.length - 1];
    169            var2 = var6.split(":", 2);
    170            var4 = Integer.parseInt(var2[0]);
    171
    172            if (var2.length > 1)
    173            {
    174                var5 = Integer.parseInt(var2[1]);
    175            }
    176
    177            if (Block.blocksList[var4] == null)
    178            {
    179                var4 = 0;
    180                var5 = 0;
    181            }
    182
    183            if (var5 < 0 || var5 > 15)
    184            {
    185                var5 = 0;
    186            }
    187        }
    188        catch (Throwable var8)
    189        {
    190            return null;
    191        }
    192
    193        FlatLayerInfo var9 = new FlatLayerInfo(var3, var4, var5);
    194        var9.setMinY(par1);
    195        return var9;
    196    }
    197
    198    private static List func_82652_b(String par0Str)
    199    {
    200        if (par0Str != null && par0Str.length() >= 1)
    201        {
    202            ArrayList var1 = new ArrayList();
    203            String[] var2 = par0Str.split(",");
    204            int var3 = 0;
    205            String[] var4 = var2;
    206            int var5 = var2.length;
    207
    208            for (int var6 = 0; var6 < var5; ++var6)
    209            {
    210                String var7 = var4[var6];
    211                FlatLayerInfo var8 = func_82646_a(var7, var3);
    212
    213                if (var8 == null)
    214                {
    215                    return null;
    216                }
    217
    218                var1.add(var8);
    219                var3 += var8.getLayerCount();
    220            }
    221
    222            return var1;
    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[] var1 = par0Str.split(";", -1);
    239            int var2 = var1.length == 1 ? 0 : MathHelper.parseIntWithDefault(var1[0], 0);
    240
    241            if (var2 >= 0 && var2 <= 2)
    242            {
    243                FlatGeneratorInfo var3 = new FlatGeneratorInfo();
    244                int var4 = var1.length == 1 ? 0 : 1;
    245                List var5 = func_82652_b(var1[var4++]);
    246
    247                if (var5 != null && !var5.isEmpty())
    248                {
    249                    var3.getFlatLayers().addAll(var5);
    250                    var3.func_82645_d();
    251                    int var6 = BiomeGenBase.plains.biomeID;
    252
    253                    if (var2 > 0 && var1.length > var4)
    254                    {
    255                        var6 = MathHelper.parseIntWithDefault(var1[var4++], var6);
    256                    }
    257
    258                    var3.setBiome(var6);
    259
    260                    if (var2 > 0 && var1.length > var4)
    261                    {
    262                        String[] var7 = var1[var4++].toLowerCase().split(",");
    263                        String[] var8 = var7;
    264                        int var9 = var7.length;
    265
    266                        for (int var10 = 0; var10 < var9; ++var10)
    267                        {
    268                            String var11 = var8[var10];
    269                            String[] var12 = var11.split("\\(", 2);
    270                            HashMap var13 = new HashMap();
    271
    272                            if (var12[0].length() > 0)
    273                            {
    274                                var3.getWorldFeatures().put(var12[0], var13);
    275
    276                                if (var12.length > 1 && var12[1].endsWith(")") && var12[1].length() > 1)
    277                                {
    278                                    String[] var14 = var12[1].substring(0, var12[1].length() - 1).split(" ");
    279
    280                                    for (int var15 = 0; var15 < var14.length; ++var15)
    281                                    {
    282                                        String[] var16 = var14[var15].split("=", 2);
    283
    284                                        if (var16.length == 2)
    285                                        {
    286                                            var13.put(var16[0], var16[1]);
    287                                        }
    288                                    }
    289                                }
    290                            }
    291                        }
    292                    }
    293                    else
    294                    {
    295                        var3.getWorldFeatures().put("village", new HashMap());
    296                    }
    297
    298                    return var3;
    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 var0 = new FlatGeneratorInfo();
    315        var0.setBiome(BiomeGenBase.plains.biomeID);
    316        var0.getFlatLayers().add(new FlatLayerInfo(1, Block.bedrock.blockID));
    317        var0.getFlatLayers().add(new FlatLayerInfo(2, Block.dirt.blockID));
    318        var0.getFlatLayers().add(new FlatLayerInfo(1, Block.grass.blockID));
    319        var0.func_82645_d();
    320        var0.getWorldFeatures().put("village", new HashMap());
    321        return var0;
    322    }
    323}