Re-added errors for properties using default value (as log spam this time), fixed some errors not showing during json parsing
This commit is contained in:
parent
1e6d27672e
commit
9873b7ad56
6 changed files with 57 additions and 33 deletions
|
@ -72,18 +72,18 @@ public abstract class BOPBiome extends Biome implements IExtendedBiome
|
|||
if (conf.isEmpty())
|
||||
return defaultBuilder.build();
|
||||
|
||||
defaultBuilder.withTemperature(conf.getFloat("temperature"));
|
||||
defaultBuilder.withRainfall(conf.getFloat("rainfall"));
|
||||
defaultBuilder.withWaterColor(conf.getInt("waterColor"));
|
||||
defaultBuilder.withTemperature(conf.getFloat("temperature", defaultBuilder.temperature));
|
||||
defaultBuilder.withRainfall(conf.getFloat("rainfall", defaultBuilder.rainfall));
|
||||
defaultBuilder.withWaterColor(conf.getInt("waterColor", defaultBuilder.waterColor));
|
||||
|
||||
Boolean enableRain = conf.getBool("enableRain");
|
||||
Boolean enableRain = conf.getBool("enableRain", defaultBuilder.enableRain);
|
||||
if (enableRain != null && !enableRain) defaultBuilder.withRainDisabled();
|
||||
|
||||
Boolean enableSnow = conf.getBool("enableSnow");
|
||||
Boolean enableSnow = conf.getBool("enableSnow", defaultBuilder.enableSnow);
|
||||
if (enableSnow != null && enableSnow) defaultBuilder.withSnowEnabled();
|
||||
|
||||
defaultBuilder.withBaseBiome(conf.getString("baseBiome"));
|
||||
defaultBuilder.withGuiColour(conf.getInt("guiColour"));
|
||||
defaultBuilder.withBaseBiome(conf.getString("baseBiome", defaultBuilder.baseBiomeRegName));
|
||||
defaultBuilder.withGuiColour(conf.getInt("guiColour", defaultBuilder.guiColour));
|
||||
|
||||
return defaultBuilder.build();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import biomesoplenty.common.init.ModBiomes;
|
|||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
import biomesoplenty.common.world.generator.GeneratorHive;
|
||||
import biomesoplenty.common.world.generator.GeneratorSplatter;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
|
@ -72,6 +73,9 @@ public class BOPHellBiome extends BOPBiome
|
|||
this.roofTopBlock = conf.getBlockState("roofTopBlock", this.roofTopBlock);
|
||||
this.roofFillerBlock = conf.getBlockState("roofFillerBlock", this.roofFillerBlock);
|
||||
|
||||
// log any warnings from parsing the config file
|
||||
for (String msg : conf.flushMessages())
|
||||
BiomesOPlenty.logger.info(msg);
|
||||
// write default values to a file
|
||||
ModBiomes.writeDefaultConfigFile(ModBiomes.BOP_DEFAULTS_DIR, this.getResourceLocation().getResourcePath(), conf);
|
||||
}
|
||||
|
|
|
@ -119,6 +119,9 @@ public class BOPOverworldBiome extends BOPBiome
|
|||
|
||||
this.beachBiomeLocation = conf.getResourceLocation("beachBiomeLocation", this.beachBiomeLocation);
|
||||
|
||||
// log any warnings from parsing the config file
|
||||
for (String msg : conf.flushMessages())
|
||||
BiomesOPlenty.logger.info(msg);
|
||||
// write default values to a file
|
||||
ModBiomes.writeDefaultConfigFile(ModBiomes.BOP_DEFAULTS_DIR, this.getResourceLocation().getResourcePath(), conf);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import biomesoplenty.common.util.block.BlockQuery;
|
|||
import biomesoplenty.common.world.GenerationManager;
|
||||
import biomesoplenty.common.world.generator.GeneratorColumns;
|
||||
import biomesoplenty.common.world.generator.GeneratorFlora;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
@ -67,6 +68,9 @@ public class ExtendedBiomeWrapper implements IExtendedBiome
|
|||
IConfigObj confGenerators = conf.getObject("generators");
|
||||
this.generationManager.configure(confGenerators);
|
||||
|
||||
// log any warnings from parsing the config file
|
||||
for (String msg : conf.flushMessages())
|
||||
BiomesOPlenty.logger.info(msg);
|
||||
// write default values to a file
|
||||
ModBiomes.writeDefaultConfigFile(ModBiomes.VANILLA_DEFAULTS_DIR, this.getResourceLocation().getResourcePath(), conf);
|
||||
}
|
||||
|
|
|
@ -540,10 +540,7 @@ public class ModBiomes implements BOPBiomes.IBiomeRegistry
|
|||
public static IConfigObj readConfigFile(String idName)
|
||||
{
|
||||
File configFile = new File(new File(BiomesOPlenty.configDirectory, "biomes"), idName + ".json");
|
||||
IConfigObj conf = new BOPConfig.ConfigFileObj(configFile);
|
||||
|
||||
// log any warnings from parsing the config file
|
||||
for (String msg : conf.flushMessages()) {BiomesOPlenty.logger.info(msg);}
|
||||
IConfigObj conf = new BOPConfig.ConfigFileObj(configFile, false, true);
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
|
|
@ -58,11 +58,13 @@ public class BOPConfig
|
|||
protected Map<String, ConfigChildObj> childObjs;
|
||||
protected List<String> messages = new ArrayList<String>();
|
||||
protected String prefix = "";
|
||||
protected boolean warnIfDefault;
|
||||
|
||||
private ConfigObjBase()
|
||||
private ConfigObjBase(boolean warnIfDefault)
|
||||
{
|
||||
this.defaults = Maps.newHashMap();
|
||||
this.childObjs = Maps.newHashMap();
|
||||
this.warnIfDefault = warnIfDefault;
|
||||
}
|
||||
|
||||
public void parse(String jsonString)
|
||||
|
@ -155,13 +157,7 @@ public class BOPConfig
|
|||
@Override
|
||||
public IConfigObj getObject(String name, boolean warnIfMissing)
|
||||
{
|
||||
if (!this.has(name))
|
||||
{
|
||||
if (warnIfMissing)
|
||||
{
|
||||
this.addMessage(name, "Error - missing value");
|
||||
}
|
||||
}
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
// attempt to return cached child first
|
||||
if (this.childObjs.containsKey(name))
|
||||
|
@ -169,16 +165,25 @@ public class BOPConfig
|
|||
return this.childObjs.get(name);
|
||||
}
|
||||
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try
|
||||
// check if the object exists and read it if it does
|
||||
if (!this.has(name))
|
||||
{
|
||||
obj = this.members.get(name).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
this.addMessage("Error fetching object " + name + ": " + e.getMessage());
|
||||
if (warnIfMissing)
|
||||
{
|
||||
this.addMessage(name, "Error - missing value");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
obj = this.members.get(name).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
this.addMessage("Error fetching object " + name + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
ConfigChildObj childObj = new ConfigChildObj(this.prefix + "." + name, obj);
|
||||
ConfigChildObj childObj = new ConfigChildObj(this.prefix + "." + name, obj, this.warnIfDefault);
|
||||
// store the child for later serialization
|
||||
this.childObjs.put(name, childObj);
|
||||
return childObj;
|
||||
|
@ -353,7 +358,12 @@ public class BOPConfig
|
|||
return defaultVal;
|
||||
}
|
||||
T out = this.<T>as(this.members.get(name), type, name);
|
||||
return out == null ? defaultVal : out;
|
||||
// warn people who try to copy-paste default configs
|
||||
if (this.warnIfDefault && out != null && out.equals(defaultVal))
|
||||
{
|
||||
this.addMessage("You can't set a property to its default value, only changed properties can be included in config files. \n Property: " + name + ", Value: " + out);
|
||||
}
|
||||
return out == null ? defaultVal : out;
|
||||
}
|
||||
|
||||
private <T> ArrayList<T> getArray(String name, ArrayList<T> defaultVal, boolean warnIfMissing, Types type)
|
||||
|
@ -586,7 +596,7 @@ public class BOPConfig
|
|||
case RESOURCELOCATION:
|
||||
return fromResourceLocation((ResourceLocation)value);
|
||||
default:
|
||||
BiomesOPlenty.logger.error("Undefined type " + type);
|
||||
this.addMessage("Undefined type " + type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -620,6 +630,7 @@ public class BOPConfig
|
|||
{
|
||||
public ConfigObj(String jsonString)
|
||||
{
|
||||
super(false);
|
||||
this.parse(jsonString);
|
||||
}
|
||||
}
|
||||
|
@ -629,11 +640,12 @@ public class BOPConfig
|
|||
{
|
||||
public ConfigFileObj(File configFile)
|
||||
{
|
||||
this(configFile, false);
|
||||
this(configFile, false, false);
|
||||
}
|
||||
|
||||
public ConfigFileObj(File configFile, boolean warnIfMissing)
|
||||
public ConfigFileObj(File configFile, boolean warnIfMissing, boolean warnIfDefault)
|
||||
{
|
||||
super(warnIfDefault);
|
||||
this.prefix = configFile.getName();
|
||||
String jsonString = null;
|
||||
if (configFile.exists())
|
||||
|
@ -658,8 +670,9 @@ public class BOPConfig
|
|||
// Concrete class for a config object which is a child of another config object
|
||||
public static class ConfigChildObj extends ConfigObjBase
|
||||
{
|
||||
protected ConfigChildObj(String prefix, JsonObject obj)
|
||||
protected ConfigChildObj(String prefix, JsonObject obj, boolean warnIfDefault)
|
||||
{
|
||||
super(warnIfDefault);
|
||||
this.prefix = prefix;
|
||||
this.members = new HashMap<String, JsonElement>();
|
||||
for (Entry<String, JsonElement> entry : obj.entrySet())
|
||||
|
@ -667,7 +680,10 @@ public class BOPConfig
|
|||
this.members.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
protected ConfigChildObj(String prefix, JsonObject obj)
|
||||
{
|
||||
this(prefix, obj, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue