Skip to content

Commit

Permalink
idk if this works
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jan 30, 2024
1 parent 9c81703 commit d0fd7dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface ConditionalMixin {
/**
* Only load mixin if requirements are fulfilled
* List of mod id's
*/
Requirement[] require() default {};
String[] value();

/**
* Don't load mixin if any of the requirements are fulfilled, higher priority then require
*/
Requirement[] conflict() default {};
boolean applyIfPresent() default true;
}
17 changes: 0 additions & 17 deletions src/main/java/org/violetmoon/zeta/annotation/Requirement.java

This file was deleted.

25 changes: 6 additions & 19 deletions src/main/java/org/violetmoon/zeta/api/ConditionalMixinManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.spongepowered.asm.util.Annotations;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.annotation.ConditionalMixin;
import org.violetmoon.zeta.annotation.Requirement;

import java.io.IOException;
import java.util.List;
Expand All @@ -28,23 +27,11 @@ public static boolean shouldApply(Zeta zeta, String targetClassName, String mixi
boolean shouldApply = true;
for (AnnotationNode node : annotationNodes) {
if (node.desc.equals(Type.getDescriptor(ConditionalMixin.class))) {
List<Requirement> requirements = Annotations.getValue(node, "require", Requirement.class);
for (Requirement req : requirements) {
String[] modids = req.value();

shouldApply = areModsLoaded(zeta, modids);

Zeta.GLOBAL_LOG.info("{}: {} is{}being applied because the mod(s) {} are{}loaded", zeta.getModDisplayName(zeta.modid), targetClassName, shouldApply ? " " : " not ", modids, shouldApply ? " " : " not ");
}

List<Requirement> conflicts = Annotations.getValue(node, "conflict", Requirement.class);
for (Requirement conflict : conflicts) {
String[] modids = conflict.value();

shouldApply = areModsLoaded(zeta, modids);

Zeta.GLOBAL_LOG.info("{}: {} is{}being applied because the mod(s) {} are{}loaded", zeta.getModDisplayName(zeta.modid), targetClassName, shouldApply ? " " : " not ", modids, shouldApply ? " " : " not ");
}
List<String> mods = Annotations.getValue(node, "value");
boolean applyIfPresent = Annotations.getValue(node, "applyIfPresent", Boolean.TRUE);
boolean anyModsLoaded = areModsLoaded(zeta, mods);
shouldApply = anyModsLoaded == applyIfPresent;
Zeta.GLOBAL_LOG.info("{}: {} is{}being applied because the mod(s) {} are{}loaded", zeta.getModDisplayName(zeta.modid), targetClassName, shouldApply ? " " : " not ", mods, anyModsLoaded ? " " : " not ");
}
}

Expand All @@ -54,7 +41,7 @@ public static boolean shouldApply(Zeta zeta, String targetClassName, String mixi
}
}

private static boolean areModsLoaded(Zeta zeta, String[] modids) {
private static boolean areModsLoaded(Zeta zeta, List<String> modids) {
for (String mod : modids) {
if (zeta.isModLoaded(mod)) {
return true;
Expand Down

0 comments on commit d0fd7dd

Please sign in to comment.