use of com.mcmoddev.orespawn.api.os3.IBlockBuilder in project OreSpawn by MinecraftModDevelopmentMods.
the class OreSpawnReader method loadSingleEntry.
private static void loadSingleEntry(Entry<String, JsonElement> entry) throws UnknownFieldException, BadValueException, UnknownNameException {
ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder();
IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder();
sb.setName(entry.getKey());
for (Entry<String, JsonElement> ent : entry.getValue().getAsJsonObject().entrySet()) {
switch(ent.getKey()) {
case Constants.ConfigNames.RETROGEN:
sb.setRetrogen(ent.getValue().getAsBoolean());
break;
case Constants.ConfigNames.ENABLED:
sb.setEnabled(ent.getValue().getAsBoolean());
break;
case Constants.ConfigNames.DIMENSIONS:
IDimensionBuilder db = OreSpawn.API.getDimensionBuilder();
if (ent.getValue().isJsonArray()) {
JsonArray dims = ent.getValue().getAsJsonArray();
if (dims.size() == 0) {
// blank list, accept all overworld
db.setAcceptAllOverworld();
} else {
dims.forEach(item -> {
if (item.isJsonPrimitive() && item.getAsJsonPrimitive().isNumber()) {
db.addWhitelistEntry(item.getAsInt());
}
});
}
} else if (ent.getValue().isJsonObject()) {
loadDimensions(db, ent.getValue().getAsJsonObject());
} else {
throw new BadValueException(Constants.ConfigNames.DIMENSIONS, ent.getValue().toString());
}
sb.setDimensions(db.create());
break;
case Constants.ConfigNames.BIOMES:
if (!ent.getValue().isJsonObject()) {
throw new BadValueException(Constants.ConfigNames.BIOMES, ent.getValue().toString());
}
IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder();
loadBiomes(bb, ent.getValue().getAsJsonObject());
sb.setBiomes(bb.create());
break;
case Constants.ConfigNames.FEATURE:
if (ent.getValue().isJsonPrimitive() && !ent.getValue().getAsJsonPrimitive().isString()) {
throw new BadValueException(Constants.ConfigNames.FEATURE, ent.getValue().toString());
}
String featureName = ent.getValue().getAsString();
if (!OreSpawn.API.featureExists(featureName)) {
throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName);
}
fb.setFeature(featureName);
break;
case Constants.ConfigNames.REPLACEMENT:
if (!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) {
throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString());
} else if (ent.getValue().getAsJsonPrimitive().isString()) {
if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) {
sb.setReplacement(OreSpawn.API.getReplacement(ent.getValue().getAsString()));
}
} else {
IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder();
for (JsonElement e : ent.getValue().getAsJsonArray()) {
if (e.isJsonObject()) {
loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry);
} else {
OreSpawn.LOGGER.error("Skipping value %s in replacements list as it is not the correct format", e.toString());
}
}
sb.setReplacement(rb.create());
}
break;
case Constants.ConfigNames.BLOCK:
if (ent.getValue().isJsonArray()) {
for (JsonElement elem : ent.getValue().getAsJsonArray()) {
IBlockBuilder block = OreSpawn.API.getBlockBuilder();
if (elem.isJsonObject()) {
JsonObject bl = elem.getAsJsonObject();
if (bl.has(Constants.ConfigNames.STATE)) {
block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), bl.get(Constants.ConfigNames.STATE).getAsString(), bl.get(Constants.ConfigNames.CHANCE).getAsInt());
} else if (bl.has(Constants.ConfigNames.METADATA)) {
block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), bl.get(Constants.ConfigNames.METADATA).getAsInt(), bl.get(Constants.ConfigNames.CHANCE).getAsInt());
} else {
block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), bl.get(Constants.ConfigNames.CHANCE).getAsInt());
}
sb.addBlock(block.create());
} else {
OreSpawn.LOGGER.error("Skipping value %s in blocks list as it is not the correct format", elem.toString());
}
}
} else {
throw new BadValueException(Constants.ConfigNames.BLOCK, ent.getValue().toString());
}
case Constants.ConfigNames.PARAMETERS:
if (ent.getValue().isJsonObject()) {
ent.getValue().getAsJsonObject().entrySet().stream().forEach(e -> fb.setParameter(e.getKey(), e.getValue()));
}
break;
default:
throw new UnknownFieldException(ent.getKey());
}
}
sb.setFeature(fb.create());
OreSpawn.API.addSpawn(sb.create());
}
Aggregations