2727import java .nio .file .Path ;
2828import java .nio .file .Paths ;
2929import java .util .*;
30+ import java .util .function .Supplier ;
3031import java .util .stream .Collectors ;
3132import java .util .zip .ZipEntry ;
3233import java .util .zip .ZipInputStream ;
@@ -51,18 +52,26 @@ public static void init(List<io.github.fabriccompatibiltylayers.modremappingapi.
5152 for (ModRemapper remapper : remappers ) {
5253 Optional <String > pkg = remapper .getDefaultPackage ();
5354
54- if (pkg .isPresent ()) {
55- defaultPackage = pkg .get ();
56- break ;
57- }
55+ pkg .ifPresent (s -> defaultPackage = s );
56+
57+ Optional <String > sourceNamespace = remapper .getSourceNamespace ();
58+
59+ sourceNamespace .ifPresent (MappingsUtilsImpl ::setSourceNamespace );
60+
61+ Optional <Supplier <InputStream >> mappings = remapper .getExtraMapping ();
62+
63+ mappings .ifPresent (inputStreamSupplier -> MappingsUtilsImpl .loadExtraMappings (inputStreamSupplier .get ()));
5864 }
5965
6066 MINECRAFT_TREE = MappingsUtilsImpl .getMinecraftMappings ();
67+
68+ writeMcMappings ();
69+
6170 LOADER_TREE = generateMappings ();
6271 MappingsUtilsImpl .addMappingsToContext (LOADER_TREE );
6372
6473 for (MappingTree .ClassMapping classView : MINECRAFT_TREE .getClasses ()) {
65- String className = classView .getName ("official" );
74+ String className = classView .getName (MappingsUtilsImpl . getSourceNamespace () );
6675
6776 if (className != null ) {
6877 MC_CLASS_NAMES .add (className );
@@ -131,6 +140,8 @@ public static void remapMods(Map<Path, Path> pathMap) {
131140 Constants .MAIN_LOGGER .debug ("Remapper created!" );
132141 remapFiles (remapper , pathMap );
133142 Constants .MAIN_LOGGER .debug ("Jar remapping done!" );
143+
144+ MappingsUtilsImpl .writeFullMappings ();
134145 }
135146
136147 public static List <String > makeModMappings (Path modPath ) {
@@ -190,6 +201,15 @@ public static void generateModMappings() {
190201 MappingsUtilsImpl .addMappingsToContext (MODS_TREE );
191202 }
192203
204+ public static void writeMcMappings () {
205+ try {
206+ MappingWriter writer = MappingWriter .create (Constants .MC_MAPPINGS_FILE .toPath (), MappingFormat .TINY_2_FILE );
207+ MINECRAFT_TREE .accept (writer );
208+ } catch (IOException e ) {
209+ throw new RuntimeException (e );
210+ }
211+ }
212+
193213 private static List <String > generateFolderMappings (File [] files ) {
194214 List <String > list = new ArrayList <>();
195215
@@ -504,7 +524,7 @@ private static TinyRemapper makeRemapper(MappingTree... trees) {
504524 }
505525
506526 for (MappingTree tree : trees ) {
507- builder .withMappings (MappingsUtilsImpl .createProvider (tree , "official" , MappingsUtils .getTargetNamespace ()));
527+ builder .withMappings (MappingsUtilsImpl .createProvider (tree , MappingsUtilsImpl . getSourceNamespace () , MappingsUtils .getTargetNamespace ()));
508528 }
509529
510530 MRAApplyVisitor preApplyVisitor = new MRAApplyVisitor ();
@@ -530,7 +550,11 @@ private static TinyRemapper makeRemapper(MappingTree... trees) {
530550
531551 TinyRemapper remapper = builder .build ();
532552
533- MappingsUtils .addMinecraftJar (remapper );
553+ try {
554+ MappingsUtils .addMinecraftJar (remapper );
555+ } catch (IOException e ) {
556+ throw new RuntimeException (e );
557+ }
534558
535559 for (ModRemapper modRemapper : remappers ) {
536560 List <RemapLibrary > libraries = new ArrayList <>();
@@ -562,11 +586,11 @@ private static void remapFiles(TinyRemapper remapper, Map<Path, Path> paths) {
562586 List <OutputConsumerPath .ResourceRemapper > resourceRemappers = new ArrayList <>(NonClassCopyMode .FIX_META_INF .remappers );
563587 resourceRemappers .add (new RefmapRemapper ());
564588
565- applyRemapper (remapper , paths , outputConsumerPaths , resourceRemappers );
589+ applyRemapper (remapper , paths , outputConsumerPaths , resourceRemappers , true , MappingsUtilsImpl . getSourceNamespace (), MappingsUtils . getTargetNamespace () );
566590 }
567591
568592 @ ApiStatus .Internal
569- public static void applyRemapper (TinyRemapper remapper , Map <Path , Path > paths , List <OutputConsumerPath > outputConsumerPaths , List <OutputConsumerPath .ResourceRemapper > resourceRemappers ) {
593+ public static void applyRemapper (TinyRemapper remapper , Map <Path , Path > paths , List <OutputConsumerPath > outputConsumerPaths , List <OutputConsumerPath .ResourceRemapper > resourceRemappers , boolean analyzeMapping , String srcNamespace , String targetNamespace ) {
570594 try {
571595 Map <Path , InputTag > tagMap = new HashMap <>();
572596
@@ -593,7 +617,7 @@ public static void applyRemapper(TinyRemapper remapper, Map<Path, Path> paths, L
593617 Constants .MAIN_LOGGER .debug ("Done 1!" );
594618 }
595619
596- MappingsUtilsImpl .completeMappingsFromTr (remapper .getEnvironment ());
620+ if ( analyzeMapping ) MappingsUtilsImpl .completeMappingsFromTr (remapper .getEnvironment (), srcNamespace );
597621 } catch (Exception e ) {
598622 remapper .finish ();
599623 outputConsumerPaths .forEach (o -> {
0 commit comments