All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hendrixshen.magiclib.impl.config.ConfigEntrypoint Maven / Gradle / Ivy

There is a newer version: 0.7.398+fe2125a-beta
Show newest version
package top.hendrixshen.magiclib.impl.config;

import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.hendrixshen.magiclib.MagicLibReference;
import top.hendrixshen.magiclib.language.impl.MagicLanguageManager;
import top.hendrixshen.magiclib.malilib.impl.ConfigHandler;
import top.hendrixshen.magiclib.malilib.impl.ConfigManager;
import top.hendrixshen.magiclib.util.FabricUtil;
import top.hendrixshen.magiclib.util.ReflectUtil;

import java.util.List;
import net.minecraft.class_437;

public class ConfigEntrypoint {
    private static final boolean isMalilibLoaded = FabricUtil.isModLoaded("malilib");
    private static final int configVersion = 1;

    public static @Nullable class_437 getGui(class_437 parent) {
        if (!isMalilibLoaded) {
            return null;
        }

        Object screen = ReflectUtil.invokeDeclared("top.hendrixshen.magiclib.impl.config.MagicLibConfigGui", "getInstance", null).orElseThrow(RuntimeException::new);
        //#if MC > 11903
        //$$ ReflectUtil.invoke("top.hendrixshen.magiclib.impl.config.MagicLibConfigGui", "setParent", screen, new Class[] {Screen.class}, parent);
        //#else
        ReflectUtil.invoke("top.hendrixshen.magiclib.impl.config.MagicLibConfigGui", "setParentGui", screen, new Class[] {class_437.class}, parent);
        //#endif
        return (class_437) screen;
    }

    public static void init() {
        if (!isMalilibLoaded) {
            return;
        }

        ConfigManager cm = ConfigManager.get(MagicLibReference.getModIdentifier());
        cm.parseConfigClass(MagicLibConfigs.class);
        ConfigHandler configHandler = new ConfigHandler(MagicLibReference.getModIdentifier(), cm, configVersion);
        configHandler.postDeserializeCallback = MagicLibConfigs::postDeserialize;
        ConfigHandler.register(configHandler);
        MagicLibConfigs.init(cm);
    }

    public static @NotNull List getFallbackLanguageListFromConfig() {
        return isMalilibLoaded ? MagicLibConfigs.fallbackLanguageList : Lists.newArrayList(MagicLanguageManager.INSTANCE.getCurrentCode());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy