Search in sources :

Example 1 with GlobalConfig

use of org.spongepowered.common.config.inheritable.GlobalConfig in project SpongeCommon by SpongePowered.

the class EntityActivationRange method addEntityToConfig.

public static void addEntityToConfig(final boolean autoPopulate, final ResourceLocation key, final byte activationType, final String activationTypeName) {
    final InheritableConfigHandle<GlobalConfig> globalConfig = SpongeGameConfigs.getGlobalInheritable();
    final EntityActivationRangeCategory activationConfig = globalConfig.get().entityActivationRange;
    boolean requiresSave = false;
    final Integer defaultRange = activationConfig.globalRanges.getOrDefault(activationTypeName, 32);
    Integer range = defaultRange;
    EntityActivationRangeCategory.ModSubCategory modSubCategory = activationConfig.mods.get(key.getNamespace());
    if (autoPopulate && modSubCategory == null) {
        modSubCategory = new EntityActivationRangeCategory.ModSubCategory();
        activationConfig.mods.put(key.getNamespace(), modSubCategory);
        requiresSave = true;
    }
    if (modSubCategory != null) {
        final Integer modActivationRange = modSubCategory.defaultRanges.get(activationTypeName);
        if (autoPopulate && modActivationRange == null) {
            modSubCategory.defaultRanges.put(activationTypeName, defaultRange);
            requiresSave = true;
        } else if (modActivationRange != null && modActivationRange > range) {
            range = modActivationRange;
        }
        final Integer entityActivationRange = modSubCategory.entities.get(key.getPath());
        if (autoPopulate && entityActivationRange == null) {
            modSubCategory.entities.put(key.getPath(), modSubCategory.defaultRanges.get(activationTypeName));
            requiresSave = true;
        }
        if (entityActivationRange != null && entityActivationRange > range) {
            range = entityActivationRange;
        }
    }
    // check max ranges
    final int newRange = range;
    EntityActivationRange.maxActivationRanges.compute(activationType, (k, maxRange) -> maxRange == null || newRange > maxRange ? newRange : maxRange);
    if (autoPopulate && requiresSave) {
        globalConfig.save();
    }
}
Also used : GlobalConfig(org.spongepowered.common.config.inheritable.GlobalConfig) EntityActivationRangeCategory(org.spongepowered.common.config.inheritable.EntityActivationRangeCategory)

Aggregations

EntityActivationRangeCategory (org.spongepowered.common.config.inheritable.EntityActivationRangeCategory)1 GlobalConfig (org.spongepowered.common.config.inheritable.GlobalConfig)1