Skip to content

Commit

Permalink
Update to Mapping-IO 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jan 5, 2025
1 parent e1cc6f0 commit fabd1b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ guava = "33.0.0-jre"
stitch = "0.6.2"
tiny-remapper = "0.10.4"
access-widener = "2.1.0"
mapping-io = "0.6.1"
mapping-io = "0.7.0"
lorenz-tiny = "4.0.2"
mercury = "0.4.2"
loom-native = "0.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Map;
import java.util.regex.Pattern;

import com.google.common.base.Stopwatch;
import org.jetbrains.annotations.VisibleForTesting;
Expand All @@ -42,9 +40,9 @@
import net.fabricmc.loom.configuration.providers.mappings.IntermediateMappingsService;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
import net.fabricmc.mappingio.adapter.OuterClassNamePropagator;
import net.fabricmc.mappingio.format.tiny.Tiny2FileReader;
import net.fabricmc.mappingio.format.tiny.Tiny2FileWriter;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public final class MappingsMerger {
Expand Down Expand Up @@ -77,10 +75,9 @@ public static void mergeAndSaveMappings(Path from, Path out, IntermediateMapping
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsCompleter, MappingsNamespace.OFFICIAL.toString());
intermediaryTree.accept(nsSwitch);

inheritMappedNamesOfEnclosingClasses(officialTree);

try (var writer = new Tiny2FileWriter(Files.newBufferedWriter(out, StandardCharsets.UTF_8), false)) {
officialTree.accept(writer);
var classNamePropagator = new OuterClassNamePropagator(writer);
officialTree.accept(classNamePropagator);
}
}

Expand All @@ -105,38 +102,4 @@ public static void legacyMergeAndSaveMappings(Path from, Path out, IntermediateM
officialTree.accept(writer);
}
}

/**
* Searches the mapping tree for inner classes with no mapped name, whose enclosing classes have mapped names.
* Currently, Yarn does not export mappings for these inner classes.
*/
private static void inheritMappedNamesOfEnclosingClasses(MemoryMappingTree tree) {
int intermediaryIdx = tree.getNamespaceId("intermediary");
int namedIdx = tree.getNamespaceId("named");

// The tree does not have an index by intermediary names by default
tree.setIndexByDstNames(true);

for (MappingTree.ClassMapping classEntry : tree.getClasses()) {
String intermediaryName = classEntry.getDstName(intermediaryIdx);
String namedName = classEntry.getDstName(namedIdx);

if (intermediaryName.equals(namedName) && intermediaryName.contains("$")) {
String[] path = intermediaryName.split(Pattern.quote("$"));
int parts = path.length;

for (int i = parts - 2; i >= 0; i--) {
String currentPath = String.join("$", Arrays.copyOfRange(path, 0, i + 1));
String namedParentClass = tree.mapClassName(currentPath, intermediaryIdx, namedIdx);

if (!namedParentClass.equals(currentPath)) {
classEntry.setDstName(namedParentClass
+ "$" + String.join("$", Arrays.copyOfRange(path, i + 1, path.length)),
namedIdx);
break;
}
}
}
}
}
}

0 comments on commit fabd1b3

Please sign in to comment.