Mixin icon indicating copy to clipboard operation
Mixin copied to clipboard

Unable to access inner class, @Shadow does not seem to support it

Open brunogenovese opened this issue 3 years ago • 1 comments

This might simply be a matter of not finding the right documentation, if so I would greatly appreciate if you can point me to it.

Problem:

  • Simply attempting to access an inner class while in a mixin, for example
  • ModelLoader.ModelDefinition x = new ModelLoader.ModelDefinition(myUnbakedModelList, myValues);
    
  • The compiler message is: "net.minecraft.client.render.model.ModelLoader.ModelDefinition' has private access in 'net.minecraft.client.render.model.ModelLoader"

Attempted solutions and their problems:

  1. Add @Shadow static class ModelDefinition; to the mixin:
  • Compiler message: "Inner classes are only allowed if they are also @Mixin classes"
  1. Create a Mixin for the inner class: @Mixin(ModelLoader.ModelDefinition.class) public class ModelLoaderMixinModelDefinition { } -Get the same "private access" error on ModelDefinition. The error message in (1) seems to indicate that "there is a way" to make a mixin for an inner class but it is not clear what that is.

Conclusion: A) If there is already mixin support for accessing inner classes, some documentation is necessary. B) If there is no mixing support for accessing inner classes, it might be a good idea to add the functionality.

brunogenovese avatar May 15 '22 16:05 brunogenovese

You can mixin to classes you're not allowed to access by passing the string name of the class:

@Mixin(targets = { "net.minecraft.client.render.model.ModelLoader$ModelDefinition" })
public class ModelDefinitionMixin {
}

However, depending on how much you need to access, there's a good chance you will still want to use an access transformer/widener to make the inner class public first. For example, you still can't declare any variables with that class as a type since you aren't supposed to have access to it.

embeddedt avatar May 22 '22 18:05 embeddedt