Skip to content

Commit c786785

Browse files
committed
Add MixinExtras
1 parent 1314fe6 commit c786785

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed

buildSrc/src/main/kotlin/org/polyfrost/gradle/addDependencies.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ fun Project.provideIncludedDependencies(version: Triple<Int, Int, Int>?, loader:
4343
} else if (version != null && version.second > 12) { // forge / neoforge
4444
// TODO add KFF
4545
}
46+
if (version == null // legacy dep module
47+
|| (version.first == 1 && version.second < 12 && loader == "forge")) {
48+
deps.add(libs.findLibrary("mixin").get().get()) // PolyMixin
49+
}
50+
deps.add(libs.findLibrary("mixin-extras").get().get())
4651
val actualDeps = mutableListOf<OCDependency>()
4752
for (dep in deps) {
4853
actualDeps.add(OCDependency(dep))

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ lwjgl = "3.3.3" # All downloaded by the isolated-lwjgl3-loader
2525

2626
# Legacy only
2727
mixin = "0.8.4+build.2"
28+
mixin-extras = "0.4.1"
2829

2930
# Gradle
3031
kotlinx-abi = "0.14.0"
@@ -44,6 +45,7 @@ junit = { module = "org.junit.jupiter:junit-jupiter" }
4445
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit-bom" }
4546

4647
mixin = { module = "org.polyfrost:polymixin", version.ref = "mixin" }
48+
mixin-extras = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixin-extras" }
4749

4850
isolated-lwjgl3-loader = { module = "org.polyfrost:isolated-lwjgl3-loader", version.ref = "isolated-lwjgl3-loader" }
4951
polyio = { module = "org.polyfrost:polyio", version.ref = "polyio" }

versions/build.gradle.kts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ loom {
3636
}
3737
if (project.platform.isForge) {
3838
forge {
39-
mixinConfig("mixins.${modId}.json")
39+
mixinConfig("mixins.${modId}.json", "mixins.${modId}.init.json")
4040
}
4141
}
42-
mixin.defaultRefmapName = "mixins.${modId}.refmap.json"
4342
}
4443

4544
repositories {
@@ -62,6 +61,8 @@ dependencies {
6261
}
6362
}
6463

64+
annotationProcessor(libs.mixin.extras)
65+
6566
for (dep in listOf("-nanovg").run { if (platform.mcVersion < 11300) this else this + listOf("-tinyfd", "-stb", "") }) {
6667
val lwjglDep = "org.lwjgl:lwjgl$dep:${libs.versions.lwjgl.get()}"
6768
compileOnlyApi(lwjglDep) {
@@ -75,9 +76,6 @@ dependencies {
7576
}
7677

7778
if (platform.isLegacyForge) {
78-
implementation(libs.mixin) {
79-
isTransitive = false
80-
}
8179
compileOnly("cc.polyfrost:oneconfig-${platform}:0.2.2-alpha216") {
8280
isTransitive = false
8381
}
@@ -192,12 +190,12 @@ tasks {
192190
"ModSide" to "CLIENT",
193191
"ForceLoadAsMod" to true,
194192
"TweakOrder" to "0",
195-
"MixinConfigs" to "mixins.$modId.json",
193+
"MixinConfigs" to "mixins.$modId.json,mixins.$modId.init.json",
196194
"TweakClass" to tweakClass
197195
)
198196
)
199197
} else {
200-
put("MixinConfigs", "mixins.$modId.json")
198+
put("MixinConfigs", "mixins.$modId.json,mixins.$modId.init.json")
201199
}
202200
}
203201
putAll(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.polyfrost.oneconfig.internal;
2+
3+
import com.llamalad7.mixinextras.MixinExtrasBootstrap;
4+
import org.objectweb.asm.tree.ClassNode;
5+
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
6+
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
7+
8+
import java.util.List;
9+
import java.util.Set;
10+
11+
public class OneConfigEarlyMixinInit implements IMixinConfigPlugin {
12+
@Override
13+
public void onLoad(String mixinPackage) {
14+
MixinExtrasBootstrap.init();
15+
}
16+
17+
@Override
18+
public String getRefMapperConfig() {
19+
return null;
20+
}
21+
22+
@Override
23+
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
24+
return true;
25+
}
26+
27+
@Override
28+
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
29+
30+
}
31+
32+
@Override
33+
public List<String> getMixins() {
34+
return null;
35+
}
36+
37+
@Override
38+
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
39+
40+
}
41+
42+
@Override
43+
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
44+
45+
}
46+
}

versions/src/main/java/org/polyfrost/oneconfig/internal/legacy/OneConfigTweaker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ private static void removeLWJGLException() {
232232
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
233233
MixinBootstrap.init();
234234
Mixins.addConfiguration("mixins.oneconfig.json");
235+
Mixins.addConfiguration("mixins.oneconfig.init.json");
235236
removeLWJGLException();
236237

237238
// performance fix
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Dummy package for `mixins.oneconfig.init.json`
3+
*/
4+
package org.polyfrost.oneconfig.internal.mixin.init;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compatibilityLevel": "JAVA_8",
3+
"minVersion": "0.8",
4+
"package": "org.polyfrost.oneconfig.internal.mixin.init",
5+
"plugin": "org.polyfrost.oneconfig.internal.OneConfigEarlyMixinInit",
6+
"verbose": true,
7+
"target": "@env(INIT)"
8+
}

versions/src/main/resources/mixins.oneconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"compatibilityLevel": "JAVA_8",
3-
"minVersion": "0.7",
3+
"minVersion": "0.8",
44
"package": "org.polyfrost.oneconfig.internal.mixin",
5-
"refmap": "mixins.oneconfig.refmap.json",
65
"plugin": "org.polyfrost.oneconfig.internal.OneConfigMixinInit",
76
"injectors": {
87
"maxShiftBy": 5

0 commit comments

Comments
 (0)