Skip to content

Commit

Permalink
Add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed May 11, 2024
1 parent 80771dd commit 4d82f32
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 4d82f32

Please sign in to comment.