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