|
1 | 1 | package dev.su5ed.sinytra.connectorextras.modmenu; |
2 | 2 |
|
3 | | -import com.mojang.logging.LogUtils; |
4 | | -import com.terraformersmc.modmenu.api.ConfigScreenFactory; |
5 | | -import com.terraformersmc.modmenu.api.ModMenuApi; |
6 | | -import net.fabricmc.loader.api.FabricLoader; |
7 | | -import net.minecraft.client.gui.screens.Screen; |
8 | | -import net.minecraftforge.client.ConfigScreenHandler; |
9 | | -import net.minecraftforge.client.gui.ModListScreen; |
10 | | -import net.minecraftforge.fml.ModList; |
11 | 3 | import net.minecraftforge.fml.common.Mod; |
12 | | -import org.slf4j.Logger; |
13 | | - |
14 | | -import java.util.ArrayList; |
15 | | -import java.util.HashMap; |
16 | | -import java.util.List; |
17 | | -import java.util.Map; |
18 | 4 |
|
19 | 5 | @Mod(ModMenuCompat.MODID) |
20 | 6 | public class ModMenuCompat { |
21 | 7 | public static final String MODID = "connectorextras_modmenu_bridge"; |
22 | | - private static final Logger LOGGER = LogUtils.getLogger(); |
23 | | - private static final String MODMENU_MODID = "modmenu"; |
24 | | - |
25 | | - private static boolean initialized = false; |
26 | | - |
27 | | - public static void init() { |
28 | | - if (initialized) { |
29 | | - return; |
30 | | - } |
31 | | - initialized = true; |
32 | | - |
33 | | - Map<String, ConfigScreenFactory<?>> modFactories = new HashMap<>(); |
34 | | - List<Map<String, ConfigScreenFactory<?>>> providedFactories = new ArrayList<>(); |
35 | | - FabricLoader.getInstance().getEntrypointContainers(MODMENU_MODID, ModMenuApi.class).forEach(container -> { |
36 | | - String modId = container.getProvider().getMetadata().getId(); |
37 | | - try { |
38 | | - ModMenuApi entry = container.getEntrypoint(); |
39 | | - modFactories.put(modId, entry.getModConfigScreenFactory()); |
40 | | - providedFactories.add(entry.getProvidedConfigScreenFactories()); |
41 | | - } catch (Throwable t) { |
42 | | - LOGGER.error("Failed to load ModMenuApi entrypoint for {}", modId, t); |
43 | | - } |
44 | | - }); |
45 | | - |
46 | | - providedFactories.forEach(map -> map.forEach(modFactories::putIfAbsent)); |
47 | | - providedFactories.clear(); |
48 | 8 |
|
49 | | - Screen dummyParent = new ModListScreen(null); |
50 | | - modFactories.forEach((modId, factory) -> { |
51 | | - // Ensure factory is active. This is required to avoid cases where the integration conditionally |
52 | | - // disables itself (e.g. when cloth config is absent) and returns a dummy factory. |
53 | | - try { |
54 | | - if (factory.create(dummyParent) == null) { |
55 | | - return; |
56 | | - } |
57 | | - } catch (Throwable t) { |
58 | | - // If an error occurs, it might be due to us creating the factory so early. |
59 | | - // Since we can't be sure about the factory's status, continue ahead |
60 | | - LOGGER.warn("Error testing config screen factory status for mod {}", modId, t); |
61 | | - } |
| 9 | + public ModMenuCompat() { |
62 | 10 |
|
63 | | - ModList.get().getModContainerById(modId).ifPresent(fmlContainer -> |
64 | | - fmlContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, |
65 | | - () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> factory.create(screen)))); |
66 | | - }); |
67 | 11 | } |
68 | 12 | } |
0 commit comments