User Tools

Site Tools


tutorial:mixin_accessors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:mixin_accessors [2020/08/28 08:14] – Fix minor error siglongtutorial:mixin_accessors [2020/08/30 10:15] – Restore old revision siglong
Line 5: Line 5:
  
 ==== Accessor ==== ==== Accessor ====
-''@Accessor'' allows you to access fields.+''@Accessor'' allows you to access fields. Suppose we want to access ''itemUseCooldown'' field of ''MinecraftClient'' class.
  
-=== Get a value from field ===+=== Getting a value from the field ===
 <code java> <code java>
 @Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
Line 22: Line 22:
 </code> </code>
  
-=== Set a value to field ===+=== Setting a value to the field ===
 <code java> <code java>
 @Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
Line 37: Line 37:
 </code> </code>
  
-==== Provider ==== +==== Invoker ==== 
-''@Provider'' allows you to access methods.+''@Invoker'' allows you to access methods. Suppose we want to invoke ''teleportTo'' method of ''EndermanEntity'' class.
  
 <code java> <code java>
 @Mixin(EndermanEntity.class) @Mixin(EndermanEntity.class)
 public interface EndermanEntityInvoker { public interface EndermanEntityInvoker {
-  @Provider +  @Invoker("teleportTo") 
-  public boolean teleportTo(double x, double y, double z);+  public boolean invokeTeleportTo(double x, double y, double z);
 } }
 </code> </code>
Line 52: Line 52:
 <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);
 </code> </code>
  
tutorial/mixin_accessors.txt · Last modified: 2022/04/29 09:54 by solidblock