Add method for getting a BlockPosQuery from the config files

This commit is contained in:
Cheeserolls 2015-06-01 20:11:24 +01:00
parent 2297888ec4
commit 629a02d9c6
8 changed files with 43 additions and 72 deletions

View file

@ -23,7 +23,10 @@ import net.minecraft.block.state.IBlockState;
import org.apache.commons.io.FileUtils;
import biomesoplenty.common.util.block.BlockQueryUtils;
import biomesoplenty.common.util.block.BlockStateUtils;
import biomesoplenty.common.util.block.BlockQueryUtils.BlockQueryParseException;
import biomesoplenty.common.util.block.BlockQueryUtils.IBlockPosQuery;
import biomesoplenty.core.BiomesOPlenty;
import com.google.gson.Gson;
@ -38,7 +41,7 @@ public class BOPConfig
public static Gson serializer = new GsonBuilder().setPrettyPrinting().create();
public static JsonParser parser = new JsonParser();
private static enum Types {BOOLEAN, STRING, INTEGER, FLOAT, BLOCKSTATE}
private static enum Types {BOOLEAN, STRING, INTEGER, FLOAT, BLOCKSTATE, BLOCKPOSQUERY}
public static boolean writeFile(File outputFile, Object obj)
{
@ -72,6 +75,7 @@ public class BOPConfig
public Integer getInt(String name, Integer defaultVal);
public Float getFloat(String name, Float defaultVal);
public IBlockState getBlockState(String name, IBlockState defaultVal);
public IBlockPosQuery getBlockPosQuery(String name, IBlockPosQuery defaultVal);
public <E extends Enum> E getEnum(String name, E defaultVal, Class<E> clazz);
// Use the methods below when you want to obtain a value from a config file which SHOULD be present
@ -81,6 +85,7 @@ public class BOPConfig
public Integer getInt(String name);
public Float getFloat(String name);
public IBlockState getBlockState(String name);
public IBlockPosQuery getBlockPosQuery(String name);
public <E extends Enum> E getEnum(String name, Class<E> clazz);
// Use the methods below when you want to obtain an array of values from a config file, if it is present, but you have a default value to use if it isn't
@ -90,6 +95,7 @@ public class BOPConfig
public ArrayList<Integer> getIntArray(String name, ArrayList<Integer> defaultVal);
public ArrayList<Float> getFloatArray(String name, ArrayList<Float> defaultVal);
public ArrayList<IBlockState> getBlockStateArray(String name, ArrayList<IBlockState> defaultVal);
public ArrayList<IBlockPosQuery> getBlockPosQueryArray(String name, ArrayList<IBlockPosQuery> defaultVal);
public <E extends Enum> ArrayList<E> getEnumArray(String name, ArrayList<E> defaultVal, Class<E> clazz);
// Use the methods below when you want to obtain an array of values from a config file which SHOULD be present
@ -99,6 +105,7 @@ public class BOPConfig
public ArrayList<Integer> getIntArray(String name);
public ArrayList<Float> getFloatArray(String name);
public ArrayList<IBlockState> getBlockStateArray(String name);
public ArrayList<IBlockPosQuery> getBlockPosQueryArray(String name);
public <E extends Enum> ArrayList<E> getEnumArray(String name, Class<E> clazz);
@ -248,6 +255,8 @@ public class BOPConfig
@Override
public IBlockState getBlockState(String name, IBlockState defaultVal) {return this.<IBlockState>get(name, defaultVal, false, Types.BLOCKSTATE);}
@Override
public IBlockPosQuery getBlockPosQuery(String name, IBlockPosQuery defaultVal) {return this.<IBlockPosQuery>get(name, defaultVal, false, Types.BLOCKPOSQUERY);}
@Override
public <E extends Enum> E getEnum(String name, E defaultVal, Class<E> clazz) {return this.getEnum(name, defaultVal, false, clazz);}
@Override
@ -261,6 +270,8 @@ public class BOPConfig
@Override
public IBlockState getBlockState(String name) {return this.<IBlockState>get(name, null, true, Types.BLOCKSTATE);}
@Override
public IBlockPosQuery getBlockPosQuery(String name) {return this.<IBlockPosQuery>get(name, null, true, Types.BLOCKPOSQUERY);}
@Override
public <E extends Enum> E getEnum(String name, Class<E> clazz) {return this.getEnum(name, null, true, clazz);}
@Override
@ -274,6 +285,8 @@ public class BOPConfig
@Override
public ArrayList<IBlockState> getBlockStateArray(String name, ArrayList<IBlockState> defaultVal) {return this.<IBlockState>getArray(name, defaultVal, false, Types.BLOCKSTATE);}
@Override
public ArrayList<IBlockPosQuery> getBlockPosQueryArray(String name, ArrayList<IBlockPosQuery> defaultVal) {return this.<IBlockPosQuery>getArray(name, defaultVal, false, Types.BLOCKPOSQUERY);}
@Override
public <E extends Enum> ArrayList<E> getEnumArray(String name, ArrayList<E> defaultVal, Class<E> clazz) {return this.getEnumArray(name, defaultVal, false, clazz);}
@Override
@ -287,6 +300,8 @@ public class BOPConfig
@Override
public ArrayList<IBlockState> getBlockStateArray(String name) {return this.<IBlockState>getArray(name, null, true, Types.BLOCKSTATE);}
@Override
public ArrayList<IBlockPosQuery> getBlockPosQueryArray(String name) {return this.<IBlockPosQuery>getArray(name, null, true, Types.BLOCKPOSQUERY);}
@Override
public <E extends Enum> ArrayList<E> getEnumArray(String name, Class<E> clazz) {return this.getEnumArray(name, null, true, clazz);}
@ -383,6 +398,8 @@ public class BOPConfig
return (T)this.asFloat(ele, extraPrefix);
case BLOCKSTATE:
return (T)this.asBlockState(ele, extraPrefix);
case BLOCKPOSQUERY:
return (T)this.asBlockPosQuery(ele, extraPrefix);
default:
return null;
}
@ -459,6 +476,23 @@ public class BOPConfig
}
}
protected IBlockPosQuery asBlockPosQuery(JsonElement ele, String extraPrefix)
{
try
{
String queryString = ele.getAsString();
try {
return BlockQueryUtils.parseQueryString(queryString);
} catch (BlockQueryParseException e) {
this.addMessage(extraPrefix, "Error parsing BlockPosQuery " + queryString + " - " + e.getMessage());
return null;
}
} catch (Exception e) {
this.addMessage(extraPrefix, "Error fetching string: " + e.getMessage());
return null;
}
}
protected IBlockState asBlockState(JsonElement ele, String extraPrefix)
{
try {

View file

@ -176,16 +176,7 @@ public class GeneratorBlobs extends BOPGeneratorBase
this.minRadius = conf.getFloat("innerRadius", this.minRadius);
this.radiusFalloff = conf.getFloat("radiusFalloff", this.radiusFalloff);
this.numBalls = conf.getInt("numBalls", this.numBalls);
String placeOnString = conf.getString("placeOn", null);
if (placeOnString != null)
{
try {
IBlockPosQuery placeOn = BlockQueryUtils.parseQueryString(placeOnString);
this.placeOn = placeOn;
} catch (BlockQueryParseException e) {
conf.addMessage("placeOn", e.getMessage());
}
}
this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn);
this.scatterYMethod = conf.getEnum("scatterYMethod", this.scatterYMethod, ScatterYMethod.class);
}

