zly2006 / conditional-mixin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

conditional-mixin

jitpack badge

A fabric library mod for using annotation to conditionally apply your mixins. Requires fabric-loader >=0.10.4 only

It is available at jitpack

Example Usages

Import conditional-mixin

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    modImplementation 'com.github.Fallen-Breath:conditional-mixin:v0.3.2'

    // suggested, to bundle it into your mod jar
    include "com.github.Fallen-Breath:conditional-mixin:v0.3.2"
}

Inherit RestrictiveMixinConfigPlugin to create your mixin config plugin class

The RestrictiveMixinConfigPlugin will disable those mixins that don't satisfy with the annotated restriction in its shouldApplyMixin method

public class MyMixinConfigPlugin extends RestrictiveMixinConfigPlugin
{
    // ...
}

Specify the mixin config plugin class in your mixin meta json:

"plugin": "my.mod.MyMixinConfigPlugin",

Then you can annotate your mixins like:

@Restriction(
        require = {
                @Condition("some_mod"),
                @Condition(value = "another_mod", versionPredicates = "2.0.x"),
                @Condition(value = "random_mod", versionPredicates = {">=1.0.1 <1.2", ">=2.0.0"}),
        }
)
@Mixin(SomeClass.class)
public abstract class SomeClassMixin
{
    // ...
}

or

@Restriction(
        require = @Condition(type = Condition.Type.MIXIN, value = "my.mod.mixin.ImportantMixin"),
        conflict = @Condition("bad_mod")
)
@Mixin(AnotherClass.class)
public abstract class AnotherClassMixin
{
    // ...
}

You can also define your own tester class for more complicated condition testing

@Restriction(
        require = @Condition(type = Condition.Type.TESTER, tester = MyConditionTester.class)
)
@Mixin(RandomClass.class)
public abstract class RandomClassMixin
{
    // ...
}

public class MyConditionTester implements ConditionTester
{
	@Override
	public boolean isSatisfied(String mixinClassName)
	{
		// More complicated checks go here
		return mixinClassName.length() % 2 == 0;
	}
}

Notes

If you are upgrading conditional-mixin from older version, make sure to check if you have overwritten some methods in your mixin plugin class, since class RestrictiveMixinConfigPlugin might implement more methods of IMixinConfigPlugin in newer versions. e.g. RestrictiveMixinConfigPlugin#preApply and RestrictiveMixinConfigPlugin#postApply are added in v0.2.0 for being able to automatically remove the @Restriction in the merged target class

About

License:GNU Lesser General Public License v3.0


Languages

Language:Java 100.0%