Skip to content

Commit 7621966

Browse files
committed
unimixins compat
1 parent 4cbda7a commit 7621966

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/main/java/com/falsepattern/lib/mixin/MixinInfo.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
@StableAPI(since = "0.10.2")
3434
public final class MixinInfo {
3535
@StableAPI.Expose
36-
public static final MixinBootstrapperType mixinBootstrapper = detect();
36+
public static final MixinBootstrapperType mixinBootstrapper;
37+
38+
static {
39+
MixinInfoCompatCompanion.mixinInfoClassLoaded = true;
40+
mixinBootstrapper = detect();
41+
}
3742

3843
@StableAPI.Expose
3944
public static boolean isMixinsInstalled() {
@@ -68,6 +73,11 @@ public static boolean isGasStation() {
6873
return mixinBootstrapper == MixinBootstrapperType.GasStation;
6974
}
7075

76+
@StableAPI.Expose(since = "0.10.15")
77+
public static boolean isUniMixin() {
78+
return mixinBootstrapper == MixinBootstrapperType.UniMixin;
79+
}
80+
7181
@StableAPI.Expose
7282
public static MixinBootstrapperType bootstrapperType() {
7383
return mixinBootstrapper;
@@ -97,6 +107,11 @@ public static boolean isClassPresentSafe(String clazz) {
97107
private static MixinBootstrapperType detect() {
98108
if (!isClassPresentSafe("org.spongepowered.asm.launch.MixinBootstrap"))
99109
return MixinBootstrapperType.None;
110+
for (val candidate: MixinInfoCompatCompanion.UNIMIXIN_CANDIDATES) {
111+
if (isClassPresentSafe(candidate)) {
112+
return MixinBootstrapperType.UniMixin;
113+
}
114+
}
100115
if (isClassPresentSafe("com.falsepattern.gasstation.GasStation"))
101116
return MixinBootstrapperType.GasStation;
102117
if (isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore"))
@@ -115,6 +130,7 @@ public enum MixinBootstrapperType {
115130
@StableAPI.Expose SpongeMixins,
116131
@StableAPI.Expose Grimoire,
117132
@StableAPI.Expose MixinBooterLegacy,
118-
@StableAPI.Expose Other
133+
@StableAPI.Expose Other,
134+
@StableAPI.Expose(since = "0.10.15") UniMixin
119135
}
120136
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2022 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice, this permission notice and the word "SNEED"
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.mixin;
23+
24+
import com.falsepattern.lib.StableAPI;
25+
import lombok.Getter;
26+
27+
import java.util.ArrayList;
28+
import java.util.Arrays;
29+
import java.util.List;
30+
31+
/**
32+
* This is a class you can use to interact with MixinInfo before it gets classloaded.
33+
* (Originally placed here for future unimixins compat in case they change the class names)
34+
*/
35+
@StableAPI(since = "0.10.15")
36+
public class MixinInfoCompatCompanion {
37+
/**
38+
* A list of all mixin classes that are candidates for unimixins.
39+
* This is used to determine if a mixin plugin is unimixins. Once MixinInfo is classloaded, this list has no effect.
40+
*/
41+
@StableAPI.Expose
42+
public static final List<String> UNIMIXIN_CANDIDATES = new ArrayList<>(Arrays.asList("io.github.legacymoddingmc.unimixins.compat.CompatCore",
43+
"io.github.legacymoddingmc.unimixins.devcompat.DevCompatCore",
44+
"io.github.legacymoddingmc.unimixins.all.AllCore",
45+
"io.github.legacymoddingmc.unimixins.mixin.MixinModule"));
46+
47+
@Getter(onMethod_ = @StableAPI.Expose)
48+
static boolean mixinInfoClassLoaded = false;
49+
}

0 commit comments

Comments
 (0)