Search in sources :

Example 1 with PollinatedModConfig

use of gg.moonflower.pollen.api.config.PollinatedModConfig in project pollen by MoonflowerTeam.

the class ConfigResourceCondition method test.

@Override
public boolean test(JsonObject json) throws JsonParseException {
    ResourceLocation configId = new ResourceLocation(GsonHelper.getAsString(json, "config"));
    Optional<PollinatedModConfig> optional = ConfigManager.get(configId.getNamespace(), byName(configId.getPath()));
    if (!optional.isPresent() || optional.get().getConfigData() == null)
        return false;
    String configKey = GsonHelper.getAsString(json, "name");
    if (!json.has("value"))
        throw new JsonSyntaxException("Expected 'value'");
    Object entry = optional.get().getConfigData().get(configKey);
    if (entry == null)
        throw new JsonSyntaxException("Unknown config key: " + configKey);
    return testEntry(entry instanceof PollinatedConfigBuilder.ConfigValue<?> ? ((PollinatedConfigBuilder.ConfigValue<?>) entry).get() : entry, json, json.get("value"));
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) PollinatedModConfig(gg.moonflower.pollen.api.config.PollinatedModConfig) ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 PollinatedModConfig (gg.moonflower.pollen.api.config.PollinatedModConfig)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1