diff --git a/expansions/pandemonium/src/main/java/ladysnake/pandemonium/common/entity/ability/EvokerVexAbility.java b/expansions/pandemonium/src/main/java/ladysnake/pandemonium/common/entity/ability/EvokerVexAbility.java index 4164d1475..0c36afab2 100644 --- a/expansions/pandemonium/src/main/java/ladysnake/pandemonium/common/entity/ability/EvokerVexAbility.java +++ b/expansions/pandemonium/src/main/java/ladysnake/pandemonium/common/entity/ability/EvokerVexAbility.java @@ -72,7 +72,7 @@ public void update() { static { try { Class extends SpellcastingIllagerEntity.CastSpellGoal> clazz = ReflectionHelper.findClass("net.minecraft.class_1564$class_1567"); - VEX_GOAL_FACTORY = clazz.getConstructor(EvokerEntity.class); + VEX_GOAL_FACTORY = clazz.getDeclaredConstructor(EvokerEntity.class); VEX_GOAL_FACTORY.setAccessible(true); } catch (ClassNotFoundException e) { throw new UncheckedReflectionException("Could not find the SummonVexGoal class", e); diff --git a/src/main/java/ladysnake/requiem/common/util/reflection/ReflectionHelper.java b/src/main/java/ladysnake/requiem/common/util/reflection/ReflectionHelper.java index e9138ca83..b4b84b68b 100644 --- a/src/main/java/ladysnake/requiem/common/util/reflection/ReflectionHelper.java +++ b/src/main/java/ladysnake/requiem/common/util/reflection/ReflectionHelper.java @@ -27,6 +27,8 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static org.apiguardian.api.API.Status.MAINTAINED; import static org.apiguardian.api.API.Status.STABLE; @@ -35,6 +37,7 @@ public class ReflectionHelper { public static final String INTERMEDIARY = "intermediary"; + public static final Pattern LTYPE_PATTERN = Pattern.compile("L(.*?);"); @API(status = MAINTAINED, since = "1.0.0") public static boolean isDevEnv() { @@ -43,12 +46,36 @@ public static boolean isDevEnv() { @API(status = MAINTAINED, since = "1.0.0") public static String getMethodDescriptor(Class> returnType, Class>... parameterTypes) { - return Type.getMethodDescriptor(Type.getType(returnType), Arrays.stream(parameterTypes).map(Type::getType).toArray(Type[]::new)); + return Type.getMethodDescriptor(Type.getType(returnType), Arrays.stream(parameterTypes).map(ReflectionHelper::getUnmappedType).toArray(Type[]::new)); + } + + /** + * Finds the {@link Type} of the given class in the intermediary namespace. + * + *
If {@code clazz} has no mappings, this method behaves as if:
+ * {@code Type.getDescriptor(clazz)}.
+ *
+ * @param clazz a class of which to find the unmapped type
+ * @return the unmapped type
+ */
+ private static Type getUnmappedType(Class> clazz) {
+ /*
+ * Note that we cannot directly check if the class has a mapping, because of array types.
+ * As such, we unmap the core class of the parsed descriptor.
+ */
+ String desc = Type.getDescriptor(clazz);
+ Matcher lMatch = LTYPE_PATTERN.matcher(desc);
+ if (lMatch.find()) {
+ String coreClass = lMatch.group(1).replace('/', '.');
+ String unmappedType = getMappingResolver().unmapClassName(INTERMEDIARY, coreClass);
+ desc = lMatch.replaceFirst("L" + unmappedType.replace('.', '/') + ";");
+ }
+ return Type.getType(desc);
}
@API(status = MAINTAINED, since = "1.0.0")
public static String getFieldDescriptor(Class> type) {
- return Type.getType(type).getDescriptor();
+ return getUnmappedType(type).getDescriptor();
}
@SuppressWarnings("unchecked")
@@ -60,7 +87,7 @@ public static