fix ModMenu error if YACL isn't installed

This commit is contained in:
Oth3r 2024-04-04 21:53:06 -05:00
commit 890216a19a

View file

@ -21,6 +21,8 @@ public class ModMenu implements ModMenuApi {
}
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
// return null if YACL isn't installed to not throw an error
if (!yaclCheck()) return screen -> null;
return parent -> YetAnotherConfigLib.createBuilder().save(Config::save)
.title(Text.of("Sit!"))
.category(ConfigCategory.createBuilder()
@ -198,4 +200,17 @@ public class ModMenu implements ModMenuApi {
.build())
.build().generateScreen(parent);
}
/**
* check if YACL is installed by getting a class and seeing if it throws
* @return if YACL is installed
*/
public static boolean yaclCheck() {
try {
Class.forName("dev.isxander.yacl3.platform.fabric.YACLPlatformImpl");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}