Annotation Interface WrapOperation


@Target(METHOD) @Retention(RUNTIME) public @interface WrapOperation
Allows you to wrap a method call, field get/set, instanceof check, or object instantiation.

Your handler method receives the targeted instruction's arguments and an Operation representing the operation being wrapped (optionally followed by the enclosing method's parameters). You should return the same type as the wrapped operation does:

Targeted operation Handler signature
Non-static method call private (static) ReturnType handler(ReceiverType instance, <params of the original call>, Operation<ReturnType> original)
super. method call private (static) ReturnType handler(ThisClass instance, <params of the original call>, Operation<ReturnType> original)
Static method call private (static) ReturnType handler(<params of the original call>, Operation<ReturnType> original)
Non-static field get private (static) FieldType handler(ReceiverType instance, Operation<FieldType> original)
Static field get private (static) FieldType handler(Operation<FieldType> original)
Non-static field write private (static) void handler(ReceiverType instance, FieldType newValue, Operation<Void> original)
Static field write private (static) void handler(FieldType newValue, Operation<Void> original)
instanceof check private (static) boolean handler(Object obj, Operation<Boolean> original)
Object instantiation private (static) ObjectType handler(<params of the original ctor>, Operation<ObjectType> original)
When calling the original, you must pass everything before the original in your handler's parameters. You can optionally pass different values to change what the original uses.

This chains when used by multiple people, unlike @Redirect and @ModifyConstant.

If you never call the original then you risk other people's code being silently ignored.

See the wiki article for more info.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
     
    org.spongepowered.asm.mixin.injection.At[]
    Selector for targeting method calls, field gets/sets and object instantiations.
    org.spongepowered.asm.mixin.injection.Constant[]
    Selector for targeting `instanceof`s.
    int
     
    boolean
     
    int
     
    org.spongepowered.asm.mixin.injection.Slice[]
     
  • Element Details

    • at

      org.spongepowered.asm.mixin.injection.At[] at
      Selector for targeting method calls, field gets/sets and object instantiations.
      Default:
      {}
    • constant

      org.spongepowered.asm.mixin.injection.Constant[] constant
      Selector for targeting `instanceof`s.
      Default:
      {}
    • slice

      org.spongepowered.asm.mixin.injection.Slice[] slice
      Default:
      {}
    • remap

      boolean remap
      Default:
      true
    • require

      int require
      Default:
      -1
    • expect

      int expect
      Default:
      1
    • allow

      int allow
      Default:
      -1