Skip to content

Commit 6edbbb5

Browse files
committed
manually specify the few mc versions that don't have mappings
1 parent ba74876 commit 6edbbb5

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

core/src/main/java/org/vivecraft/linker/Helpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static NMSHelper getNMS() {
2727
}
2828

2929
public static Object getHelper(String classTemplate) {
30-
MCVersion mc = MCVersion.getCurrent();
30+
MCVersion mc = MCVersion.getCurrentCorrected();
3131
int major = mc.major;
3232
int minor = mc.minor;
3333
while (major > 7) {

core/src/main/java/org/vivecraft/util/MCVersion.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class MCVersion implements Comparable<MCVersion> {
1515
public final String version_;
1616

1717
private static MCVersion CURRENT;
18+
private static MCVersion CORRECTED;
1819

1920
private MCVersion(int major, int minor) {
2021
this.major = major;
@@ -36,6 +37,31 @@ public static MCVersion getCurrent() {
3637
return CURRENT;
3738
}
3839

40+
public static MCVersion getCurrentCorrected() {
41+
if (CORRECTED == null) {
42+
MCVersion version = getCurrent();
43+
// version resolving always tries to use version before the current version, if the actual one is not available
44+
// some versions are not available, because they had critical bugfixes, so those need to use the one after
45+
if (version.is(9, 1)) {
46+
version = new MCVersion(9, 2);
47+
} else if (version.is(9, 3)) {
48+
version = new MCVersion(9, 4);
49+
} else if (version.is(16, 0)) {
50+
version = new MCVersion(16, 1);
51+
} else if (version.is(20, 0)) {
52+
version = new MCVersion(20, 1);
53+
} else if (version.is(20, 3)) {
54+
version = new MCVersion(20, 4);
55+
} else if (version.is(20, 5)) {
56+
version = new MCVersion(20, 6);
57+
} else if (version.is(21, 2)) {
58+
version = new MCVersion(21, 3);
59+
}
60+
CORRECTED = version;
61+
}
62+
return CORRECTED;
63+
}
64+
3965
public static MCVersion parse(String version, boolean fatal) {
4066
MCVersion mc;
4167
String[] segments = version.split("\\.");
@@ -54,6 +80,10 @@ public static MCVersion parse(String version, boolean fatal) {
5480
return mc;
5581
}
5682

83+
public boolean is(int major, int minor) {
84+
return this.major == major && this.minor == minor;
85+
}
86+
5787
@Override
5888
public String toString() {
5989
return this.version;

core/src/main/java/org/vivecraft/util/reflection/ClassGetter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ClassGetter {
1515
*/
1616
public static Class<?> getClass(boolean critical, ClassMapping... mappings) {
1717
// get the matching filed with the closest matching version, preferring older ones, unless there is none
18-
MCVersion mc = MCVersion.getCurrent();
18+
MCVersion mc = MCVersion.getCurrentCorrected();
1919
Class<?> c = null;
2020
for (String namespace : new String[]{"spigot", "mojang"}) {
2121
for (ClassMapping mapping : mappings) {
@@ -58,7 +58,7 @@ public static Class<?> getRaw(String cls) throws ClassNotFoundException {
5858
}
5959

6060
public static Class<?> getWithApi(String pre, String post) throws ClassNotFoundException {
61-
MCVersion mc = MCVersion.getCurrent();
61+
MCVersion mc = MCVersion.getCurrentCorrected();
6262
for (int i = 0; i <= 10; i++) {
6363
String apiClass;
6464
if (i != 10) {
@@ -75,7 +75,7 @@ public static Class<?> getWithApi(String pre, String post) throws ClassNotFoundE
7575
}
7676

7777
public static Class<?> getCompat(String pattern) throws ClassNotFoundException {
78-
MCVersion mc = MCVersion.getCurrent();
78+
MCVersion mc = MCVersion.getCurrentCorrected();
7979
for (int i = mc.minor; i >= 0; i--) {
8080
String apiClass;
8181
if (i != 0) {

core/src/main/java/org/vivecraft/util/reflection/ReflectionConstructor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static ReflectionConstructor getConstructor(boolean critical, Constructor
6969

7070
@Nullable
7171
private static Constructor<?> getConstructor(String namespace, ConstructorMapping... mappings) {
72-
MCVersion mc = MCVersion.getCurrent();
72+
MCVersion mc = MCVersion.getCurrentCorrected();
7373
Constructor<?> c = null;
7474
for (ConstructorMapping mapping : mappings) {
7575
int major = mc.major;

core/src/main/java/org/vivecraft/util/reflection/ReflectionField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static ReflectionField getField(ClassMapping mapping, String fieldName) {
8888

8989
@Nullable
9090
private static Field getField(String namespace, FieldMapping... mappings) {
91-
MCVersion mc = MCVersion.getCurrent();
91+
MCVersion mc = MCVersion.getCurrentCorrected();
9292
Field f = null;
9393
for (FieldMapping mapping : mappings) {
9494
int major = mc.major;

core/src/main/java/org/vivecraft/util/reflection/ReflectionMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static ReflectionMethod getMethod(boolean critical, MethodMapping... mapp
7272
@Nullable
7373
private static Method getMethod(String namespace, MethodMapping... mappings) {
7474
// get the matching method with the closest matching version, preferring older ones, unless there is none
75-
MCVersion mc = MCVersion.getCurrent();
75+
MCVersion mc = MCVersion.getCurrentCorrected();
7676
Method m = null;
7777
for (MethodMapping mapping : mappings) {
7878
int major = mc.major;

0 commit comments

Comments
 (0)