Invalid Interface Injection pretends to work in fabric dev environment
Closed this issue ยท 3 comments
Tested with MC 1.20.1, fabric 1.16.9, loop 1.9-SNAPSHOT, on intellij.
How to reproduce:
- Go through all the steps to inject an interface EXCEPT making the mixin. Say, into Enchantment.class
- Give the interface a default method and nothing else (probably not a required step)
- DO NOT create a mixin for the interface. The only usage of the interface so far should be in the fabric.mod.json
- somewhere else in the mod, check to see if the interface has been injected properly. In this example, you could hook into a player attacking with an enchanted item, and have something that logs a message if the enchantment extends your injected interface.
Expected behavior: Both in the fabric dev environment and when you build the mod and run it, say, in modrinth, the interface should fail to inject and the logging should say that no Enchantment extends your interface.
Actual behavior: In the development environment, the interface is successfully injected, even with no mixin. However, in the real environment it does not inject.
Main problem: Modders who do interface injection without the proper mixin will think that their mod works when it in fact does not.
Use case where it came up for me:
- I made Enchantment.class extends MyEnchantmentInterface. It had a default method that I wanted to override for a specific enchantment.
- When I created "MyEnchantment extends Enchantment" the class, I wrote a method override to extend the interface.
- I needed to also create the empty mixin @mixin(Enchantment.class) public interface MyMixin extends MyEnchantmentInterface {}
- But I forgot, and encountered reports of a bug I could not reproduce until I added more logging, read the discord logs, and realized the mixin was required.
TLDR interface injection works great and actually does inject the interface even without any mixins but only in the dev environment.
A modder who forgets their mixin may end up confused
This is working as expected as interface injection is fully handled by loom. The interfaces defined in your fabric.mod.json are only read by loom and not in production, this is where the mixin comes in. You must have a mixin alongside your injected interface for it to work.
This will change in the near future with injected interfaces defined in class tweaker.