Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using forge config loader rather than manually doing it
- Loading branch information
Showing
6 changed files
with
94 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 79 additions & 74 deletions
153
src/main/java/slimeknights/tmechworks/common/config/MechworksConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,109 @@ | ||
package slimeknights.tmechworks.common.config; | ||
|
||
import com.electronwill.nightconfig.core.file.CommentedFileConfig; | ||
import net.minecraftforge.common.ForgeConfigSpec; | ||
import slimeknights.tmechworks.TMechworks; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import slimeknights.tmechworks.library.Util; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class MechworksConfig { | ||
public static final Path CONFIG_PATH = Paths.get(TMechworks.CONFIG_ROOT.toString(), "Config.toml"); | ||
public static final Common COMMON_CONFIG; | ||
public static final ForgeConfigSpec COMMON_SPEC; | ||
|
||
public static void load() { | ||
CommentedFileConfig config = CommentedFileConfig.builder(CONFIG_PATH).build(); | ||
config.load(); | ||
SPEC.setConfig(config); | ||
} | ||
public static class Common { | ||
public final WorldGeneration worldGen; | ||
public final Drawbridge drawbridge; | ||
|
||
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); | ||
private Common(ForgeConfigSpec.Builder builder) { | ||
worldGen = new WorldGeneration(builder); | ||
drawbridge = new Drawbridge(builder); | ||
} | ||
|
||
public static final WorldGeneration WORLD_GENERATION = new WorldGeneration(); | ||
public static final class WorldGeneration { | ||
public final ForgeConfigSpec.BooleanValue enabled; | ||
public static final class WorldGeneration { | ||
public final ForgeConfigSpec.BooleanValue enabled; | ||
|
||
public final Ore COPPER = new Ore("copper"); | ||
public final Ore ALUMINUM = new Ore("aluminum"); | ||
public final Ore copper; | ||
public final Ore aluminum; | ||
|
||
WorldGeneration() { | ||
BUILDER.push("world"); | ||
WorldGeneration(ForgeConfigSpec.Builder builder) { | ||
builder.comment("Everything to do with world generation").push("world"); | ||
|
||
enabled = BUILDER | ||
.comment("Whether world generation is enabled as a whole") | ||
.define("enabled", true); | ||
enabled = builder | ||
.comment("Whether world generation is enabled as a whole") | ||
.define("enabled", true); | ||
|
||
BUILDER.pop(); | ||
} | ||
copper = new Ore(builder, "copper"); | ||
aluminum = new Ore(builder, "aluminum"); | ||
|
||
public static class Ore { | ||
public ForgeConfigSpec.BooleanValue enabled; | ||
builder.pop(); | ||
} | ||
|
||
public ForgeConfigSpec.BooleanValue isWhitelist; | ||
public ForgeConfigSpec.ConfigValue<List<? extends String>> filter; | ||
public static class Ore { | ||
public ForgeConfigSpec.BooleanValue enabled; | ||
|
||
Ore(String name) { | ||
this(name, true); | ||
} | ||
public ForgeConfigSpec.BooleanValue isWhitelist; | ||
public ForgeConfigSpec.ConfigValue<List<? extends String>> filter; | ||
|
||
Ore(String name, boolean onByDefault) { | ||
this(name, onByDefault, false, Collections.emptyList()); | ||
} | ||
Ore(ForgeConfigSpec.Builder builder, String name) { | ||
this(builder, name, true); | ||
} | ||
|
||
Ore(String name, boolean onByDefault, boolean isWhitelist, List<String> filter) { | ||
BUILDER.push("world." + name); | ||
Ore(ForgeConfigSpec.Builder builder, String name, boolean onByDefault) { | ||
this(builder, name, onByDefault, false, Collections.emptyList()); | ||
} | ||
|
||
enabled = BUILDER | ||
.comment("Whether or not this ore is generated") | ||
.define("enabled", onByDefault); | ||
this.isWhitelist = BUILDER | ||
.comment("If true, the filter will act as a whitelist, otherwise, blacklist") | ||
.define("isWhitelist", isWhitelist); | ||
this.filter = BUILDER | ||
.comment("A list of fully qualified biome names, for example \"minecraft:river\"") | ||
.defineList("filter", filter, (obj) -> obj != null && Util.validateResourceName(obj.toString())); | ||
Ore(ForgeConfigSpec.Builder builder, String name, boolean onByDefault, boolean isWhitelist, List<String> filter) { | ||
builder.comment("Generation settings for " + name + " ore").push(name); | ||
|
||
BUILDER.pop(2); | ||
enabled = builder | ||
.comment("Whether or not this ore is generated") | ||
.define("enabled", onByDefault); | ||
this.isWhitelist = builder | ||
.comment("If true, the filter will act as a whitelist, otherwise, blacklist") | ||
.define("isWhitelist", isWhitelist); | ||
this.filter = builder | ||
.comment("A list of fully qualified biome names, for example \"minecraft:river\"") | ||
.defineList("filter", filter, (obj) -> obj != null && Util.validateResourceName(obj.toString())); | ||
|
||
builder.pop(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static final Drawbridge DRAWBRIDGE = new Drawbridge(); | ||
|
||
public static final class Drawbridge { | ||
public final ForgeConfigSpec.IntValue extendLength; | ||
public final ForgeConfigSpec.IntValue extendUpgradeValue; | ||
public final ForgeConfigSpec.DoubleValue delay; | ||
public final ForgeConfigSpec.DoubleValue speedUpgradeValue; | ||
|
||
Drawbridge() { | ||
BUILDER.push("drawbridge"); | ||
|
||
extendLength = BUILDER | ||
.comment("Total drawbridge distance (with upgrades) going above 66 in an advanced drawbridge may cause slots to overlap with player inventory slots") | ||
.comment("The distance that the base drawbridge can extend") | ||
.defineInRange("extendLength", 16, 1, 64); | ||
extendUpgradeValue = BUILDER | ||
.comment("How much each distance upgrade increases the max distance by") | ||
.defineInRange("extendUpgradeValue", 16, 0, 64); | ||
|
||
delay = BUILDER | ||
.comment("The base delay between each block place/destroy") | ||
.defineInRange("delay", 0.5D, 0F, Integer.MAX_VALUE); | ||
speedUpgradeValue = BUILDER | ||
.comment("The amount by which each speed upgrade decreases the delay") | ||
.defineInRange("speedUpgradeValue", 0.1D, 0F, Integer.MAX_VALUE); | ||
|
||
BUILDER.pop(); | ||
public static final class Drawbridge { | ||
public final ForgeConfigSpec.IntValue extendLength; | ||
public final ForgeConfigSpec.IntValue extendUpgradeValue; | ||
public final ForgeConfigSpec.DoubleValue delay; | ||
public final ForgeConfigSpec.DoubleValue speedUpgradeValue; | ||
|
||
Drawbridge(ForgeConfigSpec.Builder builder) { | ||
builder.comment("All the settings to do with the drawbridge").push("drawbridge"); | ||
|
||
extendLength = builder | ||
.comment("Total drawbridge distance (with upgrades) going above 66 in an advanced drawbridge may cause slots to overlap with player inventory slots") | ||
.comment("The distance that the base drawbridge can extend") | ||
.defineInRange("extendLength", 16, 1, 64); | ||
extendUpgradeValue = builder | ||
.comment("How much each distance upgrade increases the max distance by") | ||
.defineInRange("extendUpgradeValue", 16, 0, 64); | ||
|
||
delay = builder | ||
.comment("The base delay between each block place/destroy") | ||
.defineInRange("delay", 0.5D, 0F, Integer.MAX_VALUE); | ||
speedUpgradeValue = builder | ||
.comment("The amount by which each speed upgrade decreases the delay") | ||
.defineInRange("speedUpgradeValue", 0.1D, 0F, Integer.MAX_VALUE); | ||
|
||
builder.pop(); | ||
} | ||
} | ||
} | ||
|
||
private static final ForgeConfigSpec SPEC = BUILDER.build(); | ||
static { | ||
Pair<Common, ForgeConfigSpec> commonPair = new ForgeConfigSpec.Builder().configure(Common::new); | ||
|
||
COMMON_CONFIG = commonPair.getLeft(); | ||
COMMON_SPEC = commonPair.getRight(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters