Giter Club home page Giter Club logo

conditional-mixin's Introduction

conditional-mixin

jitpack badge maven 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 and my maven

Example Usages

Import

Import conditional-mixin

From jitpack

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

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

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

From my maven

repositories {
    maven { url 'https://maven.fallenbreath.me/releases' }
}

dependencies {
    modImplementation 'me.fallenbreath:conditional-mixin:0.5.1'

    // suggested, to bundle it into your mod jar
    include "me.fallenbreath:conditional-mixin:0.5.1"
}

Integrate

You need to create a mixin config plugin to provide the ability to control mixin applications. Then, there are 2 ways to integrate it with conditional-mixin:

The simplest way

Let your mixin config plugin class inherit RestrictiveMixinConfigPlugin

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

import me.fallenbreath.conditionalmixin.api.mixin.RestrictiveMixinConfigPlugin;

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

Specify the mixin config plugin class in your mixin meta json, if you have not done that yet:

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

The universal way

If you have already written a custom mixin plugin and don't want to make your plugin class inherit from something else, you can directly use the RestrictionChecker provided by conditional-mixin

import me.fallenbreath.conditionalmixin.api.checker.RestrictionChecker;
import me.fallenbreath.conditionalmixin.api.checker.RestrictionCheckers;

public class MyMixinConfigPlugin
{
	private final RestrictionChecker restrictionChecker = RestrictionCheckers.memorized();
	
	// See RestrictiveMixinConfigPlugin for usages of a RestrictionChecker
}

Annotate your mixins

Now, you can annotate your mixins like these:

@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, and your mixin plugin class inherits from RestrictiveMixinConfigPlugin, 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

conditional-mixin's People

Contributors

fallen-breath avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.