Accessor〔アクセサ〕と Invoker〔インヴォーカ〕を使うと、通常はアクセスできない(private な)フィールドにアクセスしたり、メソッドを呼び出したりすることができます。
@Accessor はフィールドにアクセスすることを可能にします。例として、MinecraftClient クラスの itemUseCooldown フィールドにアクセスすることを考えます。
@Mixin(MinecraftClient.class) public interface MinecraftClientAccessor { @Accessor int getItemUseCooldown(); }
使い方:
int itemUseCooldown = ((MinecraftClientAccessor) MinecraftClient.getInstance()).getItemUseCooldown();
@Mixin(MinecraftClient.class) public interface MinecraftClientAccessor { @Accessor("itemUseCooldown") public void setItemUseCooldown(int itemUseCooldown); }
使い方:
((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100);
例として、VanillaLayeredBiomeSource クラスの BIOMES フィールドにアクセスすることを考えます。
@Mixin(VanillaLayeredBiomeSource.class) public interface VanillaLayeredBiomeSourceAccessor { @Accessor("BIOMES") public static List<RegistryKey<Biome>> getBiomes() { throw new AssertionError(); } }
使い方:
List<RegistryKey<Biome>> biomes = VanillaLayeredBiomeSourceAccessor.getBiomes();
@Mixin(VanillaLayeredBiomeSource.class) public interface VanillaLayeredBiomeSourceAccessor { @Accessor("BIOMES") public static void setBiomes(List<RegistryKey<Biome>> biomes) { throw new AssertionError(); } }
使い方:
VanillaLayeredBiomeSourceAccessor.setBiomes(biomes);
@Invoker はメソッドにアクセスすることを可能にします。例として、EndermanEntity クラスの teleportTo メソッドを呼び出すことを考えます。
@Mixin(EndermanEntity.class) public interface EndermanEntityInvoker { @Invoker("teleportTo") public boolean invokeTeleportTo(double x, double y, double z); }
使い方:
EndermanEntity enderman = ...; ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, 70.0D, 0.0D);
例として、BrewingRecipeRegistry クラスの registerPotionType メソッドを呼び出すことを考えます。
@Mixin(BrewingRecipeRegistry.class) public interface BrewingRecipeRegistryInvoker { @Invoker("registerPotionType") public static void invokeRegisterPotionType(Item item) { throw new AssertionError(); } }
使い方:
BrewingRecipeRegistryInvoker.invokeRegisterPotionType(item);