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/25 10:39] – Rewrite whole page, adding Provider 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 | + | '' |
- | ==== Accessor ==== | + | ==== Getting |
- | '' | + | |
- | + | ||
- | === Set a value to a 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: | ||
</ | </ | ||
- | === Get a value from a field === | + | ==== Setting |
<code java> | <code java> | ||
@Mixin(MinecraftClient.class) | @Mixin(MinecraftClient.class) | ||
Line 37: | Line 35: | ||
</ | </ | ||
- | ==== Provider | + | ===== 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 ===== | ||
+ | '' | ||
<code java> | <code java> | ||
@Mixin(EndermanEntity.class) | @Mixin(EndermanEntity.class) | ||
public interface EndermanEntityInvoker { | public interface EndermanEntityInvoker { | ||
- | @Provider | + | @Invoker(" |
- | public boolean | + | public boolean |
} | } | ||
</ | </ | ||
Line 52: | Line 87: | ||
<code java> | <code java> | ||
EndermanEntity enderman = ...; | EndermanEntity enderman = ...; | ||
- | ((EndermanEntityInvoker) enderman).teleportTo(0.0D, 70.0D, 0.0D); | + | ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, 70.0D, 0.0D); |
</ | </ | ||
+ | ===== 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.1598351960.txt.gz · Last modified: 2020/08/25 10:39 by siglong