In the Minecraft modding API called Fabric (and I think most other Minecraft modding APIs) there is a feature called "mixins" which lets you do some things such as:
- Change the internal code of Minecraft by injecting code into function calls or even replacing function calls
@Mixin(TitleScreen.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
System.out.println("This line is printed by an example mod mixin!");
}
}
- Access private variables and call private functions within these mixins
@Mixin(MinecraftClient.class)
public interface MinecraftClientAccessor {
@Accessor("itemUseCooldown")
public void setItemUseCooldown(int itemUseCooldown);
}
I am making a modding API for a game I am working on. It will contain higher-level stuff like adding custom items to the game which don't require editing the internal code of the game, but I also want the API to be versatile enough that modders can do similar things as they could with Fabric mixins.
As I understand, this requires some kind of reflection behaviour which does not exist in Rust. However, I have seen people emulating reflection-ish things with procedural macros. Would it be possible to make something like Fabric mixins with procedural macros? If so, how? If not, are there any other methods that can achieve something similar to mixins in Rust?