}
// TODO: move these helper functions outside core?
public static BiomeInfoSet parseBiomeRestrictions(JsonObject genObject) {
BiomeInfoSet set = null;
if (genObject.has("biomes")) {
JsonArray restrictionList = genObject.getAsJsonArray("biomes");
set = new BiomeInfoSet(restrictionList.size());
for (int i = 0, e = restrictionList.size(); i < e; i++) {
BiomeInfo info = null;
JsonElement element = restrictionList.get(i);
if (element.isJsonNull()) {
log.info("Null biome entry. Ignoring.");
} else if (element.isJsonObject()) {
JsonObject obj = element.getAsJsonObject();
String type = obj.get("type").getAsString();
boolean wl = obj.has("whitelist") ? obj.get("whitelist").getAsBoolean() : true;
JsonElement value = obj.get("entry");
JsonArray array = value.isJsonArray() ? value.getAsJsonArray() : null;
String entry = array != null ? null : value.getAsString();
int rarity = obj.has("rarity") ? obj.get("rarity").getAsInt() : -1;
l: if (type.equalsIgnoreCase("name")) {
if (array != null) {
ArrayList<String> names = new ArrayList<String>();
for (int k = 0, j = array.size(); k < j; k++) {
names.add(array.get(k).getAsString());
}
if (rarity > 0)
info = new BiomeInfoRarity(names, 4, true, rarity);
else
info = new BiomeInfo(names, 4, true);
} else {
if (rarity > 0)
info = new BiomeInfoRarity(entry, rarity);
else
info = new BiomeInfo(entry);
}
} else {
Object data = null;
int t = -1;
if (type.equalsIgnoreCase("temperature")) {
if (array != null) {
ArrayList<TempCategory> temps = new ArrayList<TempCategory>();
for (int k = 0, j = array.size(); k < j; k++) {
temps.add(TempCategory.valueOf(array.get(k).getAsString()));
}
data = EnumSet.copyOf(temps);
t = 5;
} else {
data = TempCategory.valueOf(entry);
t = 1;
}
} else if (type.equalsIgnoreCase("dictionary")) {
if (array != null) {
ArrayList<Type> tags = new ArrayList<Type>();
for (int k = 0, j = array.size(); k < j; k++) {
Type a = Type.valueOf(array.get(k).getAsString());
if (a != null)
tags.add(a);
}
data = tags.toArray(new Type[tags.size()]);
t = 6;
} else {
data = Type.valueOf(entry);
t = 2;
}
} else {
log.warn("Biome entry of unknown type");
break l;
}
if (data != null) {
if (rarity > 0)
info = new BiomeInfoRarity(data, t, wl, rarity);
else
info = new BiomeInfo(data, t, wl);
}
}
} else {
info = new BiomeInfo(element.getAsString());
}
if (info != null)
set.add(info);
}
}
return set;
}