SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.41k stars 194 forks source link

@Coerse does not provide expected behavior for local variables #585

Closed CreativeMD closed 2 years ago

CreativeMD commented 2 years ago

Hey,

not sure if this a bug or a missing feature, but @Coerse does not have the expected functionality for local variables.

There is a local variable of the type ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResult. It's a package static class. So I cannot use it as a parameter. I got the suggestion to use @Coerce Object, but to their surprise this did not fix the issue.

Code:

@Mixin(targets = "net/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask")
public abstract class RebuildTaskMixin {

    @Inject(at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Lists;newArrayList()Ljava/util/ArrayList;", remap = false),
            method = "doTask(Lnet/minecraft/client/renderer/ChunkBufferBuilderPack;)Ljava/util/concurrent/CompletableFuture;", locals = LocalCapture.CAPTURE_FAILHARD, require = 1)
    private void rebuild(ChunkBufferBuilderPack pack, CallbackInfo info, Vec3 vec, float x, float y, float z, @Coerce Object results, CompiledChunk compiled) {
        System.out.println("Does not work");
    }

}

Error:

 Expected: [Lnet/minecraft/world/phys/Vec3;, F, F, F, Ljava/lang/Object;, Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;]
    Found: [Lnet/minecraft/world/phys/Vec3;, F, F, F, Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;, Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;]
Available: [Lnet/minecraft/world/phys/Vec3;, F, F, F, Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;, Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;]

I'm not sure if this annotation is supposed to fix it. In my case it does not work for local variables, but it works fine to get the method parameters. The example below works just fine:

    @Inject(at = @At("HEAD"),
            method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V",
            require = 1)
    private void handleBlockEntity(@Coerce Object object, BlockEntity block, CallbackInfo info) {
        System.out.println("Does works");
    }