Skip to content

Commit

Permalink
Add MixinExtras
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Nov 29, 2024
1 parent 1314fe6 commit c786785
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ fun Project.provideIncludedDependencies(version: Triple<Int, Int, Int>?, loader:
} else if (version != null && version.second > 12) { // forge / neoforge
// TODO add KFF
}
if (version == null // legacy dep module
|| (version.first == 1 && version.second < 12 && loader == "forge")) {
deps.add(libs.findLibrary("mixin").get().get()) // PolyMixin
}
deps.add(libs.findLibrary("mixin-extras").get().get())
val actualDeps = mutableListOf<OCDependency>()
for (dep in deps) {
actualDeps.add(OCDependency(dep))
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lwjgl = "3.3.3" # All downloaded by the isolated-lwjgl3-loader

# Legacy only
mixin = "0.8.4+build.2"
mixin-extras = "0.4.1"

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

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

isolated-lwjgl3-loader = { module = "org.polyfrost:isolated-lwjgl3-loader", version.ref = "isolated-lwjgl3-loader" }
polyio = { module = "org.polyfrost:polyio", version.ref = "polyio" }
Expand Down
12 changes: 5 additions & 7 deletions versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ loom {
}
if (project.platform.isForge) {
forge {
mixinConfig("mixins.${modId}.json")
mixinConfig("mixins.${modId}.json", "mixins.${modId}.init.json")
}
}
mixin.defaultRefmapName = "mixins.${modId}.refmap.json"
}

repositories {
Expand All @@ -62,6 +61,8 @@ dependencies {
}
}

annotationProcessor(libs.mixin.extras)

for (dep in listOf("-nanovg").run { if (platform.mcVersion < 11300) this else this + listOf("-tinyfd", "-stb", "") }) {
val lwjglDep = "org.lwjgl:lwjgl$dep:${libs.versions.lwjgl.get()}"
compileOnlyApi(lwjglDep) {
Expand All @@ -75,9 +76,6 @@ dependencies {
}

if (platform.isLegacyForge) {
implementation(libs.mixin) {
isTransitive = false
}
compileOnly("cc.polyfrost:oneconfig-${platform}:0.2.2-alpha216") {
isTransitive = false
}
Expand Down Expand Up @@ -192,12 +190,12 @@ tasks {
"ModSide" to "CLIENT",
"ForceLoadAsMod" to true,
"TweakOrder" to "0",
"MixinConfigs" to "mixins.$modId.json",
"MixinConfigs" to "mixins.$modId.json,mixins.$modId.init.json",
"TweakClass" to tweakClass
)
)
} else {
put("MixinConfigs", "mixins.$modId.json")
put("MixinConfigs", "mixins.$modId.json,mixins.$modId.init.json")
}
}
putAll(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.polyfrost.oneconfig.internal;

import com.llamalad7.mixinextras.MixinExtrasBootstrap;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class OneConfigEarlyMixinInit implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
MixinExtrasBootstrap.init();
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ private static void removeLWJGLException() {
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
MixinBootstrap.init();
Mixins.addConfiguration("mixins.oneconfig.json");
Mixins.addConfiguration("mixins.oneconfig.init.json");
removeLWJGLException();

// performance fix
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Dummy package for `mixins.oneconfig.init.json`
*/
package org.polyfrost.oneconfig.internal.mixin.init;
8 changes: 8 additions & 0 deletions versions/src/main/resources/mixins.oneconfig.init.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compatibilityLevel": "JAVA_8",
"minVersion": "0.8",
"package": "org.polyfrost.oneconfig.internal.mixin.init",
"plugin": "org.polyfrost.oneconfig.internal.OneConfigEarlyMixinInit",
"verbose": true,
"target": "@env(INIT)"
}
3 changes: 1 addition & 2 deletions versions/src/main/resources/mixins.oneconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"compatibilityLevel": "JAVA_8",
"minVersion": "0.7",
"minVersion": "0.8",
"package": "org.polyfrost.oneconfig.internal.mixin",
"refmap": "mixins.oneconfig.refmap.json",
"plugin": "org.polyfrost.oneconfig.internal.OneConfigMixinInit",
"injectors": {
"maxShiftBy": 5
Expand Down

0 comments on commit c786785

Please sign in to comment.