SystemYou are an expert SpongePowered Mixin internals developer. You understand how mixins work at the bytecode level using ASM, and can debug, write, and optimize mixins.
You are an expert SpongePowered Mixin internals developer. You understand how mixins work at the bytecode level using ASM, and can debug, write, and optimize mixins.
User
How do you diagnose mixin injection failures? What are the most common error messages and their solutions?
Assistant
Mixin failures produce specific error messages that indicate the root cause. Here are the most common:
1. "Mixin failed to match target method"
java
// Error: @Inject(method = "tick") - target not found// Cause: Method name or descriptor mismatch// Fix: Verify method signature@Mixin(LivingEntity.class)publicclassMyMixin {
// WRONG: descriptor doesn't match@Inject(method = "tick", at = @At("HEAD"))privatevoidonTick(String arg) { } // tick()V takes no args!// CORRECT:@Inject(method = "tick", at = @At("HEAD"))privatevoidonTick(CallbackInfo ci) { }
}
2. "No injection point found"
java
// Error: Could not find injection point in target// Cause: @At target doesn't exist in the method// Fix: Use the correct injection point@Inject( method = "damage", at = @At( value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;applyArmorToDamage(...)F" // wrong method ))// Use correct target (check Yarn mappings):@At( value = "INVOKE", target = "Lnet/minecraft/entity/damage/DamageSource;getAmount()F")
3. "Injection point is ambiguous"
java
// Error: Multiple injection points match// Cause: ordinal not specified for duplicate calls// Fix: Specify ordinal or use slice@Inject( method = "tick", at = @At(value = "INVOKE", target = "...", ordinal = 1) // second occurrence)
4. "Mixin could not be applied"
java
// Error: mixin could not be applied to target class// Cause: Target class doesn't exist or wasn't loaded// Fix: Ensure target exists in the runtime environment@Mixin(value = TargetClass.class, remap = false)// disable remapping if needed
5. "Conflicting redirection"
java
// Error: Two mixins redirect the same call// Cause: Multiple @Redirect on same target// Fix: Use @WrapOperation instead, or coordinate with other mods@WrapOperation( method = "tick", at = @At(value = "INVOKE", target = "..."))privatefloatwrapHealth(Operation<Float> original) {
return original.call() * 2.0f;
}
Debugging checklist:
Check refmap generation - is it mapping correctly?
Verify Yarn mappings version matches Minecraft version
Use @Mixin(remap = false) for non-mapped targets
Add -Dmixin.debug=true JVM flag for verbose output
Check the mixin debug log at latest.log for injection details