Ejemplo n.º 1
0
 @Override
 public LocalWorld getWorld(String name) {
   LocalWorld world = worldType.worldTC;
   if (world == null) {
     return null;
   }
   if (world.getName().equals(name)) {
     return world;
   }
   return null;
 }
Ejemplo n.º 2
0
  public WorldConfig(File settingsDir, LocalWorld world, boolean checkOnly) {
    this.SettingsDir = settingsDir;
    this.WorldName = world.getName();

    File settingsFile = new File(this.SettingsDir, TCDefaultValues.WorldSettingsName.stringValue());

    this.ReadSettingsFile(settingsFile);
    this.RenameOldSettings();
    this.ReadConfigSettings();

    this.CorrectSettings();

    ReadWorldCustomObjects();

    // Check biome ids

    for (String biomeName : CustomBiomes)
      if (CustomBiomeIds.get(biomeName) == -1)
        CustomBiomeIds.put(biomeName, world.getFreeBiomeId());

    // Need add check to clashes
    if (this.SettingsMode != ConfigMode.WriteDisable)
      this.WriteSettingsFile(settingsFile, (this.SettingsMode == ConfigMode.WriteAll));

    world.setHeightBits(this.worldHeightBits);

    File BiomeFolder =
        new File(SettingsDir, TCDefaultValues.WorldBiomeConfigDirectoryName.stringValue());
    if (!BiomeFolder.exists()) {
      if (!BiomeFolder.mkdir()) {
        System.out.println(
            "TerrainControl: error create biome configs directory, working with defaults");
        return;
      }
    }

    ArrayList<LocalBiome> localBiomes = new ArrayList<LocalBiome>(world.getDefaultBiomes());

    // Add custom biomes to world
    for (String biomeName : this.CustomBiomes) {
      if (checkOnly) localBiomes.add(world.getNullBiome(biomeName));
      else localBiomes.add(world.AddBiome(biomeName, this.CustomBiomeIds.get(biomeName)));
    }

    // Build biome replace matrix
    for (int i = 0; i < this.ReplaceMatrixBiomes.length; i++)
      this.ReplaceMatrixBiomes[i] = (byte) i;

    this.biomeConfigs = new BiomeConfig[world.getMaxBiomesCount()];

    String LoadedBiomeNames = "";

    for (LocalBiome localBiome : localBiomes) {
      BiomeConfig config = new BiomeConfig(BiomeFolder, localBiome, this);
      if (checkOnly) continue;

      if (!config.ReplaceBiomeName.equals("")) {
        this.HaveBiomeReplace = true;
        this.ReplaceMatrixBiomes[config.Biome.getId()] =
            (byte) world.getBiomeIdByName(config.ReplaceBiomeName);
      }

      if (this.NormalBiomes.contains(config.Name)) this.normalBiomesRarity += config.BiomeRarity;
      if (this.IceBiomes.contains(config.Name)) this.iceBiomesRarity += config.BiomeRarity;

      this.biomeConfigs[localBiome.getId()] = config;
      if (!this.BiomeConfigsHaveReplacement)
        this.BiomeConfigsHaveReplacement = config.ReplaceCount > 0;
      if (this.biomes.size() != 0) LoadedBiomeNames += ", ";
      LoadedBiomeNames += localBiome.getName();
      this.biomes.add(config);

      if (this.ModeBiome == BiomeMode.FromImage) {
        if (this.biomeColorMap == null) this.biomeColorMap = new HashMap<Integer, Integer>();

        try {
          int color = Integer.decode(config.BiomeColor);
          if (color <= 0xFFFFFF) this.biomeColorMap.put(color, config.Biome.getId());
        } catch (NumberFormatException ex) {
          System.out.println("TerrainControl: wrong color in " + config.Biome.getName());
        }
      }
    }

    System.out.println("TerrainControl: Loaded biomes - " + LoadedBiomeNames);
  }