    001    package net.minecraft.world.gen;
    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    import net.minecraft.block.Block;
    010    import net.minecraft.util.MathHelper;
    011    import net.minecraft.world.biome.BiomeGenBase;
    012
    013    public 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
    129            return var1.toString();
    130        }
    131
    132        private static FlatLayerInfo func_82646_a(String par0Str, int par1)
    133        {
    134            String[] var2 = par0Str.split("x", 2);
    135            int var3 = 1;
    136            int var5 = 0;
    137
    138            if (var2.length == 2)
    139            {
    140                try
    141                {
    142                    var3 = Integer.parseInt(var2[0]);
    143
    144                    if (par1 + var3 >= 256)
    145                    {
    146                        var3 = 256 - par1;
    147                    }
    148
    149                    if (var3 < 0)
    150                    {
    151                        var3 = 0;
    152                    }
    153                }
    154                catch (Throwable var7)
    155                {
    156                    return null;
    157                }
    158            }
    159
    160            int var4;
    161
    162            try
    163            {
    164                String var6 = var2[var2.length - 1];
    165                var2 = var6.split(":", 2);
    166                var4 = Integer.parseInt(var2[0]);
    167
    168                if (var2.length > 1)
    169                {
    170                    var5 = Integer.parseInt(var2[1]);
    171                }
    172
    173                if (Block.blocksList[var4] == null)
    174                {
    175                    var4 = 0;
    176                    var5 = 0;
    177                }
    178
    179                if (var5 < 0 || var5 > 15)
    180                {
    181                    var5 = 0;
    182                }
    183            }
    184            catch (Throwable var8)
    185            {
    186                return null;
    187            }
    188
    189            FlatLayerInfo var9 = new FlatLayerInfo(var3, var4, var5);
    190            var9.setMinY(par1);
    191            return var9;
    192        }
    193
    194        private static List func_82652_b(String par0Str)
    195        {
    196            if (par0Str != null && par0Str.length() >= 1)
    197            {
    198                ArrayList var1 = new ArrayList();
    199                String[] var2 = par0Str.split(",");
    200                int var3 = 0;
    201                String[] var4 = var2;
    202                int var5 = var2.length;
    203
    204                for (int var6 = 0; var6 < var5; ++var6)
    205                {
    206                    String var7 = var4[var6];
    207                    FlatLayerInfo var8 = func_82646_a(var7, var3);
    208
    209                    if (var8 == null)
    210                    {
    211                        return null;
    212                    }
    213
    214                    var1.add(var8);
    215                    var3 += var8.getLayerCount();
    216                }
    217
    218                return var1;
    219            }
    220            else
    221            {
    222                return null;
    223            }
    224        }
    225
    226        public static FlatGeneratorInfo createFlatGeneratorFromString(String par0Str)
    227        {
    228            if (par0Str == null)
    229            {
    230                return getDefaultFlatGenerator();
    231            }
    232            else
    233            {
    234                String[] var1 = par0Str.split(";", -1);
    235                int var2 = var1.length == 1 ? 0 : MathHelper.parseIntWithDefault(var1[0], 0);
    236
    237                if (var2 >= 0 && var2 <= 2)
    238                {
    239                    FlatGeneratorInfo var3 = new FlatGeneratorInfo();
    240                    int var4 = var1.length == 1 ? 0 : 1;
    241                    List var5 = func_82652_b(var1[var4++]);
    242
    243                    if (var5 != null && !var5.isEmpty())
    244                    {
    245                        var3.getFlatLayers().addAll(var5);
    246                        var3.func_82645_d();
    247                        int var6 = BiomeGenBase.plains.biomeID;
    248
    249                        if (var2 > 0 && var1.length > var4)
    250                        {
    251                            var6 = MathHelper.parseIntWithDefault(var1[var4++], var6);
    252                        }
    253
    254                        var3.setBiome(var6);
    255
    256                        if (var2 > 0 && var1.length > var4)
    257                        {
    258                            String[] var7 = var1[var4++].toLowerCase().split(",");
    259                            String[] var8 = var7;
    260                            int var9 = var7.length;
    261
    262                            for (int var10 = 0; var10 < var9; ++var10)
    263                            {
    264                                String var11 = var8[var10];
    265                                String[] var12 = var11.split("\\(", 2);
    266                                HashMap var13 = new HashMap();
    267
    268                                if (var12[0].length() > 0)
    269                                {
    270                                    var3.getWorldFeatures().put(var12[0], var13);
    271
    272                                    if (var12.length > 1 && var12[1].endsWith(")") && var12[1].length() > 1)
    273                                    {
    274                                        String[] var14 = var12[1].substring(0, var12[1].length() - 1).split(" ");
    275
    276                                        for (int var15 = 0; var15 < var14.length; ++var15)
    277                                        {
    278                                            String[] var16 = var14[var15].split("=", 2);
    279
    280                                            if (var16.length == 2)
    281                                            {
    282                                                var13.put(var16[0], var16[1]);
    283                                            }
    284                                        }
    285                                    }
    286                                }
    287                            }
    288                        }
    289                        else
    290                        {
    291                            var3.getWorldFeatures().put("village", new HashMap());
    292                        }
    293
    294                        return var3;
    295                    }
    296                    else
    297                    {
    298                        return getDefaultFlatGenerator();
    299                    }
    300                }
    301                else
    302                {
    303                    return getDefaultFlatGenerator();
    304                }
    305            }
    306        }
    307
    308        public static FlatGeneratorInfo getDefaultFlatGenerator()
    309        {
    310            FlatGeneratorInfo var0 = new FlatGeneratorInfo();
    311            var0.setBiome(BiomeGenBase.plains.biomeID);
    312            var0.getFlatLayers().add(new FlatLayerInfo(1, Block.bedrock.blockID));
    313            var0.getFlatLayers().add(new FlatLayerInfo(2, Block.dirt.blockID));
    314            var0.getFlatLayers().add(new FlatLayerInfo(1, Block.grass.blockID));
    315            var0.func_82645_d();
    316            var0.getWorldFeatures().put("village", new HashMap());
    317            return var0;
    318        }
    319    }