Skip to content

Mixins

Mixins are a powerful tool used to modify the compiled bytecode of Minecraft as it loads. This allows modders to inject custom code, change existing game logic, read private variables or completely overwrite existing methods.

Because Minecraft’s source code is “read-only” and compiled, you cannot just rewrite a core game class in your mod. Instead, Mixins use Java annotations to tell the Mixin processor exactly where, when, and how to change the game’s compiled bytecode. Common Types of Mixins:

@Inject

This is the most common method. It inserts your custom code right at the head, tail, or before/after specific method calls.

@ModifyVariable / @ModifyArg

Used to intercept and change the value of variables or method arguments before they are processed by vanilla code.

@Redirect

Replaces a specific method call or field access in the vanilla game with your own custom method call.

@Accessor / @Invoker

Used to make private or protected fields and methods from Minecraft’s source code accessible and usable in your mod’s codebase.

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin {
@Inject(method = "jump", at = @At("HEAD"))
private void onJump(CallbackInfo ci) {
// custom code here, for example printing
// a message when the player jumps
}
}