Skip to content

Modifying class member variables in other mods. #2350

Answered by warjort
Desynq asked this question in Mod Dev Support
Discussion options

You must be logged in to vote

In case you want to know the real answer for future reference,
you should use an accessor
https://fabricmc.net/wiki/tutorial:mixin_accessors
which you will need to annotate as @Mutable to workaround the "final".

This is really just a quick way of writing a normal mixin with a shadowed mutable field and then adding your own interface to access the field.

However there is a gotcha. There is no guarantee the code using that final field actually accesses it at runtime.
The compiler is allowed to "inline" the values of static final fields into referencing methods at compile time.
So changing the value of the static final field will do nothing if that happens.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Desynq
Comment options

@warjort
Comment options

warjort Jun 21, 2022
Collaborator

@Desynq
Comment options

Answer selected by Desynq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants