tutorial:mixin_accessors
This is an old revision of the document!
Table of Contents
Mixin Accessors
Introduction
Mixin Accessors allow you to access fields and methods that are not visible (private) or final.
Accessor
@Accessor
allows you to access fields. Suppose we want to access itemUseCooldown
field of MinecraftClient
class.
Getting a value from the field
@Mixin(MinecraftClient.class) public interface MinecraftClientAccessor { @Accessor("itemUseCooldown") public int getItemUseCooldown(); }
Usage:
int itemUseCooldown = ((MinecraftClientAccessor) MinecraftClient.getInstance()).getItemUseCooldown();
Setting a value to the field
@Mixin(MinecraftClient.class) public interface MinecraftClientAccessor { @Accessor("itemUseCooldown") public void setItemUseCooldown(int itemUseCooldown); }
Usage:
((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100);
Invoker
@Invoker
allows you to access methods. Suppose we want to invoke teleportTo
method of EndermanEntity
class.
@Mixin(EndermanEntity.class) public interface EndermanEntityInvoker { @Invoker("teleportTo") public boolean invokeTeleportTo(double x, double y, double z); }
Usage:
EndermanEntity enderman = ...; ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, 70.0D, 0.0D);
tutorial/mixin_accessors.1598782524.txt.gz · Last modified: 2020/08/30 10:15 by siglong