Skip to content

Commit

Permalink
fix quirky 1.7.2 ReflectorClass causing mixin issues, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
tildejustin committed Jan 15, 2024
1 parent f2fa71e commit 9387e66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.lang.reflect.Field;

// suppresses some warnings in the logs
@Pseudo
@Mixin(targets = "ReflectorClass")
public class ReflectorClassMixin {
@Shadow
private String targetClassName;

@Shadow
private boolean checked;

@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = "getTargetClass", at = @At("HEAD"), remap = false)
private void getTargetClass(CallbackInfoReturnable<Class<?>> infoReturnable) {
String targetClassName = this.getTargetClassName();
if (!this.checked) { // only check the target if it hasn't been done yet
String name = this.targetClassName.replaceAll("/", ".");
String name = targetClassName.replaceAll("/", ".");
if (name.startsWith("net.minecraft.launchwrapper") || name.startsWith("net.minecraftforge") || "optifine.OptiFineClassTransformer".equals(name)) {
this.checked = true;
}
}
}

@Unique
private String getTargetClassName() {
try {
Field targetClass = this.getClass().getDeclaredField("targetClassName");
targetClass.setAccessible(true);
return (String) targetClass.get(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
try {
// 1.7.2 behavior
Field targetClass = this.getClass().getDeclaredField("targetClassNames");
targetClass.setAccessible(true);
return ((String[]) targetClass.get(this))[0];
} catch (NoSuchFieldException | IllegalAccessException ex) {
throw new RuntimeException(ex);
}
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.caching=false
minecraft_version=1.3.2
target_version=1.3-1.13.2
yarn_build=533
mod_version=2.3.0
mod_version=2.3.1
archives_name=optifabric
maven_group=me.modmuss50
fabric_loader_version=0.15.3
Expand Down

0 comments on commit 9387e66

Please sign in to comment.