Skip to content

Commit

Permalink
Don't run mappings clearer on FL 0.15+, it's not needed
Browse files Browse the repository at this point in the history
Related: #329
  • Loading branch information
embeddedt committed Jan 30, 2024
1 parent 20c0f3d commit 2c96388
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.embeddedt.modernfix.fabric.mappings;

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.MappingResolver;
import net.fabricmc.loader.api.*;
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
import net.fabricmc.loader.impl.launch.MappingConfiguration;
import net.fabricmc.mapping.tree.TinyMappingFactory;
Expand All @@ -10,16 +9,34 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Optional;

/**
* Designed for Fabric Loader 0.14.x, probably has issues on other versions. The entire thing is wrapped in a try-catch
* so it should never cause crashes, just fail to work.
*/
public class MappingsClearer {
private static final Version LOADER_015;

static {
try {
LOADER_015 = Version.parse("0.15.0");
} catch (VersionParsingException e) {
throw new RuntimeException(e);
}
}

@SuppressWarnings("unchecked")
public static void clear() {
if(FabricLoader.getInstance().isDevelopmentEnvironment())
return; // never do this in dev

Optional<Version> loaderVersion = FabricLoader.getInstance().getModContainer("fabricloader").map(m -> m.getMetadata().getVersion());
if(!loaderVersion.isPresent() || LOADER_015.compareTo(loaderVersion.get()) < 0) {
// Fabric Loader is probably too new, abort
return;
}

CommonModUtil.runWithoutCrash(() -> {
// For now, force the mapping resolver to be initialized. Fabric Loader 0.14.23 stops initializing it early,
// which means that we actually need to keep the TinyMappingFactory tree around for initialization to work
Expand Down

0 comments on commit 2c96388

Please sign in to comment.