Skip to content

Mixin Canceller

Bawnorton edited this page Aug 5, 2024 · 6 revisions

⚠️ Usage of MixinSquared on a maintained project is discouraged ⚠️
Making a PR or raising an issue would be more suitable

MixinSquared provides a way to cancel the application of Mixins that would normally be out of a user's control as other mod's mixins are not passed through their IMixinConfigPlugin.

If you wish to only cancel a specific injector, the Annotation Adjuster may be more suitable.

Implementation

Using the canceller is quite simple, all you need to do is implement the MixinCanceller interface and then register it.

public class YourModMixinCanceller implements MixinCanceller {
    @Override
    public boolean shouldCancel(List<String> targetClassNames, String mixinClassName) {
        return /* your own logic on whether to cancel mixins by their name or what they're targeting */;
    }
}

Registering

I am using Fabric

Inside your fabric.mod.json you will need to add the following entrypoint:

  "entrypoints": {
    "mixinsquared": [
      "com.example.mod.YourModMixinCanceller"
    ]
  }

I am using Forge or anything else

You will need to declare a service called com.bawnorton.mixinsquared.api.MixinCanceller inside the META-INF/services/ directory.
The content of this file will need to be a reference to your MixinCanceller implementation(s):

com.example.mod.YourModMixinCanceller
Screenshot 2023-09-28 at 17 00 29

I want to register it myself

In the onLoad method inside a IMixinConfigPlugin you can register a MixinCanceller directly using the MixinCancellerRegistrar like so:

public class YourModMixinConfigPlugin implements IMixinConfigPlugin {
    @Override
    public void onLoad(String mixinPackage) {
        MixinCancellerRegistrar.register(new YourModMixinCanceller());
    }
    ...
}