Mixin
Mixin copied to clipboard
Capturing locals out of current scope
I'm not sure if this is the correct place to post this report, I think so. The issue started in fabric loader 0.12 and above. For reference the example is with minecraft 1.17.1.
Issue: mixin is trying/requiring locals out of the current scope and this causes a verification error.
I'm trying to inject right before the second swingHand
@Inject(method={"doItemUse"}, at={@At(value="INVOKE", target="net/minecraft/client/network/ClientPlayerEntity.swingHand(Lnet/minecraft/util/Hand;)V", ordinal = 1)}, locals=LocalCapture.CAPTURE_FAILHARD)
This does, only inject right before the second swingHand.
When I tell mixin to print the locals, it gives this
private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {
-
It's suggesting Entity entity, ActionResult actionResult which is out of the current scope
-
When I use it's suggestion of the locals it crashes with an error
-
When I use the correct locals
private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {
, it crashes, saying it expects what I said in#1
This is the mixin
@Inject(method={"doItemUse"}, at={@At(value="INVOKE", target="net/minecraft/client/network/ClientPlayerEntity.swingHand(Lnet/minecraft/util/Hand;)V", ordinal = 1)}, locals=LocalCapture.CAPTURE_FAILHARD)
private void onBlockUse(CallbackInfo callbackInfo, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {
//private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {
System.out.println("epic");
}
Does your mod declare a dependency on Fabric Loader 0.12+? Does the behavior change if that changes?
It happens on the newest version
modImplementation "net.fabricmc:fabric-loader:0.12.12"
I investigated the issue a little more and it's really wack, using minecraft 1.14.4, wit fabric loader 0.12.0, the issue persists, but using fabric loader 0.11.7, it works as intended, capturing the correct locals.
Then when I test with minecraft 1.16/1.17. The issue persists on what seems to be all fabric loader versions... 😕
Basically, to my knowledge if you want to test/replicate the issue, you should be able to use an example mod for 1.17, create a mixin for MinecraftClient. Add this method
@Inject(method = { "doItemUse" }, at = { @At(value = "INVOKE", target = "net/minecraft/client/network/ClientPlayerEntity.swingHand(Lnet/minecraft/util/Hand;)V", ordinal = 1) }, locals = LocalCapture.PRINT)
private void onBlockUse(CallbackInfo callbackInfo) {
}
Run the game, it will print
/** */
/* * Expected callback signature */
/* * / */
/* private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) { */
/* // Method body */
/* }
Which is incorrect?(Am I wrong?) It should be
/** */
/* * Expected callback signature */
/* * / */
/* private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) { */
/* // Method body */
/* }
(Entity, and the first ActionResult are not in the current scope?)
Regardless of what it should/shouldn't be, if you change the mixin to CAPTURE_FAILHARD
and use it's expected parameters the game crashes.
I need to know what dependencies your fabric.mod.json declares on Loader, it controls the mixin locals algorithm being used. If you depend on a loader version >= 0.12, it'll use the same as current upstream, if you don't have a dependency on Loader or one starting below 0.12 it uses the old algorithm for compatibility.
I tried "fabricloader": ">=0.12.12"
it still crashes, I created a repo https://github.com/THEREALWWEFAN231/fabric-example-mod based off the 1.18 example mod, everything is up to date(to my knowledge). Maybe it can give you more insight on the issue.