User Tools

Site Tools


tutorial:mixin_accessors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:mixin_accessors [2022/04/29 09:54] – [Mixin Accessors] solidblocktutorial:mixin_accessors [2025/08/07 07:48] (current) – Add note about mutable to static accessors too, and note about javac inlining fields. earthcomputer
Line 34: Line 34:
 ((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100); ((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100);
 </code> </code>
 +
 +When the field is final and you need to set it, use ''@Mutable'' as well. Note that this may not work as expected if the field is set to a constant literal value in its initializer, such as ''42'' or ''"Hello World"''. This is because ''javac'' inlines constant fields.
  
 ===== Accessor for static fields ===== ===== Accessor for static fields =====
Line 71: Line 73:
 VanillaLayeredBiomeSourceAccessor.setBiomes(biomes); VanillaLayeredBiomeSourceAccessor.setBiomes(biomes);
 </code> </code>
 +
 +When the field is final and you need to set it, use ''@Mutable'' as well. Note that this may not work as expected if the field is set to a constant literal value in its initializer, such as ''42'' or ''"Hello World"''. This is because ''javac'' inlines constant fields.
  
 ===== Invoker ===== ===== Invoker =====
tutorial/mixin_accessors.1651226043.txt.gz · Last modified: 2022/04/29 09:54 by solidblock