|
5 | 5 | import com.google.gson.GsonBuilder;
|
6 | 6 | import cpw.mods.modlauncher.api.ServiceRunner;
|
7 | 7 | import dev.su5ed.sinytra.connector.locator.EmbeddedDependencies;
|
| 8 | +import net.fabricmc.loader.api.metadata.ModDependency; |
| 9 | +import net.fabricmc.loader.impl.metadata.ModDependencyImpl; |
8 | 10 | import net.minecraftforge.fml.loading.FMLPaths;
|
9 | 11 |
|
10 | 12 | import java.io.IOException;
|
11 | 13 | import java.io.UncheckedIOException;
|
12 | 14 | import java.nio.file.Files;
|
13 | 15 | import java.nio.file.Path;
|
14 | 16 | import java.util.Collection;
|
| 17 | +import java.util.List; |
| 18 | +import java.util.Map; |
15 | 19 | import java.util.Set;
|
16 | 20 | import java.util.regex.Pattern;
|
17 | 21 |
|
| 22 | +import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck; |
| 23 | + |
18 | 24 | public final class ConnectorUtil {
|
19 | 25 | public static final String MIXIN_CONFIGS_ATTRIBUTE = "MixinConfigs";
|
20 | 26 | public static final String FABRIC_MOD_JSON = "fabric.mod.json";
|
@@ -99,6 +105,11 @@ public final class ConnectorUtil {
|
99 | 105 | "null",
|
100 | 106 | "_"
|
101 | 107 | );
|
| 108 | + // Common aliased mod dependencies that don't work with forge ports, which use a different modid. |
| 109 | + // They're too annoying to override individually in each mod, so we provide this small QoL feature for the user's comfort |
| 110 | + private static final Map<String, String> GLOBAL_DEPENDENCY_OVERRIDES = Map.of( |
| 111 | + "cloth-config2", "cloth_config" |
| 112 | + ); |
102 | 113 |
|
103 | 114 | private static final boolean CACHE_ENABLED;
|
104 | 115 |
|
@@ -162,8 +173,22 @@ public static <V> V uncheckThrowable(UncheckedSupplier<V> supplier) {
|
162 | 173 | }
|
163 | 174 | }
|
164 | 175 |
|
165 |
| - public static String stripColor(String p_14407_) { |
166 |
| - return STRIP_COLOR_PATTERN.matcher(p_14407_).replaceAll(""); |
| 176 | + public static String stripColor(String str) { |
| 177 | + return str != null ? STRIP_COLOR_PATTERN.matcher(str).replaceAll("") : null; |
| 178 | + } |
| 179 | + |
| 180 | + public static List<ModDependency> applyGlobalDependencyOverrides(Collection<ModDependency> dependencies) { |
| 181 | + return dependencies.stream() |
| 182 | + .map(dependency -> { |
| 183 | + for (Map.Entry<String, String> entry : GLOBAL_DEPENDENCY_OVERRIDES.entrySet()) { |
| 184 | + String key = entry.getKey(); |
| 185 | + if (dependency.getKind() == ModDependency.Kind.DEPENDS && dependency.getModId().equals(key)) { |
| 186 | + return uncheck(() -> new ModDependencyImpl(ModDependency.Kind.DEPENDS, entry.getValue(), List.of("*"))); |
| 187 | + } |
| 188 | + } |
| 189 | + return dependency; |
| 190 | + }) |
| 191 | + .toList(); |
167 | 192 | }
|
168 | 193 |
|
169 | 194 | @FunctionalInterface
|
|
0 commit comments