Mixins
Mixins are a core technology used by the Quilt ecosystem to modify Minecraft’s compiled bytecode as the game starts. They allow mods to inject custom code, modify existing behavior, access private members, or replace parts of the game’s implementation without directly editing Minecraft itself.
How and why Quilt uses Mixins
Section titled “How and why Quilt uses Mixins”Since Minecraft is compiled and its classes cannot be modified directly, Quilt mods use the SpongePowered Mixin framework to patch the game’s bytecode at runtime. Mixins rely on Java annotations to specify exactly where and how code should be injected.
Common Types of Mixins:
@InjectInjects custom code at the beginning, end, or another specified location within an existing method.
@ModifyVariable / @ModifyArg
Intercepts and modifies local variables or method arguments before they are used by Minecraft.
@RedirectRedirects a specific method call or field access to your own implementation.
@Accessor / @Invoker
Provides access to private or protected fields and methods without modifying their visibility.
Example
Section titled “Example”@Mixin(PlayerEntity.class)public abstract class PlayerEntityMixin { @Inject(method = "jump", at = @At("HEAD")) private void onJump(CallbackInfo ci) { // Runs whenever the player jumps. }}@Mixin(PlayerEntity::class)abstract class PlayerEntityMixin { @Inject(method = "jump", at = At("HEAD")) private fun onJump(ci: CallbackInfo) { // Runs whenever the player jumps. }}