33import fr .catcore .modremapperapi .utils .Constants ;
44import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .MappingUtils ;
55import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper ;
6- import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .RemapLibrary ;
7- import io .github .fabriccompatibiltylayers .modremappingapi .impl .MappingBuilderImpl ;
6+ import io .github .fabriccompatibiltylayers .modremappingapi .impl .LibraryHandler ;
87import io .github .fabriccompatibiltylayers .modremappingapi .impl .MappingsUtilsImpl ;
98import io .github .fabriccompatibiltylayers .modremappingapi .impl .VisitorInfosImpl ;
109import io .github .fabriccompatibiltylayers .modremappingapi .impl .mappings .MappingTreeHelper ;
1514import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MRAApplyVisitor ;
1615import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MixinPostApplyVisitor ;
1716import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .CacheUtils ;
18- import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .FileUtils ;
1917import net .fabricmc .api .EnvType ;
2018import net .fabricmc .loader .api .FabricLoader ;
2119import net .fabricmc .mappingio .MappingVisitor ;
2220import net .fabricmc .mappingio .tree .MappingTree ;
23- import net .fabricmc .mappingio .tree .MemoryMappingTree ;
2421import net .fabricmc .tinyremapper .*;
2522import net .fabricmc .tinyremapper .extension .mixin .MixinExtension ;
2623import org .jetbrains .annotations .ApiStatus ;
2724
2825import java .io .*;
29- import java .net .URISyntaxException ;
3026import java .nio .file .Files ;
3127import java .nio .file .Path ;
3228import java .util .*;
3329import java .util .function .Supplier ;
3430
3531public class RemapUtil {
3632 private static List <ModRemapper > remappers ;
37- private static MappingTree LOADER_TREE ;
3833
3934 @ ApiStatus .Internal
4035 public static final Map <String , List <String >> MIXINED = new HashMap <>();
4136
4237 @ ApiStatus .Internal
4338 public static String defaultPackage = "" ;
4439
45- @ ApiStatus . Internal
46- public static final List <String > MC_CLASS_NAMES = new ArrayList <>() ;
40+ @ Deprecated
41+ public static final List <String > MC_CLASS_NAMES = MappingsRegistry . VANILLA_CLASS_LIST ;
4742
4843 @ ApiStatus .Internal
4944 public static void init (List <io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper > modRemappers ) {
@@ -87,73 +82,23 @@ public static void init(List<io.github.fabriccompatibiltylayers.modremappingapi.
8782 }
8883 }
8984
90- downloadRemappingLibs ();
91-
92- writeMcMappings ();
93-
94- LOADER_TREE = generateMappings ();
95- MappingsUtilsImpl .addMappingsToContext (LOADER_TREE );
96-
97- for (MappingTree .ClassMapping classView : MappingsRegistry .FORMATTED .getClasses ()) {
98- String className = classView .getName (MappingsUtilsImpl .getSourceNamespace ());
85+ LibraryHandler .gatherRemapLibraries (remappers );
9986
100- if (className != null ) {
101- MC_CLASS_NAMES .add ("/" + className + ".class" );
102- }
103- }
104- }
105-
106- private static void downloadRemappingLibs () {
107- try {
108- for (ModRemapper remapper : remappers ) {
109- List <RemapLibrary > libraries = new ArrayList <>();
110-
111- remapper .addRemapLibraries (libraries , FabricLoader .getInstance ().getEnvironmentType ());
112-
113- Map <RemapLibrary , Path > libraryPaths = CacheUtils .computeExtraLibraryPaths (libraries , MappingsUtilsImpl .getSourceNamespace ());
114-
115- for (Map .Entry <RemapLibrary , Path > entry : libraryPaths .entrySet ()) {
116- RemapLibrary library = entry .getKey ();
117- Path path = entry .getValue ();
118-
119- if (!library .url .isEmpty ()) {
120- Constants .MAIN_LOGGER .info ("Downloading remapping library '" + library .fileName + "' from url '" + library .url + "'" );
121- FileUtils .downloadFile (library .url , path );
122- FileUtils .removeEntriesFromZip (path , library .toExclude );
123- Constants .MAIN_LOGGER .info ("Remapping library ready for use." );
124- } else if (library .path != null ) {
125- Constants .MAIN_LOGGER .info ("Extracting remapping library '" + library .fileName + "' from mod jar." );
126- FileUtils .copyZipFile (library .path , path );
127- Constants .MAIN_LOGGER .info ("Remapping library ready for use." );
128- }
129- }
130- }
131- } catch (IOException | URISyntaxException e ) {
132- throw new RuntimeException (e );
133- }
87+ MappingsRegistry .registerAdditionalMappings (remappers );
13488 }
13589
13690 @ ApiStatus .Internal
13791 public static void remapMods (Map <Path , Path > pathMap ) {
13892 Constants .MAIN_LOGGER .debug ("Starting jar remapping!" );
13993 SoftLockFixer .preloadClasses ();
140- TinyRemapper remapper = makeRemapper (MappingsRegistry .FORMATTED , LOADER_TREE , MappingsRegistry .MODS );
94+ TinyRemapper remapper = makeRemapper (MappingsRegistry .FORMATTED , MappingsRegistry . ADDITIONAL , MappingsRegistry .MODS );
14195 Constants .MAIN_LOGGER .debug ("Remapper created!" );
14296 remapFiles (remapper , pathMap );
14397 Constants .MAIN_LOGGER .debug ("Jar remapping done!" );
14498
14599 MappingsUtilsImpl .writeFullMappings ();
146100 }
147101
148- @ ApiStatus .Internal
149- public static void writeMcMappings () {
150- try {
151- MappingTreeHelper .exportMappings (MappingsRegistry .FORMATTED , Constants .MC_MAPPINGS_FILE .toPath ());
152- } catch (IOException e ) {
153- throw new RuntimeException (e );
154- }
155- }
156-
157102 @ Deprecated
158103 public static class MappingList extends ArrayList <MappingBuilder > {
159104 public MappingList () {
@@ -180,28 +125,6 @@ public void accept(MappingVisitor visitor) throws IOException {
180125 }
181126 }
182127
183- private static MappingTree generateMappings () {
184- MemoryMappingTree mappingTree ;
185-
186- try {
187- mappingTree = MappingTreeHelper .createMappingTree ();
188-
189- io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .MappingBuilder builder = new MappingBuilderImpl (mappingTree );
190-
191- for (ModRemapper remapper : remappers ) {
192- remapper .registerMappings (builder );
193- }
194-
195- mappingTree .visitEnd ();
196-
197- MappingTreeHelper .exportMappings (mappingTree , Constants .EXTRA_MAPPINGS_FILE .toPath ());
198- } catch (IOException e ) {
199- throw new RuntimeException ("Error while generating remappers mappings" , e );
200- }
201-
202- return mappingTree ;
203- }
204-
205128 /**
206129 * Will create remapper with specified trees.
207130 */
@@ -250,21 +173,7 @@ private static TinyRemapper makeRemapper(MappingTree... trees) {
250173 throw new RuntimeException (e );
251174 }
252175
253- for (ModRemapper modRemapper : remappers ) {
254- List <RemapLibrary > libraries = new ArrayList <>();
255-
256- modRemapper .addRemapLibraries (libraries , FabricLoader .getInstance ().getEnvironmentType ());
257-
258- for (RemapLibrary library : libraries ) {
259- Path libPath = CacheUtils .getLibraryPath (MappingsUtilsImpl .getSourceNamespace ()).resolve (library .fileName );
260-
261- if (Files .exists (libPath )) {
262- remapper .readClassPathAsync (libPath );
263- } else {
264- Constants .MAIN_LOGGER .info ("Library " + libPath + " does not exist." );
265- }
266- }
267- }
176+ LibraryHandler .addLibrariesToRemapClasspath (remapper );
268177
269178 return remapper ;
270179 }
0 commit comments