-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |