Skip to content

Commit b98562c

Browse files
authored
Merge pull request #21 from FabricCompatibilityLayers/feature/remapping-context
Remapping context
2 parents 4ed4014 + 57f0e93 commit b98562c

31 files changed

Lines changed: 1027 additions & 776 deletions

src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.MappingUtils;
44
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl;
5-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingsRegistry;
5+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.context.v1.ModRemapperV1Context;
66
import net.fabricmc.api.EnvType;
77
import net.fabricmc.loader.api.FabricLoader;
88
import net.fabricmc.mappingio.MappingVisitor;
@@ -14,7 +14,7 @@
1414
@Deprecated
1515
public class RemapUtil {
1616
@Deprecated
17-
public static final List<String> MC_CLASS_NAMES = MappingsRegistry.VANILLA_CLASS_LIST;
17+
public static final List<String> MC_CLASS_NAMES = ModRemapperV1Context.INSTANCE.getMappingsRegistry().getVanillaClassNames();
1818

1919
@Deprecated
2020
public static class MappingList extends ArrayList<MappingBuilder> {

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/api/MappingUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static String unmapClass(String className) {
3838
*/
3939
@Deprecated
4040
static MappingUtils.ClassMember mapField(String className, String fieldName, @Nullable String fieldDesc) {
41-
return MappingsUtilsImpl.mapField(className, fieldName, fieldDesc);
41+
return MappingsUtilsImpl.mapField(MappingsUtilsImpl.getV1Registry(), className, fieldName, fieldDesc);
4242
}
4343

4444
/**
@@ -50,7 +50,7 @@ static MappingUtils.ClassMember mapField(String className, String fieldName, @Nu
5050
*/
5151
@Deprecated
5252
static MappingUtils.ClassMember mapFieldFromRemappedClass(String className, String fieldName, @Nullable String fieldDesc) {
53-
return MappingsUtilsImpl.mapFieldFromRemappedClass(className, fieldName, fieldDesc);
53+
return MappingsUtilsImpl.mapFieldFromRemappedClass(MappingsUtilsImpl.getV1Registry(), className, fieldName, fieldDesc);
5454
}
5555

5656
/**
@@ -62,7 +62,7 @@ static MappingUtils.ClassMember mapFieldFromRemappedClass(String className, Stri
6262
*/
6363
@Deprecated
6464
static MappingUtils.ClassMember mapMethod(String className, String methodName, String methodDesc) {
65-
return MappingsUtilsImpl.mapMethod(className, methodName, methodDesc);
65+
return MappingsUtilsImpl.mapMethod(MappingsUtilsImpl.getV1Registry(), className, methodName, methodDesc);
6666
}
6767

6868
/**
@@ -74,7 +74,7 @@ static MappingUtils.ClassMember mapMethod(String className, String methodName, S
7474
*/
7575
@Deprecated
7676
static MappingUtils.ClassMember mapMethodFromRemappedClass(String className, String methodName, String methodDesc) {
77-
return MappingsUtilsImpl.mapMethodFromRemappedClass(className, methodName, methodDesc);
77+
return MappingsUtilsImpl.mapMethodFromRemappedClass(MappingsUtilsImpl.getV1Registry(), className, methodName, methodDesc);
7878
}
7979

8080
/**
@@ -85,7 +85,7 @@ static MappingUtils.ClassMember mapMethodFromRemappedClass(String className, Str
8585
*/
8686
@Deprecated
8787
static MappingUtils.ClassMember mapField(Class<?> owner, String fieldName) {
88-
return MappingsUtilsImpl.mapField(owner, fieldName);
88+
return MappingsUtilsImpl.mapField(MappingsUtilsImpl.getV1Registry(), owner, fieldName);
8989
}
9090

9191
/**
@@ -97,7 +97,7 @@ static MappingUtils.ClassMember mapField(Class<?> owner, String fieldName) {
9797
*/
9898
@Deprecated
9999
static MappingUtils.ClassMember mapMethod(Class<?> owner, String methodName, Class<?>[] parameterTypes) {
100-
return MappingsUtilsImpl.mapMethod(owner, methodName, parameterTypes);
100+
return MappingsUtilsImpl.mapMethod(MappingsUtilsImpl.getV1Registry(), owner, methodName, parameterTypes);
101101
}
102102

103103
/**

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/api/v1/MappingUtils.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface MappingUtils {
1111
* @return remapped class name
1212
*/
1313
static String mapClass(String className) {
14-
return MappingsUtilsImpl.mapClass(className);
14+
return MappingsUtilsImpl.mapClass(MappingsUtilsImpl.getV1Registry(), className);
1515
}
1616

1717
/**
@@ -20,7 +20,7 @@ static String mapClass(String className) {
2020
* @return original class name
2121
*/
2222
static String unmapClass(String className) {
23-
return MappingsUtilsImpl.unmapClass(className);
23+
return MappingsUtilsImpl.unmapClass(MappingsUtilsImpl.getV1Registry(), className);
2424
}
2525

2626
/**
@@ -31,7 +31,7 @@ static String unmapClass(String className) {
3131
* @return
3232
*/
3333
static ClassMember mapField(String className, String fieldName, @Nullable String fieldDesc) {
34-
return MappingsUtilsImpl.mapField(className, fieldName, fieldDesc);
34+
return MappingsUtilsImpl.mapField(MappingsUtilsImpl.getV1Registry(), className, fieldName, fieldDesc);
3535
}
3636

3737
/**
@@ -42,7 +42,7 @@ static ClassMember mapField(String className, String fieldName, @Nullable String
4242
* @return
4343
*/
4444
static ClassMember mapFieldFromRemappedClass(String className, String fieldName, @Nullable String fieldDesc) {
45-
return MappingsUtilsImpl.mapFieldFromRemappedClass(className, fieldName, fieldDesc);
45+
return MappingsUtilsImpl.mapFieldFromRemappedClass(MappingsUtilsImpl.getV1Registry(), className, fieldName, fieldDesc);
4646
}
4747

4848
/**
@@ -53,7 +53,7 @@ static ClassMember mapFieldFromRemappedClass(String className, String fieldName,
5353
* @return
5454
*/
5555
static ClassMember mapMethod(String className, String methodName, String methodDesc) {
56-
return MappingsUtilsImpl.mapMethod(className, methodName, methodDesc);
56+
return MappingsUtilsImpl.mapMethod(MappingsUtilsImpl.getV1Registry(), className, methodName, methodDesc);
5757
}
5858

5959
/**
@@ -64,15 +64,15 @@ static ClassMember mapMethod(String className, String methodName, String methodD
6464
* @return
6565
*/
6666
static ClassMember mapMethodFromRemappedClass(String className, String methodName, String methodDesc) {
67-
return MappingsUtilsImpl.mapMethodFromRemappedClass(className, methodName, methodDesc);
67+
return MappingsUtilsImpl.mapMethodFromRemappedClass(MappingsUtilsImpl.getV1Registry(), className, methodName, methodDesc);
6868
}
6969

7070
static ClassMember mapField(Class<?> owner, String fieldName) {
71-
return MappingsUtilsImpl.mapField(owner, fieldName);
71+
return MappingsUtilsImpl.mapField(MappingsUtilsImpl.getV1Registry(), owner, fieldName);
7272
}
7373

7474
static ClassMember mapMethod(Class<?> owner, String methodName, Class<?>[] parameterTypes) {
75-
return MappingsUtilsImpl.mapMethod(owner, methodName, parameterTypes);
75+
return MappingsUtilsImpl.mapMethod(MappingsUtilsImpl.getV1Registry(), owner, methodName, parameterTypes);
7676
}
7777

7878
/**
@@ -81,7 +81,7 @@ static ClassMember mapMethod(Class<?> owner, String methodName, Class<?>[] param
8181
* @return remapped descriptor
8282
*/
8383
static String mapDescriptor(String desc) {
84-
return MappingsUtilsImpl.mapDescriptor(desc);
84+
return MappingsUtilsImpl.mapDescriptor(MappingsUtilsImpl.getV1Registry(), desc);
8585
}
8686

8787
class ClassMember {

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/api/v1/ModRemapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ default Optional<String> getSourceNamespace() {
3030
default Optional<Supplier<InputStream>> getExtraMapping() {
3131
return Optional.empty();
3232
}
33+
34+
/**
35+
* Whether to enable mixin remapping. Enabled by default for compatibility purposes.
36+
* @return true - enabled <br> false - disabled
37+
*/
38+
default boolean remapMixins() {
39+
return true;
40+
}
3341
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.fabriccompatibiltylayers.modremappingapi.impl;
2+
3+
import java.nio.file.Path;
4+
5+
public class DefaultModCandidate extends ModCandidate {
6+
public DefaultModCandidate(String modName, Path file, Path original) {
7+
super(modName, modName, file, original);
8+
}
9+
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/DefaultModEntry.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/DefaultModRemapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public void registerPreVisitors(VisitorInfos infos) {
3333
public void registerPostVisitors(VisitorInfos infos) {
3434

3535
}
36+
37+
@Override
38+
public boolean remapMixins() {
39+
return false;
40+
}
3641
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/LibraryHandler.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,34 @@
1818
import java.util.Map;
1919

2020
public class LibraryHandler {
21-
private static final Map<RemapLibrary, Path> remapLibraries = new HashMap<>();
21+
private final Map<RemapLibrary, Path> remapLibraries = new HashMap<>();
2222

23-
public static void gatherRemapLibraries(List<ModRemapper> remappers) {
23+
private String sourceNamespace;
24+
25+
public LibraryHandler() {}
26+
27+
public void init(String sourceNamespace) {
28+
this.sourceNamespace = sourceNamespace;
29+
30+
Path sourceLibraryPath = CacheUtils.getLibraryPath(this.sourceNamespace);
31+
32+
if (!Files.exists(sourceLibraryPath)) {
33+
try {
34+
Files.createDirectories(sourceLibraryPath);
35+
} catch (IOException e) {
36+
throw new RuntimeException(e);
37+
}
38+
}
39+
}
40+
41+
public void gatherRemapLibraries(List<ModRemapper> remappers) {
2442
try {
2543
for (ModRemapper remapper : remappers) {
2644
List<RemapLibrary> libraries = new ArrayList<>();
2745

2846
remapper.addRemapLibraries(libraries, FabricLoader.getInstance().getEnvironmentType());
2947

30-
Map<RemapLibrary, Path> temp = CacheUtils.computeExtraLibraryPaths(libraries, MappingsUtilsImpl.getSourceNamespace());
48+
Map<RemapLibrary, Path> temp = CacheUtils.computeExtraLibraryPaths(libraries, sourceNamespace);
3149

3250
for (Map.Entry<RemapLibrary, Path> entry : temp.entrySet()) {
3351
RemapLibrary library = entry.getKey();
@@ -54,7 +72,7 @@ public static void gatherRemapLibraries(List<ModRemapper> remappers) {
5472
}
5573
}
5674

57-
public static void addLibrariesToRemapClasspath(TinyRemapper remapper) {
75+
public void addLibrariesToRemapClasspath(TinyRemapper remapper) {
5876
for (Path libPath : remapLibraries.values()) {
5977
if (Files.exists(libPath)) {
6078
remapper.readClassPathAsync(libPath);

0 commit comments

Comments
 (0)