View file

@ -114,16 +114,7 @@ public class GeneratorColumns extends BOPGeneratorBase
this.minHeight = conf.getInt("minHeight", this.minHeight);
this.maxHeight = conf.getInt("maxHeight", this.maxHeight);
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
String placeOnString = conf.getString("placeOn", null);
if (placeOnString != null)
{
try {
IBlockPosQuery placeOn = BlockQueryUtils.parseQueryString(placeOnString);
this.placeOn = placeOn;
} catch (BlockQueryParseException e) {
conf.addMessage("placeOn", e.getMessage());
}
}
this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn);
}

View file

@ -300,16 +300,7 @@ public class GeneratorLakes extends BOPGeneratorBase
this.lineWith = conf.getBlockState("lineWith", this.lineWith);
this.grassBorderWith = conf.getBlockState("grassBorderWith", this.grassBorderWith);
this.frozenLiquid = conf.getBlockState("frozenLiquid", this.frozenLiquid);
String grassReplaceString = conf.getString("grassReplace", null);
if (grassReplaceString != null)
{
try {
IBlockPosQuery grassReplace = BlockQueryUtils.parseQueryString(grassReplaceString);
this.grassReplace = grassReplace;
} catch (BlockQueryParseException e) {
conf.addMessage("grassReplace", e.getMessage());
}
}
this.grassReplace = conf.getBlockPosQuery("grassReplace", this.grassReplace);
}
}

