-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix modmenu bridge loading client classes on server
Fixes #6
- Loading branch information
Showing
4 changed files
with
69 additions
and
60 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
58 changes: 1 addition & 57 deletions
58
modmenu-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/modmenu/ModMenuCompat.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,68 +1,12 @@ | ||
package dev.su5ed.sinytra.connectorextras.modmenu; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import com.terraformersmc.modmenu.api.ConfigScreenFactory; | ||
import com.terraformersmc.modmenu.api.ModMenuApi; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraftforge.client.ConfigScreenHandler; | ||
import net.minecraftforge.client.gui.ModListScreen; | ||
import net.minecraftforge.fml.ModList; | ||
import net.minecraftforge.fml.common.Mod; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Mod(ModMenuCompat.MODID) | ||
public class ModMenuCompat { | ||
public static final String MODID = "connectorextras_modmenu_bridge"; | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
private static final String MODMENU_MODID = "modmenu"; | ||
|
||
private static boolean initialized = false; | ||
|
||
public static void init() { | ||
if (initialized) { | ||
return; | ||
} | ||
initialized = true; | ||
|
||
Map<String, ConfigScreenFactory<?>> modFactories = new HashMap<>(); | ||
List<Map<String, ConfigScreenFactory<?>>> providedFactories = new ArrayList<>(); | ||
FabricLoader.getInstance().getEntrypointContainers(MODMENU_MODID, ModMenuApi.class).forEach(container -> { | ||
String modId = container.getProvider().getMetadata().getId(); | ||
try { | ||
ModMenuApi entry = container.getEntrypoint(); | ||
modFactories.put(modId, entry.getModConfigScreenFactory()); | ||
providedFactories.add(entry.getProvidedConfigScreenFactories()); | ||
} catch (Throwable t) { | ||
LOGGER.error("Failed to load ModMenuApi entrypoint for {}", modId, t); | ||
} | ||
}); | ||
|
||
providedFactories.forEach(map -> map.forEach(modFactories::putIfAbsent)); | ||
providedFactories.clear(); | ||
|
||
Screen dummyParent = new ModListScreen(null); | ||
modFactories.forEach((modId, factory) -> { | ||
// Ensure factory is active. This is required to avoid cases where the integration conditionally | ||
// disables itself (e.g. when cloth config is absent) and returns a dummy factory. | ||
try { | ||
if (factory.create(dummyParent) == null) { | ||
return; | ||
} | ||
} catch (Throwable t) { | ||
// If an error occurs, it might be due to us creating the factory so early. | ||
// Since we can't be sure about the factory's status, continue ahead | ||
LOGGER.warn("Error testing config screen factory status for mod {}", modId, t); | ||
} | ||
public ModMenuCompat() { | ||
|
||
ModList.get().getModContainerById(modId).ifPresent(fmlContainer -> | ||
fmlContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, | ||
() -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> factory.create(screen)))); | ||
}); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...nu-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/modmenu/ModMenuCompatSetup.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,65 @@ | ||
package dev.su5ed.sinytra.connectorextras.modmenu; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import com.terraformersmc.modmenu.api.ConfigScreenFactory; | ||
import com.terraformersmc.modmenu.api.ModMenuApi; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraftforge.client.ConfigScreenHandler; | ||
import net.minecraftforge.client.gui.ModListScreen; | ||
import net.minecraftforge.fml.ModList; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ModMenuCompatSetup { | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
private static final String MODMENU_MODID = "modmenu"; | ||
|
||
private static boolean initialized = false; | ||
|
||
public static void init() { | ||
if (initialized) { | ||
return; | ||
} | ||
initialized = true; | ||
|
||
Map<String, ConfigScreenFactory<?>> modFactories = new HashMap<>(); | ||
List<Map<String, ConfigScreenFactory<?>>> providedFactories = new ArrayList<>(); | ||
FabricLoader.getInstance().getEntrypointContainers(MODMENU_MODID, ModMenuApi.class).forEach(container -> { | ||
String modId = container.getProvider().getMetadata().getId(); | ||
try { | ||
ModMenuApi entry = container.getEntrypoint(); | ||
modFactories.put(modId, entry.getModConfigScreenFactory()); | ||
providedFactories.add(entry.getProvidedConfigScreenFactories()); | ||
} catch (Throwable t) { | ||
LOGGER.error("Failed to load ModMenuApi entrypoint for {}", modId, t); | ||
} | ||
}); | ||
|
||
providedFactories.forEach(map -> map.forEach(modFactories::putIfAbsent)); | ||
providedFactories.clear(); | ||
|
||
Screen dummyParent = new ModListScreen(null); | ||
modFactories.forEach((modId, factory) -> { | ||
// Ensure factory is active. This is required to avoid cases where the integration conditionally | ||
// disables itself (e.g. when cloth config is absent) and returns a dummy factory. | ||
try { | ||
if (factory.create(dummyParent) == null) { | ||
return; | ||
} | ||
} catch (Throwable t) { | ||
// If an error occurs, it might be due to us creating the factory so early. | ||
// Since we can't be sure about the factory's status, continue ahead | ||
LOGGER.warn("Error testing config screen factory status for mod {}", modId, t); | ||
} | ||
|
||
ModList.get().getModContainerById(modId).ifPresent(fmlContainer -> | ||
fmlContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, | ||
() -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> factory.create(screen)))); | ||
}); | ||
} | ||
} |
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