This is an old revision of the document!
Table of Contents
This is a WIP Effort of GauntRecluse to attempt to rewrite Mixin Examples with improved structure, more detailed examples, and additional examples that cover topics such as MixinExtras
@WrapOperation
or Expressions.
Mixin Examples (DRAFT)
This is not intended for first learning how to use certain Mixin tools entirely, moreso, it is meant to illustrate syntax, and explain the different elements of it. It is meant to still be a step above a simple cheat sheet in terms of detailing and explanations, as certain cheat sheet lack any contextual elements and may lead to confusing or otherwise harmful lacks of detail.
One should read the introduction page if they have not already. Further reading of external resources can be found at the bottom of this page.
General Injection
TODO: This section will cover injection related examples that do not fit into any other category
Injecting at the head of a method
Injecting at the tail of a method
TODO: Specify difference between the end of a method block and its “tail”, the last return statement, or the last operation in a void method.
Injecting after the target via shifting
TODO: Shift.AFTER; mention that it's the only really relevant shifting.
Targeting Tools
TODO: This section will cover targeting using tools other than injection point references, notably Slices and Expressions
Narrowing with a Slice
TODO: @Slice; This should mention that from
is by default “HEAD” and to
is by default “TAIL”
Targeting an Expression
TODO: This will likely just link back to the MixinExtras Wiki's relevant article, at least at first, as it has much more comprehensive examples, and creating similarly comprehensive examples will require a lot of care.
This tool is included in MixinExtras 0.5.0 and onward, which is included in Fabric Loader 0.17.0 and onward; it also requires a specific setup beforehand.
==== Using ordinals ====
TODO: This will need a notification that it is more brittle than slices and expressions.
—-
===== Redirecting =====
TODO: This section will cover redirectors, though this is a low priority given their obsolescence relative to MixinExtras WrapOps and MEVs
Redirecting's only remaining purpose is to create a crash in the case of another mod trying to redirect the same call or otherwise using such incompatibilities. One should favor MixinExtras injectors where redirectors would have been relevant before.
==== Redirect a method call ====
TODO: @Redirect
==== Redirecting a constant ====
TODO: @ModifyConstant
—-
===== Overwriting =====
TODO: This will very briefly go over using method overwrites, but this obviously is the lowest priority given it is nearly absolutely never needed to overwrite a method.
Overwriting is almost never necessary, and should only be used as a last resort, as it replaces a whole method. It is heavily recommended to gather second opinions before committing to a Mixin Overwrite.
===== Further Reading =====
* Sponge Mixin Wiki
* MixinExtras Wiki
* Mixin JavaDoc