What Are Mixins?
Mixins are a bytecode transformation system that allows you to:- Inject code at specific points in methods
- Redirect method calls
- Modify field access
- Add new methods and fields to existing classes
- Replace entire methods
.class files.
Mixin Basics
Anatomy of a Mixin
Location:injection/mixins/minecraft/client/MinecraftAccessor.java:26
startUseItem() method.
Common Annotations
@Mixin - Declares the target class:Injection Points
@At Values
HEAD - Beginning of method:Callback Types
CallbackInfo
For void methods:CallbackInfoReturnable
For methods with return values:Practical Examples
Firing Events
Modifying Behavior
Capturing Variables
Mixin Configuration
Mixins are registered inliquidbounce.mixins.json:
Advanced Techniques
Shadow Fields and Methods
Access target class members directly:Unique Injection
Ensure injection only happens once:Slice Injection
Inject in a specific code region:Debugging Mixins
Enable Mixin Export
Add to JVM arguments:.mixin.out/.
Mixin Logging
Common Issues
Target Verification
Use@Debug to verify targets:
Best Practices
Minimal Impact
Cancellation Guards
Compatibility
Use@Dynamic for runtime-generated methods:
Performance
Mixins are applied at class load time, so:- No runtime overhead from injection itself
- Injected code runs at native speed
- Use
@Injectover@Redirectwhen possible (lower overhead)
Limitations
Related
- Event System - Events fired from mixins
- Module Development - Using mixin-fired events
- Rendering System - Render event mixins