I’m new to Minecraft modding, and I’m learning to modify Minecraft source code with Fabric and Mixin. I just added a sanity level to PlayerEntity
(SanityManager
is my custom class, and I use Yarn 1.21.4 mapping):
...
@Mixin(PlayerEntity.class) public abstract class PlayerEntityMixin{
@Unique protected SanityManager sanityManager=new SanityManager();
@Unique public SanityManager getSanityManager(){
return sanityManager;
}
...
}
Then I wanted to display it on HUD, which is managed in InGameHud
, I thought. I started mixing-in in another class:
...
@Mixin(InGameHud.class) public abstract class InGameHudMixin{
...
@Unique private void renderSanity(DrawContext context,PlayerEntity player,int top,int right){
SanityManager sanityManager=player.getSanityManager();//Cannot compile
}
}
But when I was trying to get the SanityManager
of a PlayerEntity
got from arguments, I found that it was the vanilla PlayerEntity
syntactically, even though it will be mixed-in my custom method at runtime, so I couldn’t call getSanityManager()
directly on PlayerEntity
.
I thought transforming it might solve this, but which class should I transform it to ?
I also considered @Shadow
, but it can only shadow members in currently mixing-in vanilla class.
Please tell me how to call getSanityManager()
from renderSanity(...)
.