diff --git a/README.md b/README.md new file mode 100644 index 0000000..1236c65 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# MixinConstraints + +A library to enable/disable mixins using annotations. +Annotations can be applied to mixin classes to toggle the whole mixin, or individual fields/methods for more precision. + +# Installing + +MixinConstraints is available through Maven Central +The library currently only supports Fabric + +__Gradle__ +```groovy +dependencies { + include(implementation("com.moulberry:mixinconstraints:1.0.0")) +} +``` + +Next, you will need to bootstrap the library to affect your mixins. + +The easiest way is using the built-in Mixin Plugin by adding the following to your modid.mixins.json: +```json +{ + "plugin": "com.moulberry.mixinconstraints.ConstraintsMixinPlugin", +} +``` + +If you already have your own mixin plugin, you can use the [ConstraintsMixinPlugin](https://github.com/Moulberry/MixinConstraints/blob/master/src/main/java/com/moulberry/mixinconstraints/ConstraintsMixinPlugin.java) class as a reference to add support. + +# Using the library + +The library provides 4 annotations +- @IfModLoaded (checks if a mod is loaded) +- @IfModAbsent (checks if a mod is absent) +- @IfMinecraftVersion (checks if the Minecraft version matches a range) +- @IfDevEnvironment (checks if the game is running inside a development environment) + +These annotations can be applied to classes to control whether the whole mixin is applied + +For example, the following mixin will only be applied if sodium or embeddium is present +```java +@IfModLoaded(value = "sodium", aliases = {"embeddium"}) +@Mixin(BlockOcclusionCache.class) +public class MixinSodiumBlockOcclusionCache { + ... +} +``` + +Additionally, the annotations can also be applied to individual fields/methods + +For example, the following mixin will inject only one of the two methods depending on whether the mod is in a dev environment +```java +@Mixin(Minecraft.class) +public class MixinMinecraft { + @IfDevEnvironment + @Inject(at = @At("HEAD"), method = "run") + private void runDev(CallbackInfo info) { + System.out.println("Hello from a dev environment!"); + } + + @IfDevEnvironment(negate = true) + @Inject(at = @At("HEAD"), method = "run") + private void runProd(CallbackInfo info) { + System.out.println("Hello from production!"); + } +} +``` + +# License +The library is available under the MIT license.