3
3
import fr .catcore .modremapperapi .utils .Constants ;
4
4
import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .MappingUtils ;
5
5
import 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 ;
8
7
import io .github .fabriccompatibiltylayers .modremappingapi .impl .MappingsUtilsImpl ;
9
8
import io .github .fabriccompatibiltylayers .modremappingapi .impl .VisitorInfosImpl ;
10
9
import io .github .fabriccompatibiltylayers .modremappingapi .impl .mappings .MappingTreeHelper ;
15
14
import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MRAApplyVisitor ;
16
15
import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MixinPostApplyVisitor ;
17
16
import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .CacheUtils ;
18
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .FileUtils ;
19
17
import net .fabricmc .api .EnvType ;
20
18
import net .fabricmc .loader .api .FabricLoader ;
21
19
import net .fabricmc .mappingio .MappingVisitor ;
22
20
import net .fabricmc .mappingio .tree .MappingTree ;
23
- import net .fabricmc .mappingio .tree .MemoryMappingTree ;
24
21
import net .fabricmc .tinyremapper .*;
25
22
import net .fabricmc .tinyremapper .extension .mixin .MixinExtension ;
26
23
import org .jetbrains .annotations .ApiStatus ;
27
24
28
25
import java .io .*;
29
- import java .net .URISyntaxException ;
30
26
import java .nio .file .Files ;
31
27
import java .nio .file .Path ;
32
28
import java .util .*;
33
29
import java .util .function .Supplier ;
34
30
35
31
public class RemapUtil {
36
32
private static List <ModRemapper > remappers ;
37
- private static MappingTree LOADER_TREE ;
38
33
39
34
@ ApiStatus .Internal
40
35
public static final Map <String , List <String >> MIXINED = new HashMap <>();
41
36
42
37
@ ApiStatus .Internal
43
38
public static String defaultPackage = "" ;
44
39
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 ;
47
42
48
43
@ ApiStatus .Internal
49
44
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.
87
82
}
88
83
}
89
84
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 );
99
86
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 );
134
88
}
135
89
136
90
@ ApiStatus .Internal
137
91
public static void remapMods (Map <Path , Path > pathMap ) {
138
92
Constants .MAIN_LOGGER .debug ("Starting jar remapping!" );
139
93
SoftLockFixer .preloadClasses ();
140
- TinyRemapper remapper = makeRemapper (MappingsRegistry .FORMATTED , LOADER_TREE , MappingsRegistry .MODS );
94
+ TinyRemapper remapper = makeRemapper (MappingsRegistry .FORMATTED , MappingsRegistry . ADDITIONAL , MappingsRegistry .MODS );
141
95
Constants .MAIN_LOGGER .debug ("Remapper created!" );
142
96
remapFiles (remapper , pathMap );
143
97
Constants .MAIN_LOGGER .debug ("Jar remapping done!" );
144
98
145
99
MappingsUtilsImpl .writeFullMappings ();
146
100
}
147
101
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
-
157
102
@ Deprecated
158
103
public static class MappingList extends ArrayList <MappingBuilder > {
159
104
public MappingList () {
@@ -180,28 +125,6 @@ public void accept(MappingVisitor visitor) throws IOException {
180
125
}
181
126
}
182
127
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
-
205
128
/**
206
129
* Will create remapper with specified trees.
207
130
*/
@@ -250,21 +173,7 @@ private static TinyRemapper makeRemapper(MappingTree... trees) {
250
173
throw new RuntimeException (e );
251
174
}
252
175
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 );
268
177
269
178
return remapper ;
270
179
}
0 commit comments