tutorial:mixin_accessors
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:mixin_accessors [2025/08/07 07:44] – Fix formatting earthcomputer | tutorial:mixin_accessors [2025/10/17 13:47] (current) – Add warnings for outdated examples, use yarncode plugin for most refs to vanilla code. gauntrecluse | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== | 
| - | Mixin accessors | + | FIXME //This page is under revison. This page may change suddenly | 
| + | |||
| + | **Accessor Mixins** are special mixins defined as interfaces which must **only** contain '' | ||
| + | |||
| + | The '' | ||
| + | |||
| + | Unlike typical injectors, accessors do not prefix the merged methods with the modid of the mod that contains them. Additionally as the **Accessor Mixins** are used in user code, the names of the handlers are not mangled, these differences are important to keep in mind when writing **Accessor Mixins** for compatibility and debugging purposes. | ||
| + | |||
| + | '' | ||
| ===== Accessor ===== | ===== Accessor ===== | ||
| - | '' | + | '' | 
| ==== Getting a value from the field ==== | ==== Getting a value from the field ==== | ||
| - | <code java> | + | <yarncode | 
| - | @Mixin(MinecraftClient.class) | + | @Mixin(class_310.class) | 
| - | public interface | + | public interface | 
| - | @Accessor | + | @Accessor(" | 
| - | int getItemUseCooldown(); | + | int modid$getItemUseCooldown(); | 
| } | } | ||
| - | </code> | + | </yarncode> | 
| Usage: | Usage: | ||
| - | <code java> | + | <yarncode | 
| - | int itemUseCooldown | + | int field_1752 | 
| - | </code> | + | </yarncode> | 
| ==== Setting a value to the field ==== | ==== Setting a value to the field ==== | ||
| - | <code java> | + | <yarncode | 
| - | @Mixin(MinecraftClient.class) | + | @Mixin(class_310.class) | 
| - | public interface | + | public interface | 
| - | @Accessor(" | + | @Accessor(" | 
| - |  | + | void modid$setItemUseCooldown(int | 
| } | } | ||
| - | </code> | + | </yarncode> | 
| Usage: | Usage: | ||
| - | <code java> | + | <yarncode | 
| - | ((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100); | + | ((class_310Accessor) class_310.method_1551()).modid$setItemUseCooldown(100); | 
| - | </code> | + | </yarncode> | 
| - | When the field is final and you need to set it, use '' | + | When the field is final and you need to set it, use '' | 
| ===== Accessor for static fields ===== | ===== Accessor for static fields ===== | ||
| - | Suppose we want to access '' | + | FIXME // | 
| + | Suppose we want to access | ||
| ==== Getting a value from the field ==== | ==== Getting a value from the field ==== | ||
| Line 45: | Line 54: | ||
| public interface VanillaLayeredBiomeSourceAccessor { | public interface VanillaLayeredBiomeSourceAccessor { | ||
| @Accessor(" | @Accessor(" | ||
| - |  | + | static List< | 
| throw new AssertionError(); | throw new AssertionError(); | ||
| } | } | ||
| Line 54: | Line 63: | ||
| <code java> | <code java> | ||
| - | List< | + | List< | 
| </ | </ | ||
| Line 62: | Line 71: | ||
| public interface VanillaLayeredBiomeSourceAccessor { | public interface VanillaLayeredBiomeSourceAccessor { | ||
| @Accessor(" | @Accessor(" | ||
| - |  | + | static void modid$setBiomes(List< | 
| throw new AssertionError(); | throw new AssertionError(); | ||
| } | } | ||
| Line 71: | Line 80: | ||
| <code java> | <code java> | ||
| - | VanillaLayeredBiomeSourceAccessor.setBiomes(biomes); | + | VanillaLayeredBiomeSourceAccessor.modid$setBiomes(biomes); | 
| </ | </ | ||
| + | |||
| + | When the field is final and you need to set it, use '' | ||
| ===== Invoker ===== | ===== Invoker ===== | ||
| - | '' | + | '' | 
| - | <code java> | + | <yarncode | 
| - | @Mixin(EndermanEntity.class) | + | @Mixin(class_1560.class) | 
| - | public interface | + | public interface | 
| - | @Invoker(" | + | @Invoker(" | 
| - |  | + | boolean | 
| } | } | ||
| - | </code> | + | </yarncode> | 
| Usage: | Usage: | ||
| - | <code java> | + | <yarncode | 
| - | EndermanEntity | + | class_1560 | 
| - | ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, | + | ((class_1560Invoker) enderman).modid$invokeTeleportTo(0.0D, | 
| - | </code> | + | </yarncode> | 
| ===== Invoker for static methods ===== | ===== Invoker for static methods ===== | ||
| + | FIXME //This example is not fully accurate to latest versions, '' | ||
| Suppose we want to invoke '' | Suppose we want to invoke '' | ||
| Line 99: | Line 111: | ||
| public interface BrewingRecipeRegistryInvoker { | public interface BrewingRecipeRegistryInvoker { | ||
| @Invoker(" | @Invoker(" | ||
| - |  | + | static void modid$invokeRegisterPotionType(Item item) { | 
| throw new AssertionError(); | throw new AssertionError(); | ||
| } | } | ||
| Line 108: | Line 120: | ||
| <code java> | <code java> | ||
| - | BrewingRecipeRegistryInvoker.invokeRegisterPotionType(item); | + | BrewingRecipeRegistryInvoker.modid$invokeRegisterPotionType(item); | 
| </ | </ | ||
tutorial/mixin_accessors.1754552683.txt.gz · Last modified: 2025/08/07 07:44 by earthcomputer
                
                