Switched biomes over to use Guava's Optional, in turn removing BiomeConfigurationHandler
This commit is contained in:
parent
35864315b9
commit
8b9080067d
6 changed files with 64 additions and 116 deletions
|
@ -8,9 +8,11 @@
|
|||
|
||||
package biomesoplenty.api.biome;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class BOPBiomes
|
||||
{
|
||||
public static BiomeGenBase alps;
|
||||
public static Optional<BiomeGenBase> alps = Optional.absent();
|
||||
}
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import biomesoplenty.common.util.config.JsonBiome;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
public class BiomeConfigurationHandler
|
||||
{
|
||||
private static Map<BiomeGenBase, String> configFileMap = new HashMap();
|
||||
|
||||
public static void init(File configDirectory)
|
||||
{
|
||||
load(configDirectory);
|
||||
}
|
||||
|
||||
private static void load(File configDirectory)
|
||||
{
|
||||
for (Entry<BiomeGenBase, String> entry : configFileMap.entrySet())
|
||||
{
|
||||
BiomeGenBase biome = entry.getKey();
|
||||
String configFileName = entry.getValue();
|
||||
File configFile = new File(configDirectory, configFileName + ".json");
|
||||
|
||||
if (configFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonBiome jsonBiome = JsonBiome.serializer.fromJson(FileUtils.readFileToString(configFile), JsonBiome.class);
|
||||
|
||||
JsonBiome.configureBiomeWithJson(biome, jsonBiome);
|
||||
}
|
||||
catch (JsonSyntaxException e)
|
||||
{
|
||||
BiomesOPlenty.logger.error("An error occurred reading " + configFile.getName(), e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtils.write(configFile, JsonBiome.serializer.toJson(JsonBiome.createFromBiomeGenBase(biome), JsonBiome.class));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void translateVanillaValues(BiomeGenBase biome)
|
||||
{
|
||||
/*IExtendedBiome extendedBiome = ExtendedBiomeRegistry.getExtension(biome);
|
||||
GenerationManager generationManager = extendedBiome.getGenerationManager();
|
||||
|
||||
if (extendedBiome.getBiomeOwner() == BiomeOwner.OTHER)
|
||||
{
|
||||
if (biome.theBiomeDecorator.cactiPerChunk > 0)
|
||||
{
|
||||
WorldGenCactus cactusGen = new WorldGenCactus();
|
||||
IExtendedCactusGen extendedCactusGen = (IExtendedCactusGen) cactusGen;
|
||||
|
||||
extendedCactusGen.setCactiPerChunk(biome.theBiomeDecorator.cactiPerChunk);
|
||||
generationManager.addGenerator("cactus", extendedCactusGen, Decorate.EventType.CACTUS);
|
||||
biome.theBiomeDecorator.cactiPerChunk = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public static Map<BiomeGenBase, String> getConfigFileMap()
|
||||
{
|
||||
return BiomeConfigurationHandler.configFileMap;
|
||||
}
|
||||
}
|
|
@ -9,11 +9,21 @@
|
|||
package biomesoplenty.common.init;
|
||||
|
||||
import static biomesoplenty.api.biome.BOPBiomes.alps;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import biomesoplenty.common.biome.ExtendedBiomeRegistry;
|
||||
import biomesoplenty.common.biome.overworld.BiomeGenAlps;
|
||||
import biomesoplenty.common.config.BiomeConfigurationHandler;
|
||||
import biomesoplenty.common.util.config.JsonBiome;
|
||||
import biomesoplenty.common.world.WorldTypeBOP;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
|
||||
public class ModBiomes
|
||||
{
|
||||
|
@ -78,20 +88,18 @@ public class ModBiomes
|
|||
registerExternalBiome(BiomeGenBase.mesaPlateau, "mesa_plateau");*/
|
||||
}
|
||||
|
||||
private static BiomeGenBase registerBiome(BiomeGenBase biome, String id)
|
||||
private static Optional<BiomeGenBase> registerBiome(BiomeGenBase biome, String id)
|
||||
{
|
||||
biome.biomeID = getNextFreeBiomeId();
|
||||
BiomeConfigurationHandler.getConfigFileMap().put(biome, id);
|
||||
|
||||
return biome;
|
||||
return loadOrCreateConfig(biome, id);
|
||||
}
|
||||
|
||||
private static void registerExternalBiome(BiomeGenBase biome, String id)
|
||||
/*private static void registerExternalBiome(BiomeGenBase biome, String id)
|
||||
{
|
||||
ExtendedBiomeRegistry.createExtension(biome);
|
||||
BiomeConfigurationHandler.translateVanillaValues(biome);
|
||||
BiomeConfigurationHandler.getConfigFileMap().put(biome, id);
|
||||
}
|
||||
}*/
|
||||
|
||||
public static int getNextFreeBiomeId()
|
||||
{
|
||||
|
@ -111,4 +119,42 @@ public class ModBiomes
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static Optional<BiomeGenBase> loadOrCreateConfig(BiomeGenBase biome, String fileName)
|
||||
{
|
||||
File configFile = new File(new File(BiomesOPlenty.configDirectory, "biomes"), fileName + ".json");
|
||||
|
||||
if (configFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonBiome jsonBiome = JsonBiome.serializer.fromJson(FileUtils.readFileToString(configFile), JsonBiome.class);
|
||||
|
||||
return JsonBiome.configureBiomeWithJson(biome, jsonBiome);
|
||||
}
|
||||
catch (JsonSyntaxException e)
|
||||
{
|
||||
BiomesOPlenty.logger.error("An error occurred reading " + configFile.getName(), e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtils.write(configFile, JsonBiome.serializer.toJson(JsonBiome.createFromBiomeGenBase(biome), JsonBiome.class));
|
||||
|
||||
return Optional.of(biome);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ package biomesoplenty.common.init;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import biomesoplenty.common.config.BiomeConfigurationHandler;
|
||||
import biomesoplenty.common.config.MiscConfigurationHandler;
|
||||
|
||||
public class ModConfiguration
|
||||
|
@ -19,9 +18,4 @@ public class ModConfiguration
|
|||
{
|
||||
MiscConfigurationHandler.init(new File(configDirectory, "misc.cfg"));
|
||||
}
|
||||
|
||||
public static void initEnd(File configDirectory)
|
||||
{
|
||||
BiomeConfigurationHandler.init(new File(configDirectory, "biomes"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import biomesoplenty.api.biome.generation.IGenerator;
|
|||
import biomesoplenty.common.biome.BOPBiomeManager;
|
||||
import biomesoplenty.common.biome.ExtendedBiomeRegistry;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -94,7 +95,7 @@ public class JsonBiome
|
|||
return biome;
|
||||
}
|
||||
|
||||
public static void configureBiomeWithJson(BiomeGenBase biome, JsonBiome jsonBiome)
|
||||
public static Optional<BiomeGenBase> configureBiomeWithJson(BiomeGenBase biome, JsonBiome jsonBiome)
|
||||
{
|
||||
IExtendedBiome extendedBiome = ExtendedBiomeRegistry.getExtension(biome);
|
||||
|
||||
|
@ -109,7 +110,7 @@ public class JsonBiome
|
|||
}
|
||||
else
|
||||
{
|
||||
biome.biomeID = -1;
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +150,10 @@ public class JsonBiome
|
|||
GenerationManager generationManager = extendedBiome.getGenerationManager();
|
||||
|
||||
generationManager.createGeneratorTable(jsonBiome.decoration);
|
||||
|
||||
return Optional.of(biome);
|
||||
}
|
||||
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ public class BiomesOPlenty
|
|||
public static CommonProxy proxy;
|
||||
|
||||
public static Logger logger = LogManager.getLogger(MOD_ID);
|
||||
|
||||
private File configDirectory;
|
||||
public static File configDirectory;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
|
@ -60,7 +59,6 @@ public class BiomesOPlenty
|
|||
ModGenerators.init();
|
||||
ModBiomes.init();
|
||||
ModHandlers.init();
|
||||
ModConfiguration.initEnd(configDirectory);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
Loading…
Reference in a new issue