| 1 | package net.minecraft.world.gen;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Map;
|
| 7 | import java.util.Map.Entry;
|
| 8 | import net.minecraft.block.Block;
|
| 9 | import net.minecraft.init.Blocks;
|
| 10 | import net.minecraft.util.MathHelper;
|
| 11 | import net.minecraft.world.biome.BiomeGenBase;
|
| 12 |
|
| 13 | public class FlatGeneratorInfo
|
| 14 | {
|
| 15 | private final List<FlatLayerInfo> flatLayers = Lists.<FlatLayerInfo>newArrayList();
|
| 16 | private final Map<String, Map<String, String>> worldFeatures = Maps.<String, Map<String, String>>newHashMap();
|
| 17 | private int biomeToUse;
|
| 18 |
|
| 19 | /**
|
| 20 | * Return the biome used on this preset.
|
| 21 | */
|
| 22 | public int getBiome()
|
| 23 | {
|
| 24 | return this.biomeToUse;
|
| 25 | }
|
| 26 |
|
| 27 | /**
|
| 28 | * Set the biome used on this preset.
|
| 29 | */
|
| 30 | public void setBiome(int biome)
|
| 31 | {
|
| 32 | this.biomeToUse = biome;
|
| 33 | }
|
| 34 |
|
| 35 | public Map<String, Map<String, String>> getWorldFeatures()
|
| 36 | {
|
| 37 | return this.worldFeatures;
|
| 38 | }
|
| 39 |
|
| 40 | public List<FlatLayerInfo> getFlatLayers()
|
| 41 | {
|
| 42 | return this.flatLayers;
|
| 43 | }
|
| 44 |
|
| 45 | public void func_82645_d()
|
| 46 | {
|
| 47 | int i = 0;
|
| 48 |
|
| 49 | for (FlatLayerInfo flatlayerinfo : this.flatLayers)
|
| 50 | {
|
| 51 | flatlayerinfo.setMinY(i);
|
| 52 | i += flatlayerinfo.getLayerCount();
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | public String toString()
|
| 57 | {
|
| 58 | StringBuilder stringbuilder = new StringBuilder();
|
| 59 | stringbuilder.append((int)3);
|
| 60 | stringbuilder.append(";");
|
| 61 |
|
| 62 | for (int i = 0; i < this.flatLayers.size(); ++i)
|
| 63 | {
|
| 64 | if (i > 0)
|
| 65 | {
|
| 66 | stringbuilder.append(",");
|
| 67 | }
|
| 68 |
|
| 69 | stringbuilder.append(((FlatLayerInfo)this.flatLayers.get(i)).toString());
|
| 70 | }
|
| 71 |
|
| 72 | stringbuilder.append(";");
|
| 73 | stringbuilder.append(this.biomeToUse);
|
| 74 |
|
| 75 | if (!this.worldFeatures.isEmpty())
|
| 76 | {
|
| 77 | stringbuilder.append(";");
|
| 78 | int k = 0;
|
| 79 |
|
| 80 | for (Entry<String, Map<String, String>> entry : this.worldFeatures.entrySet())
|
| 81 | {
|
| 82 | if (k++ > 0)
|
| 83 | {
|
| 84 | stringbuilder.append(",");
|
| 85 | }
|
| 86 |
|
| 87 | stringbuilder.append(((String)entry.getKey()).toLowerCase());
|
| 88 | Map<String, String> map = (Map)entry.getValue();
|
| 89 |
|
| 90 | if (!map.isEmpty())
|
| 91 | {
|
| 92 | stringbuilder.append("(");
|
| 93 | int j = 0;
|
| 94 |
|
| 95 | for (Entry<String, String> entry1 : map.entrySet())
|
| 96 | {
|
| 97 | if (j++ > 0)
|
| 98 | {
|
| 99 | stringbuilder.append(" ");
|
| 100 | }
|
| 101 |
|
| 102 | stringbuilder.append((String)entry1.getKey());
|
| 103 | stringbuilder.append("=");
|
| 104 | stringbuilder.append((String)entry1.getValue());
|
| 105 | }
|
| 106 |
|
| 107 | stringbuilder.append(")");
|
| 108 | }
|
| 109 | }
|
| 110 | }
|
| 111 | else
|
| 112 | {
|
| 113 | stringbuilder.append(";");
|
| 114 | }
|
| 115 |
|
| 116 | return stringbuilder.toString();
|
| 117 | }
|
| 118 |
|
| 119 | private static FlatLayerInfo func_180715_a(int p_180715_0_, String p_180715_1_, int p_180715_2_)
|
| 120 | {
|
| 121 | String[] astring = p_180715_0_ >= 3 ? p_180715_1_.split("\\*", 2) : p_180715_1_.split("x", 2);
|
| 122 | int i = 1;
|
| 123 | int j = 0;
|
| 124 |
|
| 125 | if (astring.length == 2)
|
| 126 | {
|
| 127 | try
|
| 128 | {
|
| 129 | i = Integer.parseInt(astring[0]);
|
| 130 |
|
| 131 | if (p_180715_2_ + i >= 256)
|
| 132 | {
|
| 133 | i = 256 - p_180715_2_;
|
| 134 | }
|
| 135 |
|
| 136 | if (i < 0)
|
| 137 | {
|
| 138 | i = 0;
|
| 139 | }
|
| 140 | }
|
| 141 | catch (Throwable var8)
|
| 142 | {
|
| 143 | return null;
|
| 144 | }
|
| 145 | }
|
| 146 |
|
| 147 | Block block = null;
|
| 148 |
|
| 149 | try
|
| 150 | {
|
| 151 | String s = astring[astring.length - 1];
|
| 152 |
|
| 153 | if (p_180715_0_ < 3)
|
| 154 | {
|
| 155 | astring = s.split(":", 2);
|
| 156 |
|
| 157 | if (astring.length > 1)
|
| 158 | {
|
| 159 | j = Integer.parseInt(astring[1]);
|
| 160 | }
|
| 161 |
|
| 162 | block = Block.getBlockById(Integer.parseInt(astring[0]));
|
| 163 | }
|
| 164 | else
|
| 165 | {
|
| 166 | astring = s.split(":", 3);
|
| 167 | block = astring.length > 1 ? Block.getBlockFromName(astring[0] + ":" + astring[1]) : null;
|
| 168 |
|
| 169 | if (block != null)
|
| 170 | {
|
| 171 | j = astring.length > 2 ? Integer.parseInt(astring[2]) : 0;
|
| 172 | }
|
| 173 | else
|
| 174 | {
|
| 175 | block = Block.getBlockFromName(astring[0]);
|
| 176 |
|
| 177 | if (block != null)
|
| 178 | {
|
| 179 | j = astring.length > 1 ? Integer.parseInt(astring[1]) : 0;
|
| 180 | }
|
| 181 | }
|
| 182 |
|
| 183 | if (block == null)
|
| 184 | {
|
| 185 | return null;
|
| 186 | }
|
| 187 | }
|
| 188 |
|
| 189 | if (block == Blocks.air)
|
| 190 | {
|
| 191 | j = 0;
|
| 192 | }
|
| 193 |
|
| 194 | if (j < 0 || j > 15)
|
| 195 | {
|
| 196 | j = 0;
|
| 197 | }
|
| 198 | }
|
| 199 | catch (Throwable var9)
|
| 200 | {
|
| 201 | return null;
|
| 202 | }
|
| 203 |
|
| 204 | FlatLayerInfo flatlayerinfo = new FlatLayerInfo(p_180715_0_, i, block, j);
|
| 205 | flatlayerinfo.setMinY(p_180715_2_);
|
| 206 | return flatlayerinfo;
|
| 207 | }
|
| 208 |
|
| 209 | private static List<FlatLayerInfo> func_180716_a(int p_180716_0_, String p_180716_1_)
|
| 210 | {
|
| 211 | if (p_180716_1_ != null && p_180716_1_.length() >= 1)
|
| 212 | {
|
| 213 | List<FlatLayerInfo> list = Lists.<FlatLayerInfo>newArrayList();
|
| 214 | String[] astring = p_180716_1_.split(",");
|
| 215 | int i = 0;
|
| 216 |
|
| 217 | for (String s : astring)
|
| 218 | {
|
| 219 | FlatLayerInfo flatlayerinfo = func_180715_a(p_180716_0_, s, i);
|
| 220 |
|
| 221 | if (flatlayerinfo == null)
|
| 222 | {
|
| 223 | return null;
|
| 224 | }
|
| 225 |
|
| 226 | list.add(flatlayerinfo);
|
| 227 | i += flatlayerinfo.getLayerCount();
|
| 228 | }
|
| 229 |
|
| 230 | return list;
|
| 231 | }
|
| 232 | else
|
| 233 | {
|
| 234 | return null;
|
| 235 | }
|
| 236 | }
|
| 237 |
|
| 238 | public static FlatGeneratorInfo createFlatGeneratorFromString(String flatGeneratorSettings)
|
| 239 | {
|
| 240 | if (flatGeneratorSettings == null)
|
| 241 | {
|
| 242 | return getDefaultFlatGenerator();
|
| 243 | }
|
| 244 | else
|
| 245 | {
|
| 246 | String[] astring = flatGeneratorSettings.split(";", -1);
|
| 247 | int i = astring.length == 1 ? 0 : MathHelper.parseIntWithDefault(astring[0], 0);
|
| 248 |
|
| 249 | if (i >= 0 && i <= 3)
|
| 250 | {
|
| 251 | FlatGeneratorInfo flatgeneratorinfo = new FlatGeneratorInfo();
|
| 252 | int j = astring.length == 1 ? 0 : 1;
|
| 253 | List<FlatLayerInfo> list = func_180716_a(i, astring[j++]);
|
| 254 |
|
| 255 | if (list != null && !list.isEmpty())
|
| 256 | {
|
| 257 | flatgeneratorinfo.getFlatLayers().addAll(list);
|
| 258 | flatgeneratorinfo.func_82645_d();
|
| 259 | int k = BiomeGenBase.plains.biomeID;
|
| 260 |
|
| 261 | if (i > 0 && astring.length > j)
|
| 262 | {
|
| 263 | k = MathHelper.parseIntWithDefault(astring[j++], k);
|
| 264 | }
|
| 265 |
|
| 266 | flatgeneratorinfo.setBiome(k);
|
| 267 |
|
| 268 | if (i > 0 && astring.length > j)
|
| 269 | {
|
| 270 | String[] astring1 = astring[j++].toLowerCase().split(",");
|
| 271 |
|
| 272 | for (String s : astring1)
|
| 273 | {
|
| 274 | String[] astring2 = s.split("\\(", 2);
|
| 275 | Map<String, String> map = Maps.<String, String>newHashMap();
|
| 276 |
|
| 277 | if (astring2[0].length() > 0)
|
| 278 | {
|
| 279 | flatgeneratorinfo.getWorldFeatures().put(astring2[0], map);
|
| 280 |
|
| 281 | if (astring2.length > 1 && astring2[1].endsWith(")") && astring2[1].length() > 1)
|
| 282 | {
|
| 283 | String[] astring3 = astring2[1].substring(0, astring2[1].length() - 1).split(" ");
|
| 284 |
|
| 285 | for (int l = 0; l < astring3.length; ++l)
|
| 286 | {
|
| 287 | String[] astring4 = astring3[l].split("=", 2);
|
| 288 |
|
| 289 | if (astring4.length == 2)
|
| 290 | {
|
| 291 | map.put(astring4[0], astring4[1]);
|
| 292 | }
|
| 293 | }
|
| 294 | }
|
| 295 | }
|
| 296 | }
|
| 297 | }
|
| 298 | else
|
| 299 | {
|
| 300 | flatgeneratorinfo.getWorldFeatures().put("village", Maps.<String, String>newHashMap());
|
| 301 | }
|
| 302 |
|
| 303 | return flatgeneratorinfo;
|
| 304 | }
|
| 305 | else
|
| 306 | {
|
| 307 | return getDefaultFlatGenerator();
|
| 308 | }
|
| 309 | }
|
| 310 | else
|
| 311 | {
|
| 312 | return getDefaultFlatGenerator();
|
| 313 | }
|
| 314 | }
|
| 315 | }
|
| 316 |
|
| 317 | public static FlatGeneratorInfo getDefaultFlatGenerator()
|
| 318 | {
|
| 319 | FlatGeneratorInfo flatgeneratorinfo = new FlatGeneratorInfo();
|
| 320 | flatgeneratorinfo.setBiome(BiomeGenBase.plains.biomeID);
|
| 321 | flatgeneratorinfo.getFlatLayers().add(new FlatLayerInfo(1, Blocks.bedrock));
|
| 322 | flatgeneratorinfo.getFlatLayers().add(new FlatLayerInfo(2, Blocks.dirt));
|
| 323 | flatgeneratorinfo.getFlatLayers().add(new FlatLayerInfo(1, Blocks.grass));
|
| 324 | flatgeneratorinfo.func_82645_d();
|
| 325 | flatgeneratorinfo.getWorldFeatures().put("village", Maps.<String, String>newHashMap());
|
| 326 | return flatgeneratorinfo;
|
| 327 | }
|
| 328 | }
|
| 329 |
|