Skip to content

Commit

Permalink
Fix crash reported in Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Oct 14, 2023
1 parent 4b42af1 commit 35ccab3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.regex.Pattern;

public class ReflectionUtil {
private static final Pattern pattern = Pattern.compile("Attempted to load class ([A-Za-z]+(/[A-Za-z]+)+) for invalid dist [A-Za-z0-9]+_[A-Za-z0-9]+", Pattern.CASE_INSENSITIVE);

public static boolean hasMethodOverride(Class<?> clazz, Class<?> superclass, boolean fallbackResult, String methodName, Class<?>... methodArgs) {
while (clazz != null && clazz != superclass && superclass.isAssignableFrom(clazz)) {
try {
Expand All @@ -20,12 +24,16 @@ public static boolean hasMethodOverride(Class<?> clazz, Class<?> superclass, boo
" getting declared methods crashes with NoClassDefFoundError: " + error.getMessage() +
". This is usually caused by modded" +
" entities declaring methods that have a return type or parameter type that is annotated" +
" with @Environment(value=EnvType.CLIENT). Loading the type is not possible, because" +
" with @OnlyIn(Dist.CLIENT). Loading the type is not possible, because" +
" it only exists in the CLIENT environment. The recommended fix is to annotate the method with" +
" this argument or return type with the same annotation." +
" Lithium handles this error by assuming the class cannot be included in some optimizations.");
return fallbackResult;
} catch (Throwable e) {
if (pattern.matcher(e.getMessage()).matches()) {
return false;
}

final String crashedClass = clazz.getName();
CrashReport crashReport = CrashReport.create(e, "Lithium Class Analysis");
CrashReportSection crashReportSection = crashReport.addElement(e.getClass().toString() + " when getting declared methods.");
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"conformVisibility": true
},
"mixins": [
"ai.nearby_entity_tracking.EntityMixin",
"ai.nearby_entity_tracking.EntityTrackingSectionMixin",
Expand Down

0 comments on commit 35ccab3

Please sign in to comment.