mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
Allow Entries to be conditionally shown
- Define a required mod using `requiredMod = "modid"` in entries & comments
This commit is contained in:
@@ -92,7 +92,6 @@ public abstract class MidnightConfig {
|
|||||||
EntryInfo info = new EntryInfo();
|
EntryInfo info = new EntryInfo();
|
||||||
if ((field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class)) && !field.isAnnotationPresent(Server.class) && !field.isAnnotationPresent(Hidden.class) && PlatformFunctions.isClientEnv())
|
if ((field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class)) && !field.isAnnotationPresent(Server.class) && !field.isAnnotationPresent(Hidden.class) && PlatformFunctions.isClientEnv())
|
||||||
initClient(modid, field, info);
|
initClient(modid, field, info);
|
||||||
if (field.isAnnotationPresent(Comment.class)) info.centered = field.getAnnotation(Comment.class).centered();
|
|
||||||
if (field.isAnnotationPresent(Entry.class))
|
if (field.isAnnotationPresent(Entry.class))
|
||||||
try { info.defaultValue = field.get(null);
|
try { info.defaultValue = field.get(null);
|
||||||
} catch (IllegalAccessException ignored) {}
|
} catch (IllegalAccessException ignored) {}
|
||||||
@@ -111,10 +110,14 @@ public abstract class MidnightConfig {
|
|||||||
private static void initClient(String modid, Field field, EntryInfo info) {
|
private static void initClient(String modid, Field field, EntryInfo info) {
|
||||||
info.dataType = getUnderlyingType(field);
|
info.dataType = getUnderlyingType(field);
|
||||||
Entry e = field.getAnnotation(Entry.class);
|
Entry e = field.getAnnotation(Entry.class);
|
||||||
|
Comment c = field.getAnnotation(Comment.class);
|
||||||
info.width = e != null ? e.width() : 0;
|
info.width = e != null ? e.width() : 0;
|
||||||
info.field = field; info.modid = modid;
|
info.field = field; info.modid = modid;
|
||||||
|
boolean requiredModLoaded = true;
|
||||||
|
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
|
if (!e.requiredMod().isEmpty()) requiredModLoaded = PlatformFunctions.isModLoaded(e.requiredMod());
|
||||||
|
if (!requiredModLoaded) return;
|
||||||
if (!e.name().isEmpty()) info.name = Text.translatable(e.name());
|
if (!e.name().isEmpty()) info.name = Text.translatable(e.name());
|
||||||
if (info.dataType == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, (int) e.min(), (int) e.max(), true);
|
if (info.dataType == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, (int) e.min(), (int) e.max(), true);
|
||||||
else if (info.dataType == float.class) textField(info, Float::parseFloat, DECIMAL_ONLY, (float) e.min(), (float) e.max(), false);
|
else if (info.dataType == float.class) textField(info, Float::parseFloat, DECIMAL_ONLY, (float) e.min(), (float) e.max(), false);
|
||||||
@@ -132,8 +135,11 @@ public abstract class MidnightConfig {
|
|||||||
int index = values.indexOf(info.value) + 1;
|
int index = values.indexOf(info.value) + 1;
|
||||||
info.value = values.get(index >= values.size() ? 0 : index); button.setMessage(func.apply(info.value));
|
info.value = values.get(index >= values.size() ? 0 : index); button.setMessage(func.apply(info.value));
|
||||||
}, func);
|
}, func);
|
||||||
}}
|
}} else if (c != null) {
|
||||||
entries.add(info);
|
if (!c.requiredMod().isEmpty()) requiredModLoaded = PlatformFunctions.isModLoaded(c.requiredMod());
|
||||||
|
info.centered = c.centered();
|
||||||
|
}
|
||||||
|
if (requiredModLoaded) entries.add(info);
|
||||||
}
|
}
|
||||||
public static Class<?> getUnderlyingType(Field field) {
|
public static Class<?> getUnderlyingType(Field field) {
|
||||||
if (field.getType() == List.class) {
|
if (field.getType() == List.class) {
|
||||||
@@ -496,6 +502,7 @@ public abstract class MidnightConfig {
|
|||||||
boolean isSlider() default false;
|
boolean isSlider() default false;
|
||||||
int precision() default 100;
|
int precision() default 100;
|
||||||
String category() default "default";
|
String category() default "default";
|
||||||
|
String requiredMod() default "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Client {}
|
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Client {}
|
||||||
@@ -504,6 +511,7 @@ public abstract class MidnightConfig {
|
|||||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment {
|
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment {
|
||||||
boolean centered() default false;
|
boolean centered() default false;
|
||||||
String category() default "default";
|
String category() default "default";
|
||||||
|
String requiredMod() default "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HiddenAnnotationExclusionStrategy implements ExclusionStrategy {
|
public static class HiddenAnnotationExclusionStrategy implements ExclusionStrategy {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ configurations {
|
|||||||
runtimeClasspath.extendsFrom common
|
runtimeClasspath.extendsFrom common
|
||||||
developmentFabric.extendsFrom common
|
developmentFabric.extendsFrom common
|
||||||
archivesBaseName = rootProject.archives_base_name + "-fabric"
|
archivesBaseName = rootProject.archives_base_name + "-fabric"
|
||||||
|
version = rootProject.mod_version + "+" + rootProject.minecraft_version
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -33,10 +34,10 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", rootProject.version
|
||||||
|
|
||||||
filesMatching("fabric.mod.json") {
|
filesMatching("fabric.mod.json") {
|
||||||
expand "version": project.version
|
expand "version": rootProject.version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ components.java {
|
|||||||
|
|
||||||
unifiedPublishing {
|
unifiedPublishing {
|
||||||
project {
|
project {
|
||||||
displayName = "MidnightLib $project.version - Fabric $project.minecraft_version"
|
displayName = "MidnightLib $rootProject.version - Fabric $project.minecraft_version"
|
||||||
releaseType = "$project.release_type"
|
releaseType = "$project.release_type"
|
||||||
changelog = releaseChangelog()
|
changelog = releaseChangelog()
|
||||||
gameVersions = []
|
gameVersions = []
|
||||||
@@ -93,7 +94,7 @@ unifiedPublishing {
|
|||||||
modrinth {
|
modrinth {
|
||||||
token = MODRINTH_TOKEN
|
token = MODRINTH_TOKEN
|
||||||
id = rootProject.modrinth_id
|
id = rootProject.modrinth_id
|
||||||
version = "$project.version-$project.name"
|
version = "$rootProject.version-$project.name"
|
||||||
gameVersions.addAll project.minecraft_version, project.supported_versions
|
gameVersions.addAll project.minecraft_version, project.supported_versions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ configurations {
|
|||||||
canBeResolved = true
|
canBeResolved = true
|
||||||
canBeConsumed = false
|
canBeConsumed = false
|
||||||
}
|
}
|
||||||
|
archivesBaseName = rootProject.archives_base_name + "-neoforge"
|
||||||
|
version = rootProject.mod_version + "+" + rootProject.minecraft_version
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -45,10 +47,10 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property 'version', project.version
|
inputs.property 'version', rootProject.version
|
||||||
|
|
||||||
filesMatching('META-INF/neoforge.mods.toml') {
|
filesMatching('META-INF/neoforge.mods.toml') {
|
||||||
expand version: project.version
|
expand version: rootProject.version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ components.java {
|
|||||||
|
|
||||||
unifiedPublishing {
|
unifiedPublishing {
|
||||||
project {
|
project {
|
||||||
displayName = "MidnightLib $project.version - NeoForge $project.minecraft_version"
|
displayName = "MidnightLib $rootProject.version - NeoForge $project.minecraft_version"
|
||||||
releaseType = "$project.release_type"
|
releaseType = "$project.release_type"
|
||||||
changelog = releaseChangelog()
|
changelog = releaseChangelog()
|
||||||
gameVersions = []
|
gameVersions = []
|
||||||
@@ -96,7 +98,7 @@ unifiedPublishing {
|
|||||||
modrinth {
|
modrinth {
|
||||||
token = MODRINTH_TOKEN
|
token = MODRINTH_TOKEN
|
||||||
id = rootProject.modrinth_id
|
id = rootProject.modrinth_id
|
||||||
version = "$project.version-$project.name"
|
version = "$rootProject.version-$project.name"
|
||||||
gameVersions.addAll project.minecraft_version, project.supported_versions
|
gameVersions.addAll project.minecraft_version, project.supported_versions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package eu.midnightdust.neoforge;
|
|||||||
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import eu.midnightdust.core.MidnightLib;
|
import eu.midnightdust.core.MidnightLib;
|
||||||
import eu.midnightdust.lib.config.AutoCommand;
|
|
||||||
import eu.midnightdust.lib.config.MidnightConfig;
|
import eu.midnightdust.lib.config.MidnightConfig;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
@@ -16,6 +15,7 @@ import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
|||||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mod("midnightlib")
|
@Mod("midnightlib")
|
||||||
@@ -32,7 +32,7 @@ public class MidnightLibNeoForge {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPostInit(FMLClientSetupEvent event) {
|
public static void onPostInit(FMLClientSetupEvent event) {
|
||||||
ModList.get().forEachModContainer((modid, modContainer) -> {
|
ModList.get().forEachModContainer((modid, modContainer) -> {
|
||||||
if (MidnightConfig.configClass.containsKey(modid)) {
|
if (MidnightConfig.configClass.containsKey(modid) && !MidnightLib.hiddenMods.contains(modid)) {
|
||||||
modContainer.registerExtensionPoint(IConfigScreenFactory.class, (minecraftClient, screen) -> MidnightConfig.getScreen(screen, modid));
|
modContainer.registerExtensionPoint(IConfigScreenFactory.class, (minecraftClient, screen) -> MidnightConfig.getScreen(screen, modid));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -43,7 +43,10 @@ public class MidnightLibNeoForge {
|
|||||||
public static class MidnightLibEvents {
|
public static class MidnightLibEvents {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerCommands(RegisterCommandsEvent event) {
|
public static void registerCommands(RegisterCommandsEvent event) {
|
||||||
commands.forEach(command -> event.getDispatcher().register(command));
|
try {
|
||||||
|
commands.forEach(command -> event.getDispatcher().register(command));
|
||||||
|
}
|
||||||
|
catch (ConcurrentModificationException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user