-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a config system using YACL
Also added Mod Menu compatibility.
- Loading branch information
1 parent
b28f4b9
commit 5f27dfc
Showing
16 changed files
with
140 additions
and
40 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
15 changes: 15 additions & 0 deletions
15
.../github/steveplays28/noisium/experimental/client/compat/modmenu/NoisiumModMenuCompat.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.steveplays28.noisium.experimental.client.compat.modmenu; | ||
|
||
import com.terraformersmc.modmenu.api.ConfigScreenFactory; | ||
import com.terraformersmc.modmenu.api.ModMenuApi; | ||
import io.github.steveplays28.noisium.experimental.config.NoisiumConfig; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class NoisiumModMenuCompat implements ModMenuApi { | ||
@Override | ||
public ConfigScreenFactory<?> getModConfigScreenFactory() { | ||
return parent -> NoisiumConfig.HANDLER.generateGui().generateScreen(parent); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
common/src/main/java/io/github/steveplays28/noisium/experimental/config/NoisiumConfig.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.steveplays28.noisium.experimental.config; | ||
|
||
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; | ||
import dev.isxander.yacl3.config.v2.api.SerialEntry; | ||
import dev.isxander.yacl3.config.v2.api.autogen.AutoGen; | ||
import dev.isxander.yacl3.config.v2.api.autogen.IntField; | ||
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder; | ||
import io.github.steveplays28.noisium.util.ModLoaderUtil; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static io.github.steveplays28.noisium.Noisium.MOD_ID; | ||
|
||
public class NoisiumConfig { | ||
public static final @NotNull String JSON_5_FILE_SUFFIX = ".json5"; | ||
public static final @NotNull ConfigClassHandler<NoisiumConfig> HANDLER = ConfigClassHandler.createBuilder(NoisiumConfig.class).id( | ||
new Identifier(MOD_ID, "config")).serializer(config -> GsonConfigSerializerBuilder.create(config).setPath( | ||
ModLoaderUtil.getConfigDir().resolve(String.format("%s/config%s", MOD_ID, JSON_5_FILE_SUFFIX))).setJson5(true).build()).build(); | ||
|
||
private static final @NotNull String SERVER_CATEGORY = "Server"; | ||
|
||
@AutoGen(category = SERVER_CATEGORY) | ||
@SerialEntry(comment = "The amount of threads used by a server world's chunk manager. Every world has its own chunk manager, and thus its own threads. After changing this option you MUST restart the server.") | ||
@IntField(min = 1, format = "%i threads") | ||
public int serverWorldChunkManagerThreads = 2; | ||
@AutoGen(category = SERVER_CATEGORY) | ||
@SerialEntry(comment = "The amount of threads used by a server world's chunk manager lighting populator. Every world has its own chunk manager, and thus its own threads. After changing this option you MUST restart the server") | ||
@IntField(min = 1, format = "%i threads") | ||
public int serverWorldChunkManagerLightingThreads = 2; | ||
} |
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
13 changes: 12 additions & 1 deletion
13
...ub/steveplays28/noisium/util/ModUtil.java → ...veplays28/noisium/util/ModLoaderUtil.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,14 +1,25 @@ | ||
package io.github.steveplays28.noisium.util; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.nio.file.Path; | ||
|
||
@SuppressWarnings("unused") | ||
public abstract class ModUtil { | ||
public abstract class ModLoaderUtil { | ||
/** | ||
* Checks if a mod is present during loading. | ||
*/ | ||
@ExpectPlatform | ||
public static boolean isModPresent(String id) { | ||
throw new AssertionError("Platform implementation expected."); | ||
} | ||
|
||
/** | ||
* @return The config directory of the mod loader. | ||
*/ | ||
@ExpectPlatform | ||
public static @NotNull Path getConfigDir() { | ||
throw new AssertionError("Platform implementation expected."); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
fabric/src/main/java/io/github/steveplays28/noisium/util/fabric/ModLoaderUtilImpl.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.steveplays28.noisium.util.fabric; | ||
|
||
import io.github.steveplays28.noisium.util.ModLoaderUtil; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* Implements {@link ModLoaderUtil}. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ModLoaderUtilImpl { | ||
/** | ||
* Checks if a mod is present during loading. | ||
*/ | ||
public static boolean isModPresent(String id) { | ||
return FabricLoader.getInstance().isModLoaded(id); | ||
} | ||
|
||
/** | ||
* @return The config directory of the mod loader. | ||
*/ | ||
public static @NotNull Path getConfigDir() { | ||
return FabricLoader.getInstance().getConfigDir(); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
fabric/src/main/java/io/github/steveplays28/noisium/util/fabric/ModUtilImpl.java
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
forge/src/main/java/io/github/steveplays28/noisium/util/forge/ModLoaderUtilImpl.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.steveplays28.noisium.util.forge; | ||
|
||
import io.github.steveplays28.noisium.util.ModLoaderUtil; | ||
import net.minecraftforge.fml.loading.FMLPaths; | ||
import net.minecraftforge.fml.loading.LoadingModList; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* Implements {@link ModLoaderUtil}. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ModLoaderUtilImpl { | ||
/** | ||
* Checks if a mod is present during loading. | ||
*/ | ||
public static boolean isModPresent(String id) { | ||
return LoadingModList.get().getModFileById(id) != null; | ||
} | ||
|
||
/** | ||
* @return The config directory of the mod loader. | ||
*/ | ||
public static @NotNull Path getConfigDir() { | ||
return FMLPaths.CONFIGDIR.get(); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
forge/src/main/java/io/github/steveplays28/noisium/util/forge/ModUtilImpl.java
This file was deleted.
Oops, something went wrong.
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