User Tools

Site Tools


tutorial:mixin_redirectors

Mixin redirectors

introduction

Redirectors are methods that can replace method invocations, field accesses, object creation, and instanceof checks. Redirectors are declared by @Redirect annotations and generally look like this:

  1. @Redirect(method = "${signatureOfMethodInWhichToRedirect}",
  2. at = @At(value = "${injectionPointReference}", target = "${signature}"))
  3. public ReturnType redirectSomeMethod(Arg0Type arg0, Arg1Type arg1) {
  4. MyClass.doMyComputations();
  5.  
  6. return computeSomethingElse();
  7. }

:!: Redirectors of all kinds work by redirecting the target to your handler method. This causes a hard incompatibility if another mod tries to redirect the same target as this makes it impossible to chain or nest redirects. This makes @WrapOperation and @ModifyExpressionValue from MixinExtras preferable for all use-cases where the developer does not directly intend for an incompatibility. You can find more information about those alternatives on the Official MixinExtras Wiki.

Refer to the specific redirection tutorials for information about injection point references:

tutorial/mixin_redirectors.txt · Last modified: 2025/09/22 22:21 by gauntrecluse