diff --git a/src/main/java/fr/catcore/modremapperapi/remapping/MappingBuilder.java b/src/main/java/fr/catcore/modremapperapi/remapping/MappingBuilder.java index 5fe3ab2..d3d7f43 100644 --- a/src/main/java/fr/catcore/modremapperapi/remapping/MappingBuilder.java +++ b/src/main/java/fr/catcore/modremapperapi/remapping/MappingBuilder.java @@ -9,6 +9,8 @@ import java.util.List; public class MappingBuilder { + private static final boolean BABRIC = WhichFabricVariantAmIOn.getVariant() == FabricVariants.BABRIC || WhichFabricVariantAmIOn.getVariant() == FabricVariants.BABRIC_NEW_FORMAT; + private final String obfucated; private final String intermediary; private final List entries = new ArrayList<>(); @@ -69,8 +71,8 @@ public List build() { } public void accept(MappingVisitor visitor) throws IOException { - visitor.visitClass(obfucated); - visitor.visitDstName(MappedElementKind.CLASS, 0, this.intermediary); + visitor.visitClass(BABRIC ? intermediary : obfucated); + visitor.visitDstName(MappedElementKind.CLASS, 0, BABRIC ? obfucated : this.intermediary); for (Entry entry : this.entries) { entry.accept(visitor); @@ -99,10 +101,10 @@ public String toString(String className) { } public void accept(MappingVisitor visitor) throws IOException { - if (type == Type.FIELD) visitor.visitField(obfuscated, description); - else visitor.visitMethod(obfuscated, description); + if (type == Type.FIELD) visitor.visitField(BABRIC ? intermediary : obfuscated, description); + else visitor.visitMethod(BABRIC ? intermediary : obfuscated, description); - visitor.visitDstName(type == Type.FIELD ? MappedElementKind.FIELD : MappedElementKind.METHOD, 0, intermediary); + visitor.visitDstName(type == Type.FIELD ? MappedElementKind.FIELD : MappedElementKind.METHOD, 0, BABRIC ? obfuscated : intermediary); } } diff --git a/src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java b/src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java index ad4954f..8daf49c 100644 --- a/src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java +++ b/src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java @@ -6,6 +6,8 @@ import fr.catcore.modremapperapi.utils.Constants; import fr.catcore.modremapperapi.utils.FileUtils; import fr.catcore.modremapperapi.utils.MappingsUtils; +import fr.catcore.wfvaio.FabricVariants; +import fr.catcore.wfvaio.WhichFabricVariantAmIOn; import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl; import io.github.fabriccompatibiltylayers.modremappingapi.impl.VisitorInfosImpl; @@ -13,6 +15,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.mappingio.MappingVisitor; import net.fabricmc.mappingio.MappingWriter; +import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch; import net.fabricmc.mappingio.format.MappingFormat; import net.fabricmc.mappingio.tree.MappingTree; import net.fabricmc.mappingio.tree.MemoryMappingTree; @@ -32,6 +35,7 @@ import java.util.zip.ZipInputStream; public class RemapUtil { + private static final boolean BABRIC = WhichFabricVariantAmIOn.getVariant() == FabricVariants.BABRIC || WhichFabricVariantAmIOn.getVariant() == FabricVariants.BABRIC_NEW_FORMAT; private static MappingTree LOADER_TREE; private static MappingTree MINECRAFT_TREE; private static MappingTree MODS_TREE; @@ -226,7 +230,11 @@ private static MappingTree generateMappings() { MemoryMappingTree mappingTree = new MemoryMappingTree(); try { - MappingsUtilsImpl.initializeMappingTree(mappingTree); + if (BABRIC) { + MappingsUtilsImpl.initializeMappingTree(mappingTree, "intermediary", "official"); + } else { + MappingsUtilsImpl.initializeMappingTree(mappingTree); + } MappingList mappingList = new MappingList(); @@ -240,6 +248,14 @@ private static MappingTree generateMappings() { MappingWriter mappingWriter = MappingWriter.create(Constants.EXTRA_MAPPINGS_FILE.toPath(), MappingFormat.TINY_2_FILE); mappingTree.accept(mappingWriter); + + if (Objects.equals(mappingTree.getSrcNamespace(), "intermediary")) { + MemoryMappingTree newTree = new MemoryMappingTree(); + MappingVisitor visitor = new MappingSourceNsSwitch(newTree, "official"); + + mappingTree.accept(visitor); + mappingTree = newTree; + } } catch (IOException e) { throw new RuntimeException("Error while generating remappers mappings", e); } 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 1cda861..51a3641 100644 --- a/src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java +++ b/src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java @@ -149,7 +149,6 @@ private static void adaptVanillaMappings() { VANILLA_MAPPINGS.accept(visitor); } catch (IOException e) { e.printStackTrace(); -// throw new RuntimeException(e); } } @@ -182,16 +181,21 @@ public static IMappingProvider createProvider(MappingTree mappings, String from, @ApiStatus.Internal public static void initializeMappingTree(MappingVisitor mappingVisitor) throws IOException { + initializeMappingTree(mappingVisitor, "official", "intermediary"); + } + + @ApiStatus.Internal + public static void initializeMappingTree(MappingVisitor mappingVisitor, String src, String target) throws IOException { mappingVisitor.visitHeader(); List namespaces = new ArrayList<>(); - namespaces.add("intermediary"); + namespaces.add(src); if (getMinecraftMappings().getDstNamespaces().contains("named")) { namespaces.add("named"); } - mappingVisitor.visitNamespaces("official", namespaces); + mappingVisitor.visitNamespaces(target, namespaces); } @ApiStatus.Internal