|
4 | 4 | import com.tterrag.registrate.builders.BlockBuilder; |
5 | 5 | import net.neoforged.fml.ModList; |
6 | 6 | import net.neoforged.neoforgespi.language.ModFileScanData; |
| 7 | +import org.jetbrains.annotations.NotNull; |
7 | 8 |
|
8 | 9 | import java.lang.annotation.ElementType; |
9 | 10 | import java.lang.annotation.Retention; |
10 | 11 | import java.lang.annotation.RetentionPolicy; |
11 | 12 | import java.lang.annotation.Target; |
12 | 13 | import java.lang.reflect.Method; |
13 | 14 | import java.lang.reflect.Modifier; |
14 | | -import java.util.Arrays; |
15 | | -import java.util.Comparator; |
16 | | -import java.util.LinkedHashMap; |
17 | | -import java.util.List; |
18 | | -import java.util.Map; |
19 | | -import java.util.Objects; |
| 15 | +import java.util.*; |
20 | 16 | import java.util.function.Consumer; |
21 | 17 |
|
22 | 18 | /** |
@@ -94,22 +90,24 @@ private static Method resolveRegistratorMethod(final ModFileScanData.AnnotationD |
94 | 90 | } |
95 | 91 |
|
96 | 92 | final List<Method> registrators = Arrays.stream(owner.getDeclaredMethods()) |
97 | | - .filter(method -> method.getName().equals(annotationData.memberName())) |
| 93 | + .filter(method -> annotationData.memberName().startsWith(method.getName())) //Compare ignoring the ()V for params |
98 | 94 | .filter(method -> method.isAnnotationPresent(Registrator.class)) |
99 | 95 | .toList(); |
100 | 96 | if (registrators.size() != 1) { |
101 | 97 | throw new IllegalStateException("Expected exactly one annotated @CreateBlockEdits.Registrator method for " + describe(annotationData) + ", but found " + registrators.size() + "."); |
102 | 98 | } |
103 | 99 |
|
104 | | - final Method registratorMethod = registrators.get(0); |
| 100 | + return resolveRegistratorMethodFromRegistrators(registrators); |
| 101 | + } |
| 102 | + |
| 103 | + private static @NotNull Method resolveRegistratorMethodFromRegistrators(final List<Method> registrators) { |
| 104 | + final Method registratorMethod = registrators.getFirst(); |
105 | 105 | if (!Modifier.isPublic(registratorMethod.getModifiers()) |
106 | 106 | || !Modifier.isStatic(registratorMethod.getModifiers()) |
107 | 107 | || registratorMethod.getParameterCount() != 0 |
108 | | - || registratorMethod.getReturnType() != Void.TYPE |
109 | | - || !registratorMethod.getName().equals("register")) { |
| 108 | + || registratorMethod.getReturnType() != Void.TYPE) { |
110 | 109 | throw new IllegalStateException("Invalid @CreateBlockEdits.Registrator method " + registratorMethod.toGenericString() + "; expected public static void register() with no arguments."); |
111 | 110 | } |
112 | | - |
113 | 111 | return registratorMethod; |
114 | 112 | } |
115 | 113 |
|
|
0 commit comments