|
1 | 1 | package amerifrance.guideapi;
|
2 | 2 |
|
3 | 3 |
|
| 4 | +import amerifrance.guideapi.api.GuideAPI; |
| 5 | +import amerifrance.guideapi.api.impl.Book; |
| 6 | +import com.electronwill.nightconfig.core.CommentedConfig; |
| 7 | +import com.google.common.collect.Maps; |
4 | 8 | import net.minecraftforge.common.ForgeConfigSpec;
|
| 9 | +import net.minecraftforge.fml.ModContainer; |
5 | 10 | import net.minecraftforge.fml.ModLoadingContext;
|
| 11 | +import net.minecraftforge.fml.config.ConfigFileTypeHandler; |
6 | 12 | import net.minecraftforge.fml.config.ModConfig;
|
7 | 13 | import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
8 | 14 | import org.apache.commons.lang3.tuple.Pair;
|
9 | 15 |
|
| 16 | +import java.util.HashMap; |
| 17 | +import java.util.Map; |
| 18 | + |
10 | 19 | public class GuideConfig {
|
11 |
| - /** |
12 |
| - * Synced to clients. |
13 |
| - * Only loaded on world load |
14 |
| - */ |
15 |
| - public static final Server SERVER; |
| 20 | + |
16 | 21 | /**
|
17 | 22 | * For side independent configuration. Not synced.
|
18 | 23 | * Loaded after registry events but before setup
|
19 | 24 | */
|
20 |
| - public static final Common COMMON; |
21 |
| - |
22 |
| - private static final ForgeConfigSpec serverSpec; |
23 |
| - private static final ForgeConfigSpec commonSpec; |
24 |
| - |
25 |
| - |
26 |
| - static { |
27 |
| - final Pair<Server, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Server::new); |
28 |
| - serverSpec = specPair.getRight(); |
29 |
| - SERVER = specPair.getLeft(); |
30 |
| - } |
31 |
| - |
32 |
| - static { |
33 |
| - final Pair<Common, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Common::new); |
34 |
| - commonSpec = specPair.getRight(); |
35 |
| - COMMON = specPair.getLeft(); |
36 |
| - } |
37 |
| - |
38 |
| - public static void registerConfigs() { |
39 |
| - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, commonSpec); |
40 |
| - ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, serverSpec); |
41 |
| - FMLJavaModLoadingContext.get().getModEventBus().register(GuideConfig.class); |
42 |
| - } |
| 25 | + public static Common COMMON; |
43 | 26 |
|
44 |
| - public static class Server { |
| 27 | + public static class Common { |
45 | 28 |
|
46 | 29 | public final ForgeConfigSpec.BooleanValue canSpawnWithBook;
|
47 | 30 |
|
48 |
| - Server(ForgeConfigSpec.Builder builder) { |
49 |
| - builder.comment("Server configuration settings").push("server"); |
50 |
| - canSpawnWithBook = builder.comment("Allows books to spawn with new players.\nThis is a global override for all books.").define("canSpawnWithBook",true); |
51 |
| - builder.pop(); |
52 |
| - } |
53 |
| - |
54 |
| -// for ( Book book : GuideAPI.getBooks().values()) TODO |
55 |
| -// SPAWN_BOOKS.put(book, config.getBoolean(book.getRegistryName().toString(), "Books.Spawn", book.shouldSpawnWithBook(), "")); |
56 |
| -// |
57 |
| -// config.setCategoryComment("Books.Spawn", "If true, the user will spawn with the book.\nThis defaults to the value the book owner has set and is overridden by this config."); |
58 |
| - } |
59 |
| - |
60 |
| - public static class Common { |
61 |
| - |
62 | 31 | public final ForgeConfigSpec.BooleanValue enableLogging;
|
| 32 | + public final Map<Book,ForgeConfigSpec.BooleanValue> SPAWN_BOOKS = new HashMap<>(); |
63 | 33 |
|
64 | 34 |
|
65 | 35 | Common(ForgeConfigSpec.Builder builder) {
|
66 | 36 | builder.comment("Common configurations settings").push("common");
|
67 | 37 | enableLogging = builder.comment("Enables extra information being printed to the console.").define("enableLogging",true);
|
| 38 | + canSpawnWithBook = builder.comment("Allows books to spawn with new players.\nThis is a global override for all books if set to false.").define("canSpawnWithBook",true); |
| 39 | + builder.comment("If the player should spawn with this book").push("spawnBook"); |
| 40 | + for(Book book : GuideAPI.getBooks().values()){ |
| 41 | + SPAWN_BOOKS.put(book,builder.define(book.getRegistryName().getNamespace()+"-"+book.getRegistryName().getPath(),book.shouldSpawnWithBook())); |
| 42 | + } |
| 43 | + builder.pop(); |
68 | 44 | builder.pop();
|
69 | 45 | }
|
70 | 46 | }
|
71 | 47 |
|
| 48 | + public static void buildConfiguration(){ |
| 49 | + final Pair<Common, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Common::new); |
| 50 | + ForgeConfigSpec commonSpec = specPair.getRight(); |
| 51 | + COMMON = specPair.getLeft(); |
| 52 | + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, commonSpec); |
| 53 | + FMLJavaModLoadingContext.get().getModEventBus().register(GuideConfig.class); |
| 54 | + } |
| 55 | + |
72 | 56 | }
|
0 commit comments