Skip to content

Commit

Permalink
Bump min forge version to 36.0.53 and mark our list configs as allowi…
Browse files Browse the repository at this point in the history
…ng empty lists and streamline how we create resource location lists and validate their elements
  • Loading branch information
pupnewfster committed Mar 12, 2021
1 parent 9461455 commit d01da44
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ minecraft_version=1.16.5
mappings_version=20210310-1.16.5
mappings_channel=mojWparam
loader_version_range=[36,)
forge_version=36.0.52
forge_version=36.0.53
mod_version=10.0.21
#This determines the minimum version of forge required to use Mekanism
# Only bump it whenever we need access to a feature in forge that is not available in earlier versions
forge_version_range=[36.0.45,)
forge_version_range=[36.0.53,)
minecraft_version_range=[1.16.5]
#This specifies what type of release it will be uploaded to curseforge as
# options are: alpha, beta, release
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mekanism.additions.common.config;

import java.util.ArrayList;
import java.util.Locale;
import mekanism.additions.common.registries.AdditionsEntityTypes;
import mekanism.api.providers.IEntityTypeProvider;
import mekanism.common.config.BaseMekanismConfig;
Expand All @@ -10,7 +8,6 @@
import mekanism.common.config.value.CachedDoubleValue;
import mekanism.common.config.value.CachedResourceLocationListValue;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.config.ModConfig.Type;
import net.minecraftforge.registries.ForgeRegistries;
Expand Down Expand Up @@ -89,28 +86,10 @@ private SpawnConfig(IMekanismConfig config, ForgeConfigSpec.Builder builder, Str
this.maxSpawnCostPercentage = CachedDoubleValue.wrap(config, builder.comment("The multiplier for max spawn cost of " + name + " spawns, compared to the adult mob.")
.worldRestart()
.defineInRange("maxSpawnCostPercentage", 1D, 0, 100));
this.biomeBlackList = CachedResourceLocationListValue.wrap(config, builder.comment("The list of biome ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
.worldRestart()
.defineList("biomeBlackList", new ArrayList<>(), o -> {
if (o instanceof String) {
ResourceLocation rl = ResourceLocation.tryParse(((String) o).toLowerCase(Locale.ROOT));
if (rl != null) {
return ForgeRegistries.BIOMES.containsKey(rl);
}
}
return false;
}));
this.structureBlackList = CachedResourceLocationListValue.wrap(config, builder.comment("The list of structure ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
.worldRestart()
.defineList("structureBlackList", new ArrayList<>(), o -> {
if (o instanceof String) {
ResourceLocation rl = ResourceLocation.tryParse(((String) o).toLowerCase(Locale.ROOT));
if (rl != null) {
return ForgeRegistries.STRUCTURE_FEATURES.containsKey(rl);
}
}
return false;
}));
this.biomeBlackList = CachedResourceLocationListValue.define(config, builder.comment("The list of biome ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
.worldRestart(), "biomeBlackList", ForgeRegistries.BIOMES::containsKey);
this.structureBlackList = CachedResourceLocationListValue.define(config, builder.comment("The list of structure ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
.worldRestart(), "structureBlackList", ForgeRegistries.STRUCTURE_FEATURES::containsKey);
builder.pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mekanism.generators.common.config;

import java.util.ArrayList;
import java.util.Locale;
import mekanism.api.math.FloatingLong;
import mekanism.common.config.BaseMekanismConfig;
import mekanism.common.config.value.CachedBooleanValue;
Expand All @@ -10,7 +8,6 @@
import mekanism.common.config.value.CachedIntValue;
import mekanism.common.config.value.CachedLongValue;
import mekanism.common.config.value.CachedResourceLocationListValue;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.config.ModConfig.Type;

Expand Down Expand Up @@ -106,9 +103,9 @@ public class GeneratorsConfig extends BaseMekanismConfig {
//TODO: Also see if we can somehow check world.getHeight()
windGenerationMaxY = CachedIntValue.wrap(this, builder.comment("The maximum Y value that affects the Wind Generators Power generation.")
.define("windGenerationMaxY", 255, value -> value instanceof Integer && (Integer) value > windGenerationMinY.get()));
//Note: Unlike in 1.15 we don't verify the dimension exists as dimensions are a lot more dynamic now
windGenerationDimBlacklist = CachedResourceLocationListValue.wrap(this, builder.comment("The list of dimension ids that the Wind Generator will not generate power in.")
.defineList("windGenerationDimBlacklist", new ArrayList<>(), o -> o instanceof String && ResourceLocation.tryParse(((String) o).toLowerCase(Locale.ROOT)) != null));
//Note: We cannot verify the dimension exists as dimensions are dynamic so may not actually exist when we are validating
windGenerationDimBlacklist = CachedResourceLocationListValue.define(this, builder.comment("The list of dimension ids that the Wind Generator will not generate power in."),
"windGenerationDimBlacklist", rl -> true);
builder.pop();

builder.comment("Fusion Settings").push(FUSION_CATEGORY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
package mekanism.common.config.value;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import mekanism.api.annotations.NonNull;
import mekanism.common.config.IMekanismConfig;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;

public class CachedResourceLocationListValue extends CachedResolvableConfigValue<List<ResourceLocation>, List<? extends String>> {

private static final Supplier<List<? extends String>> EMPTY = ArrayList::new;

private CachedResourceLocationListValue(IMekanismConfig config, ConfigValue<List<? extends String>> internal) {
super(config, internal);
}

public static CachedResourceLocationListValue wrap(IMekanismConfig config, ConfigValue<List<? extends String>> internal) {
return new CachedResourceLocationListValue(config, internal);
public static CachedResourceLocationListValue define(IMekanismConfig config, ForgeConfigSpec.Builder builder, String path,
Predicate<@NonNull ResourceLocation> rlValidator) {
return new CachedResourceLocationListValue(config, builder.defineListAllowEmpty(Collections.singletonList(path), EMPTY, o -> {
if (o instanceof String) {
ResourceLocation rl = ResourceLocation.tryParse(((String) o).toLowerCase(Locale.ROOT));
if (rl != null) {
return rlValidator.test(rl);
}
}
return false;
}));
}

@Override
Expand Down

0 comments on commit d01da44

Please sign in to comment.