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 [2020/08/29 14:46] – Fix a bug siglong | tutorial:mixin_accessors [2022/04/29 09:54] (current) – [Mixin Accessors] solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Mixin Accessors ====== | + | ====== Mixin Accessors |
+ | Mixin accessors and invokers allow you to access fields or invoke methods that are not visible (private) or final. | ||
- | ===== Introduction | + | ===== Accessor |
- | Mixin Accessors allow you to access fields and methods that are not visible (private) or final. | + | |
- | + | ||
- | ==== Accessor | + | |
'' | '' | ||
- | === Getting a value from the field === | + | ==== Getting a value from the field ==== |
<code java> | <code java> | ||
@Mixin(MinecraftClient.class) | @Mixin(MinecraftClient.class) | ||
public interface MinecraftClientAccessor { | public interface MinecraftClientAccessor { | ||
- | @Accessor(" | + | @Accessor |
- | | + | int getItemUseCooldown(); |
} | } | ||
</ | </ | ||
Line 22: | Line 20: | ||
</ | </ | ||
- | === Setting a value to the field === | + | ==== Setting a value to the field ==== |
<code java> | <code java> | ||
@Mixin(MinecraftClient.class) | @Mixin(MinecraftClient.class) | ||
Line 37: | Line 35: | ||
</ | </ | ||
- | ==== Invoker ==== | + | ===== Accessor for static fields ===== |
+ | Suppose we want to access '' | ||
+ | |||
+ | ==== Getting a value from the field ==== | ||
+ | <code java> | ||
+ | @Mixin(VanillaLayeredBiomeSource.class) | ||
+ | public interface VanillaLayeredBiomeSourceAccessor { | ||
+ | @Accessor(" | ||
+ | public static List< | ||
+ | throw new AssertionError(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Usage: | ||
+ | |||
+ | <code java> | ||
+ | List< | ||
+ | </ | ||
+ | |||
+ | ==== Setting a value to the field ==== | ||
+ | <code java> | ||
+ | @Mixin(VanillaLayeredBiomeSource.class) | ||
+ | public interface VanillaLayeredBiomeSourceAccessor { | ||
+ | @Accessor(" | ||
+ | public static void setBiomes(List< | ||
+ | throw new AssertionError(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Usage: | ||
+ | |||
+ | <code java> | ||
+ | VanillaLayeredBiomeSourceAccessor.setBiomes(biomes); | ||
+ | </ | ||
+ | |||
+ | ===== Invoker | ||
'' | '' | ||
Line 55: | Line 90: | ||
</ | </ | ||
+ | ===== Invoker for static methods ===== | ||
+ | Suppose we want to invoke '' | ||
+ | |||
+ | <code java> | ||
+ | @Mixin(BrewingRecipeRegistry.class) | ||
+ | public interface BrewingRecipeRegistryInvoker { | ||
+ | @Invoker(" | ||
+ | public static void invokeRegisterPotionType(Item item) { | ||
+ | throw new AssertionError(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Usage: | ||
+ | |||
+ | <code java> | ||
+ | BrewingRecipeRegistryInvoker.invokeRegisterPotionType(item); | ||
+ | </ |
tutorial/mixin_accessors.1598712385.txt.gz · Last modified: 2020/08/29 14:46 by siglong