View file

@ -146,16 +146,7 @@ public class GeneratorLogs extends BOPGeneratorBase
}
this.minLength = conf.getInt("minLength", this.minLength);
this.maxLength = conf.getInt("maxLength", this.maxLength);
String placeOnString = conf.getString("placeOn", null);
if (placeOnString != null)
{
try {
IBlockPosQuery placeOn = BlockQueryUtils.parseQueryString(placeOnString);
this.placeOn = placeOn;
} catch (BlockQueryParseException e) {
conf.addMessage("placeOn", e.getMessage());
}
}
this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn);
}
}

View file

@ -105,16 +105,7 @@ public class GeneratorSplatter extends BOPGeneratorBase
this.amountPerChunk = conf.getFloat("amountPerChunk", this.amountPerChunk);
this.to = conf.getBlockState("to", this.to);
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
String placeOnString = conf.getString("placeOn", null);
if (placeOnString != null)
{
try {
IBlockPosQuery placeOn = BlockQueryUtils.parseQueryString(placeOnString);
this.placeOn = placeOn;
} catch (BlockQueryParseException e) {
conf.addMessage("placeOn", e.getMessage());
}
}
this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn);
this.scatterYMethod = conf.getEnum("scatterYMethod", this.scatterYMethod, ScatterYMethod.class);
}

View file

@ -158,16 +158,7 @@ public class GeneratorSplotches extends BOPGeneratorBase
this.amountPerChunk = conf.getFloat("amountPerChunk", this.amountPerChunk);
this.to = conf.getBlockState("to", this.to);
this.splotchSize = conf.getInt("splotchSize", this.splotchSize);
String fromString = conf.getString("from", null);
if (fromString != null)
{
try {
IBlockPosQuery from = BlockQueryUtils.parseQueryString(fromString);
this.from = from;
} catch (BlockQueryParseException e) {
conf.addMessage("from", e.getMessage());
}
}
this.from = conf.getBlockPosQuery("from", this.from);
this.scatterYMethod = conf.getEnum("scatterYMethod", this.scatterYMethod, ScatterYMethod.class);
}

View file

@ -120,16 +120,7 @@ public class GeneratorWaterside extends BOPGeneratorBase
this.amountPerChunk = conf.getFloat("amountPerChunk", this.amountPerChunk);
this.maxRadius = conf.getInt("maxRadius", this.maxRadius);
this.to = conf.getBlockState("to", this.to);
String fromString = conf.getString("from", null);
if (fromString != null)
{
try {
IBlockPosQuery from = BlockQueryUtils.parseQueryString(fromString);
this.from = from;
} catch (BlockQueryParseException e) {
conf.addMessage("from", e.getMessage());
}
}
this.from = conf.getBlockPosQuery("from", this.from);
}
}