MinecraftDev icon indicating copy to clipboard operation
MinecraftDev copied to clipboard

Unable to Locate Mixin Target Reference for Anonymous Inner Class of Inner Enum

Open ByThePowerOfScience opened this issue 1 year ago • 0 comments

Minecraft Development for IntelliJ plugin version

2023.1-1.6.4

IntelliJ version

2023.1

Operating System

Mac OSX 12

Target platform

Mixins

Description of the bug

This is a very niche case, so I totally understand why the plugin misses this, but it should be relatively(?) easy to fix.

Overview

The plugin is unable to find a valid Mixin target in the source for an anonymous inner class of an inner enum class. It can locate the inner class' method if you target the inner enum itself, but it cannot locate the anonymous inner class. It gives an "UnresolvedMixinReference" warning despite the Mixin working properly at runtime.

It seems that the plugin just isn't able to locate the bytecode of the anonymous inner class of the inner class.

Minimum Reproducible Example:

NOTE: This requires the target class to be precompiled and in a separate jar than the Mixin, as the plugin cannot validate Mixins within the same project since there's no bytecode to work off of.

This example is also version-agnostic, as it appears to be a class location issue.

Target class:

package a.pkg;

public class Foo {
	public static enum Bar {
		ONE() {
			@Override
			public float method1() { // The target
				return 1f;
			}
		};
		public float method1() { return 0f; }
	}
}

Mixin

@Mixin(targets="a/pkg/Foo$Bar$1") // Sidebar shortcut cannot find source
public abstract class MyMixin {
	@Inject(
		remap=false,
		method="method1", // ERROR: Cannot find target method
		at=@At("HEAD")
	)
	public void injector(CallbackInfoReturnable<Float> cir) {
		// <...>
	}
}

The target and shortcuts can be identified if we either change our target to targets="a/pkg/Foo$Bar" or by revising the target class to have Bar on the top level (thus changing our target to targets="a/pkg/Bar$1"), but the method and shortcuts only break in our example case here.

Specific Example

Target Class

https://github.com/rwtema/Extra-Utilities-2-Source/blob/master/1.10.2/src/main/java/com/rwtema/extrautils2/blocks/BlockPassiveGenerator.java#L487

Mixin

@Mixin(targets="com/rwtema/extrautils2/blocks/BlockPassiveGenerator$GeneratorType$9")
public abstract class MDragonEgg {
	@Inject(
		remap=false,
		method="basePowerGen",
		at=@At("HEAD")
	)
	public void basePowerGen(CallbackInfoReturnable<Float> cir) {}
}

ByThePowerOfScience avatar May 03 '23 01:05 ByThePowerOfScience