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/11/26 14:17] – Removed FIXME header as the page seems overall accurate to the topic now. gauntrecluse | tutorial:mixin_accessors [2025/11/30 20:08] (current) – gauntrecluse | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| 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. | 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. | ||
| - | '' | + | '' |
| + | Prefixing accessor or invoker handlers is not necessary if they are static, as those may not conflict, and the stacktrace provides the Mixin class whose handlers are involved in errors, thus making it sufficient without needing to prefix with the modid. | ||
| ===== Accessor ===== | ===== Accessor ===== | ||
| Line 53: | Line 54: | ||
| public interface VanillaLayeredBiomeSourceAccessor { | public interface VanillaLayeredBiomeSourceAccessor { | ||
| @Accessor(" | @Accessor(" | ||
| - | static List< | + | static List< |
| throw new AssertionError(); | throw new AssertionError(); | ||
| } | } | ||
| Line 62: | Line 63: | ||
| <code java> | <code java> | ||
| - | List< | + | List< |
| </ | </ | ||
| Line 70: | Line 71: | ||
| public interface VanillaLayeredBiomeSourceAccessor { | public interface VanillaLayeredBiomeSourceAccessor { | ||
| @Accessor(" | @Accessor(" | ||
| - | static void modid$setBiomes(List< | + | static void setBiomes(List< |
| throw new AssertionError(); | throw new AssertionError(); | ||
| } | } | ||
| Line 79: | Line 80: | ||
| <code java> | <code java> | ||
| - | VanillaLayeredBiomeSourceAccessor.modid$setBiomes(biomes); | + | VanillaLayeredBiomeSourceAccessor.setBiomes(biomes); |
| </ | </ | ||
| Line 108: | Line 109: | ||
| <code java> | <code java> | ||
| @Mixin(BrewingRecipeRegistry.class) | @Mixin(BrewingRecipeRegistry.class) | ||
| - | public interface | + | public interface |
| @Invoker(" | @Invoker(" | ||
| - | static void modid$invokeRegisterPotionType(Item item) { | + | static void invokeRegisterPotionType(Item item) { |
| throw new AssertionError(); | throw new AssertionError(); | ||
| } | } | ||
| Line 119: | Line 120: | ||
| <code java> | <code java> | ||
| - | BrewingRecipeRegistryInvoker.modid$invokeRegisterPotionType(item); | + | BrewingRecipeRegistryAccessor.invokeRegisterPotionType(item); |
| + | </ | ||
| + | |||
| + | ==== Invoker for constructors ==== | ||
| + | |||
| + | Invokers for constructors must be static, pass ''"< | ||
| + | |||
| + | For example, we will use the '' | ||
| + | <code java> | ||
| + | @Mixin(Identifier.class) | ||
| + | public interface IdentifierAccessor { | ||
| + | @Invoker("< | ||
| + | static Identifier newIdentifier(String namespace, String path) { | ||
| + | throw new AssertionError(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Usage: | ||
| + | <code java> | ||
| + | Identifier exampleVariable = IdentifierAccessor.newIdentifier(" | ||
| </ | </ | ||
tutorial/mixin_accessors.1764166657.txt.gz · Last modified: 2025/11/26 14:17 by gauntrecluse