|
1 | 1 | package org.embeddedt.modernfix.fabric.mappings; |
2 | 2 |
|
3 | | -import net.fabricmc.loader.api.FabricLoader; |
4 | | -import net.fabricmc.loader.api.MappingResolver; |
| 3 | +import net.fabricmc.loader.api.*; |
5 | 4 | import net.fabricmc.loader.impl.launch.FabricLauncherBase; |
6 | 5 | import net.fabricmc.loader.impl.launch.MappingConfiguration; |
7 | 6 | import net.fabricmc.mapping.tree.TinyMappingFactory; |
|
10 | 9 | import java.lang.reflect.Constructor; |
11 | 10 | import java.lang.reflect.Field; |
12 | 11 | import java.util.Map; |
| 12 | +import java.util.Optional; |
13 | 13 |
|
14 | 14 | /** |
15 | 15 | * Designed for Fabric Loader 0.14.x, probably has issues on other versions. The entire thing is wrapped in a try-catch |
16 | 16 | * so it should never cause crashes, just fail to work. |
17 | 17 | */ |
18 | 18 | public class MappingsClearer { |
| 19 | + private static final Version LOADER_015; |
| 20 | + |
| 21 | + static { |
| 22 | + try { |
| 23 | + LOADER_015 = Version.parse("0.15.0"); |
| 24 | + } catch (VersionParsingException e) { |
| 25 | + throw new RuntimeException(e); |
| 26 | + } |
| 27 | + } |
| 28 | + |
19 | 29 | @SuppressWarnings("unchecked") |
20 | 30 | public static void clear() { |
21 | 31 | if(FabricLoader.getInstance().isDevelopmentEnvironment()) |
22 | 32 | return; // never do this in dev |
| 33 | + |
| 34 | + Optional<Version> loaderVersion = FabricLoader.getInstance().getModContainer("fabricloader").map(m -> m.getMetadata().getVersion()); |
| 35 | + if(!loaderVersion.isPresent() || LOADER_015.compareTo(loaderVersion.get()) < 0) { |
| 36 | + // Fabric Loader is probably too new, abort |
| 37 | + return; |
| 38 | + } |
| 39 | + |
23 | 40 | CommonModUtil.runWithoutCrash(() -> { |
24 | 41 | // For now, force the mapping resolver to be initialized. Fabric Loader 0.14.23 stops initializing it early, |
25 | 42 | // which means that we actually need to keep the TinyMappingFactory tree around for initialization to work |
|
0 commit comments