diff --git a/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java b/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java index 3faebeb65..138cd054d 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java @@ -13,8 +13,6 @@ import java.util.HashMap; import java.util.Map; import biomesoplenty.common.util.config.BOPConfig.IConfigObj; -import biomesoplenty.common.world.feature.*; -import biomesoplenty.common.world.feature.tree.*; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; @@ -75,57 +73,12 @@ public class GenerationManager else { // there was previously no generator of this name - attempt to add it - IGenerator generator = GeneratorFactory.create(conf); + IGenerator generator = GeneratorRegistry.createGenerator(conf); if (generator != null) { this.generators.put(name, generator); } } } - - // TODO: use GeneratorRegistry instead? - public enum GeneratorFactory - { - FLORA, DOUBLE_FLORA, GRASS, ORE_CLUSTER, ORE_SINGLE, WATERSIDE, BASIC_TREE, BIG_TREE, BUSH; - - public static IGenerator create(IConfigObj conf) - { - GeneratorStage stage = conf.getEnum("stage", GeneratorStage.class); - GeneratorFactory factory = conf.getEnum("type", GeneratorFactory.class); - if (stage == null || factory == null) {return null;} - IGenerator generator = factory.create(); - generator.setStage(stage); - generator.configure(conf); - return generator; - } - - public IGenerator create() - { - switch (this) - { - case FLORA: - return new GeneratorFlora(); - case DOUBLE_FLORA: - return new GeneratorDoubleFlora(); - case GRASS: - return new GeneratorGrass(); - case ORE_CLUSTER: - return new GeneratorOreCluster(); - case ORE_SINGLE: - return new GeneratorOreSingle(); - case WATERSIDE: - return new GeneratorWaterside(); - case BASIC_TREE: - return new GeneratorBasicTree(); - case BIG_TREE: - return new GeneratorBigTree(); - case BUSH: - return new GeneratorBush(); - default: - return null; - } - } - - } } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java b/src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java index 2f7306b10..cb28058cb 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java @@ -10,7 +10,6 @@ package biomesoplenty.api.biome.generation; import biomesoplenty.common.util.config.BOPConfig.IConfigObj; -// TODO - scrap this? public abstract class GeneratorCustomizable implements IGenerator { private final String identifier; diff --git a/src/main/java/biomesoplenty/api/biome/generation/GeneratorRegistry.java b/src/main/java/biomesoplenty/api/biome/generation/GeneratorRegistry.java index 405dc0aa7..99161e0f2 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GeneratorRegistry.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GeneratorRegistry.java @@ -8,6 +8,8 @@ package biomesoplenty.api.biome.generation; +import biomesoplenty.common.util.config.BOPConfig.IConfigObj; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -34,4 +36,27 @@ public class GeneratorRegistry { return generatorClasses.containsValue(identifier); } + + public static IGenerator createGenerator(IConfigObj conf) + { + GeneratorStage stage = conf.getEnum("stage", GeneratorStage.class); + String identifier = conf.getString("type"); + if (stage == null || identifier == null) {return null;} + Class clazz = getGeneratorClass(identifier); + if (clazz == null) + { + conf.addMessage("No generator is registered with type name " + identifier); + return null; + } + IGenerator generator; + try { + generator = clazz.newInstance(); + } catch (Exception e) { + conf.addMessage("Failed to create instance of generator " + identifier + " - " + e.getMessage()); + return null; + } + generator.setStage(stage); + generator.configure(conf); + return generator; + } } diff --git a/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java b/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java index b14909eeb..f666d84a0 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java @@ -14,7 +14,6 @@ import java.util.Random; import net.minecraft.util.BlockPos; import net.minecraft.world.World; -import biomesoplenty.api.biome.generation.GenerationManager.GeneratorFactory; import biomesoplenty.common.util.config.BOPConfig.IConfigObj; public class GeneratorWeighted extends GeneratorCustomizable @@ -133,7 +132,7 @@ public class GeneratorWeighted extends GeneratorCustomizable { // there was previously no generator of this name - attempt to add it Integer weight = conf.getInt("weight", null); - IGenerator generator = GeneratorFactory.create(conf); + IGenerator generator = GeneratorRegistry.createGenerator(conf); if (weight != null && generator != null) { this.add(name, weight, generator); diff --git a/src/main/java/biomesoplenty/common/init/ModBiomes.java b/src/main/java/biomesoplenty/common/init/ModBiomes.java index 257a5e22e..cadc80f45 100644 --- a/src/main/java/biomesoplenty/common/init/ModBiomes.java +++ b/src/main/java/biomesoplenty/common/init/ModBiomes.java @@ -97,7 +97,7 @@ public class ModBiomes // If there was a valid config file, then use it to configure the biome if (!conf.isEmpty()) {biome.configure(conf);} // log any warnings from parsing the config file - for (String msg : conf.flushMessages()) {BiomesOPlenty.logger.warn(idName+" config "+msg);} + for (String msg : conf.flushMessages()) {BiomesOPlenty.logger.warn(msg);} BiomeGenBase.getBiomeGenArray()[id] = biome;