1
1
package fr .catcore .modremapperapi .remapping ;
2
2
3
- import fr .catcore .modremapperapi .utils .Constants ;
4
3
import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .MappingUtils ;
5
- import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper ;
6
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .LibraryHandler ;
7
4
import io .github .fabriccompatibiltylayers .modremappingapi .impl .MappingsUtilsImpl ;
8
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .VisitorInfosImpl ;
9
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .mappings .MappingTreeHelper ;
10
5
import io .github .fabriccompatibiltylayers .modremappingapi .impl .mappings .MappingsRegistry ;
11
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .SoftLockFixer ;
12
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .minecraft .MinecraftRemapper ;
13
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .resource .RefmapRemapper ;
14
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MRAApplyVisitor ;
15
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MixinPostApplyVisitor ;
16
- import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .CacheUtils ;
17
6
import net .fabricmc .api .EnvType ;
18
7
import net .fabricmc .loader .api .FabricLoader ;
19
8
import net .fabricmc .mappingio .MappingVisitor ;
20
- import net .fabricmc .mappingio .tree .MappingTree ;
21
- import net .fabricmc .tinyremapper .*;
22
- import net .fabricmc .tinyremapper .extension .mixin .MixinExtension ;
23
9
import org .jetbrains .annotations .ApiStatus ;
24
10
25
11
import java .io .*;
26
- import java .nio .file .Files ;
27
- import java .nio .file .Path ;
28
12
import java .util .*;
29
- import java .util .function .Supplier ;
30
13
14
+ @ Deprecated
31
15
public class RemapUtil {
32
- private static List <ModRemapper > remappers ;
33
-
34
- @ ApiStatus .Internal
35
- public static final Map <String , List <String >> MIXINED = new HashMap <>();
36
-
37
- @ ApiStatus .Internal
38
- public static String defaultPackage = "" ;
39
-
40
16
@ Deprecated
41
17
public static final List <String > MC_CLASS_NAMES = MappingsRegistry .VANILLA_CLASS_LIST ;
42
18
43
- @ ApiStatus .Internal
44
- public static void init (List <io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper > modRemappers ) {
45
- remappers = modRemappers ;
46
-
47
- for (ModRemapper remapper : remappers ) {
48
- Optional <String > pkg = remapper .getDefaultPackage ();
49
-
50
- pkg .ifPresent (s -> defaultPackage = s );
51
-
52
- Optional <String > sourceNamespace = remapper .getSourceNamespace ();
53
-
54
- sourceNamespace .ifPresent (MappingsUtilsImpl ::setSourceNamespace );
55
-
56
- Optional <Supplier <InputStream >> mappings = remapper .getExtraMapping ();
57
-
58
- mappings .ifPresent (inputStreamSupplier -> {
59
- try {
60
- MappingsRegistry .generateFormattedMappings (inputStreamSupplier .get ());
61
- } catch (IOException e ) {
62
- throw new RuntimeException (e );
63
- }
64
- });
65
- }
66
-
67
- if (!MappingsRegistry .generated ) {
68
- try {
69
- MappingsRegistry .generateFormattedMappings (null );
70
- } catch (IOException e ) {
71
- throw new RuntimeException (e );
72
- }
73
- }
74
-
75
- Path sourceLibraryPath = CacheUtils .getLibraryPath (MappingsUtilsImpl .getSourceNamespace ());
76
-
77
- if (!Files .exists (sourceLibraryPath )) {
78
- try {
79
- Files .createDirectories (sourceLibraryPath );
80
- } catch (IOException e ) {
81
- throw new RuntimeException (e );
82
- }
83
- }
84
-
85
- LibraryHandler .gatherRemapLibraries (remappers );
86
-
87
- MappingsRegistry .registerAdditionalMappings (remappers );
88
- }
89
-
90
- @ ApiStatus .Internal
91
- public static void remapMods (Map <Path , Path > pathMap ) {
92
- Constants .MAIN_LOGGER .debug ("Starting jar remapping!" );
93
- SoftLockFixer .preloadClasses ();
94
- TinyRemapper remapper = makeRemapper (MappingsRegistry .FORMATTED , MappingsRegistry .ADDITIONAL , MappingsRegistry .MODS );
95
- Constants .MAIN_LOGGER .debug ("Remapper created!" );
96
- remapFiles (remapper , pathMap );
97
- Constants .MAIN_LOGGER .debug ("Jar remapping done!" );
98
-
99
- MappingsUtilsImpl .writeFullMappings ();
100
- }
101
-
102
19
@ Deprecated
103
20
public static class MappingList extends ArrayList <MappingBuilder > {
104
21
public MappingList () {
@@ -125,124 +42,6 @@ public void accept(MappingVisitor visitor) throws IOException {
125
42
}
126
43
}
127
44
128
- /**
129
- * Will create remapper with specified trees.
130
- */
131
- private static TinyRemapper makeRemapper (MappingTree ... trees ) {
132
- TinyRemapper .Builder builder = TinyRemapper
133
- .newRemapper ()
134
- .renameInvalidLocals (true )
135
- .ignoreFieldDesc (false )
136
- .propagatePrivate (true )
137
- .ignoreConflicts (true );
138
-
139
- if (FabricLoader .getInstance ().isDevelopmentEnvironment ()) {
140
- builder .fixPackageAccess (true );
141
- }
142
-
143
- for (MappingTree tree : trees ) {
144
- builder .withMappings (MappingTreeHelper .createMappingProvider (tree , MappingsUtilsImpl .getSourceNamespace (), MappingsUtilsImpl .getTargetNamespace ()));
145
- }
146
-
147
- MRAApplyVisitor preApplyVisitor = new MRAApplyVisitor ();
148
- MRAApplyVisitor postApplyVisitor = new MRAApplyVisitor ();
149
- MixinPostApplyVisitor mixinPostApplyVisitor = new MixinPostApplyVisitor ();
150
-
151
- VisitorInfosImpl preInfos = new VisitorInfosImpl ();
152
- VisitorInfosImpl postInfos = new VisitorInfosImpl ();
153
-
154
- for (ModRemapper modRemapper : remappers ) {
155
- modRemapper .registerPreVisitors (preInfos );
156
- modRemapper .registerPostVisitors (postInfos );
157
- }
158
-
159
- preApplyVisitor .setInfos (preInfos );
160
- postApplyVisitor .setInfos (postInfos );
161
-
162
- builder .extraPreApplyVisitor (preApplyVisitor );
163
- builder .extraPostApplyVisitor (postApplyVisitor );
164
- builder .extraPostApplyVisitor (mixinPostApplyVisitor );
165
-
166
- builder .extension (new MixinExtension (EnumSet .of (MixinExtension .AnnotationTarget .HARD )));
167
-
168
- TinyRemapper remapper = builder .build ();
169
-
170
- try {
171
- MinecraftRemapper .addMinecraftJar (remapper );
172
- } catch (IOException e ) {
173
- throw new RuntimeException (e );
174
- }
175
-
176
- LibraryHandler .addLibrariesToRemapClasspath (remapper );
177
-
178
- return remapper ;
179
- }
180
-
181
- /**
182
- * Will remap file with specified remapper and store it into output.
183
- *
184
- * @param remapper {@link TinyRemapper} to remap with.
185
- */
186
- private static void remapFiles (TinyRemapper remapper , Map <Path , Path > paths ) {
187
- List <OutputConsumerPath > outputConsumerPaths = new ArrayList <>();
188
-
189
- List <OutputConsumerPath .ResourceRemapper > resourceRemappers = new ArrayList <>(NonClassCopyMode .FIX_META_INF .remappers );
190
- resourceRemappers .add (new RefmapRemapper ());
191
-
192
- applyRemapper (remapper , paths , outputConsumerPaths , resourceRemappers , true , MappingsUtilsImpl .getSourceNamespace (), MappingsUtilsImpl .getTargetNamespace ());
193
- }
194
-
195
- @ ApiStatus .Internal
196
- public static void applyRemapper (TinyRemapper remapper , Map <Path , Path > paths , List <OutputConsumerPath > outputConsumerPaths , List <OutputConsumerPath .ResourceRemapper > resourceRemappers , boolean analyzeMapping , String srcNamespace , String targetNamespace ) {
197
- try {
198
- Map <Path , InputTag > tagMap = new HashMap <>();
199
-
200
- Constants .MAIN_LOGGER .debug ("Creating InputTags!" );
201
- for (Path input : paths .keySet ()) {
202
- InputTag tag = remapper .createInputTag ();
203
- tagMap .put (input , tag );
204
- remapper .readInputsAsync (tag , input );
205
- }
206
-
207
- Constants .MAIN_LOGGER .debug ("Initializing remapping!" );
208
- for (Map .Entry <Path , Path > entry : paths .entrySet ()) {
209
- Constants .MAIN_LOGGER .debug ("Starting remapping " + entry .getKey ().toString () + " to " + entry .getValue ().toString ());
210
- OutputConsumerPath outputConsumer = new OutputConsumerPath .Builder (entry .getValue ()).build ();
211
-
212
- outputConsumerPaths .add (outputConsumer );
213
-
214
- Constants .MAIN_LOGGER .debug ("Apply remapper!" );
215
- remapper .apply (outputConsumer , tagMap .get (entry .getKey ()));
216
-
217
- Constants .MAIN_LOGGER .debug ("Add input as non class file!" );
218
- outputConsumer .addNonClassFiles (entry .getKey (), remapper , resourceRemappers );
219
-
220
- Constants .MAIN_LOGGER .debug ("Done 1!" );
221
- }
222
-
223
- if (analyzeMapping ) MappingsUtilsImpl .completeMappingsFromTr (remapper .getEnvironment (), srcNamespace );
224
- } catch (Exception e ) {
225
- remapper .finish ();
226
- outputConsumerPaths .forEach (o -> {
227
- try {
228
- o .close ();
229
- } catch (IOException e2 ) {
230
- e2 .printStackTrace ();
231
- }
232
- });
233
- throw new RuntimeException ("Failed to remap jar" , e );
234
- } finally {
235
- remapper .finish ();
236
- outputConsumerPaths .forEach (o -> {
237
- try {
238
- o .close ();
239
- } catch (IOException e ) {
240
- e .printStackTrace ();
241
- }
242
- });
243
- }
244
- }
245
-
246
45
@ Deprecated
247
46
public static String getRemappedFieldName (Class <?> owner , String fieldName ) {
248
47
return MappingUtils .mapField (owner , fieldName ).name ;
0 commit comments