From 26a9ccb317df921e33e53c307c3c10e3c541dc5a Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 1 Jun 2024 21:22:34 +0200 Subject: [PATCH] small code clean up --- .../modremapperapi/utils/MappingsUtils.java | 32 +++++++++++-------- .../impl/MappingsUtilsImpl.java | 7 +++- .../modremappingapi/test/TestModRemapper.java | 1 - 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/catcore/modremapperapi/utils/MappingsUtils.java b/src/main/java/fr/catcore/modremapperapi/utils/MappingsUtils.java index 11051aa..de45be8 100644 --- a/src/main/java/fr/catcore/modremapperapi/utils/MappingsUtils.java +++ b/src/main/java/fr/catcore/modremapperapi/utils/MappingsUtils.java @@ -116,17 +116,18 @@ public static void addMinecraftJar(TinyRemapper remapper) throws IOException { "intermediary", "official" ); + + if (!MappingsUtilsImpl.isSourceNamespaceObf()) { + classPath = getMinecraftJar( + Arrays.asList( + classPath + ), + "official", + MappingsUtilsImpl.getSourceNamespace() + ); + } - remapper.readClassPathAsync( - !Objects.equals(MappingsUtilsImpl.getSourceNamespace(), "official") ? - getMinecraftJar( - Arrays.asList( - classPath - ), - "official", - MappingsUtilsImpl.getSourceNamespace() - ) : classPath - ); + remapper.readClassPathAsync(classPath); } catch (IOException e) { throw new RuntimeException("Failed to populate default remap classpath", e); } @@ -160,11 +161,14 @@ public static void addMinecraftJar(TinyRemapper remapper) throws IOException { Object realmsJar = share.get("fabric-loader:inputRealmsJar"); if (realmsJar instanceof Path) list.add((Path) realmsJar); + + Path[] classPath = list.toArray(new Path[0]); + + if (!MappingsUtilsImpl.isSourceNamespaceObf()) { + classPath = getMinecraftJar(list, "official", MappingsUtilsImpl.getSourceNamespace()); + } - for (Path path : - !Objects.equals(MappingsUtilsImpl.getSourceNamespace(), "official") ? - getMinecraftJar(list, "official", MappingsUtilsImpl.getSourceNamespace()) - : list.toArray(new Path[0])) { + for (Path path : classPath) { Constants.MAIN_LOGGER.debug("Appending '%s' to remapper classpath", path); remapper.readClassPathAsync(path); } diff --git a/src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java b/src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java index ef15af3..58922be 100644 --- a/src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java +++ b/src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java @@ -1,6 +1,7 @@ package io.github.fabriccompatibiltylayers.modremappingapi.impl; import fr.catcore.modremapperapi.utils.Constants; +import fr.catcore.modremapperapi.utils.MappingsUtils; import fr.catcore.wfvaio.WhichFabricVariantAmIOn; import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.MappingTreeHelper; @@ -85,6 +86,10 @@ public static void loadExtraMappings(InputStream stream) { } } + public static boolean isSourceNamespaceObf() { + return Objects.equals(sourceNamespace, "official"); + } + @ApiStatus.Internal public static MemoryMappingTree loadMappings(InputStream stream) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { @@ -220,7 +225,7 @@ public static IMappingProvider createProvider(MappingTree mappings, String from, @ApiStatus.Internal public static void initializeMappingTree(MappingVisitor mappingVisitor) throws IOException { - initializeMappingTree(mappingVisitor, getSourceNamespace(), "intermediary"); + initializeMappingTree(mappingVisitor, getSourceNamespace(), MappingsUtils.getTargetNamespace()); } @ApiStatus.Internal diff --git a/src/test/java/io/github/fabriccompatibiltylayers/modremappingapi/test/TestModRemapper.java b/src/test/java/io/github/fabriccompatibiltylayers/modremappingapi/test/TestModRemapper.java index 8cfd68d..762b11b 100644 --- a/src/test/java/io/github/fabriccompatibiltylayers/modremappingapi/test/TestModRemapper.java +++ b/src/test/java/io/github/fabriccompatibiltylayers/modremappingapi/test/TestModRemapper.java @@ -9,7 +9,6 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files;