Add mixin to all projects

This commit is contained in:
Jared 2023-06-11 03:25:08 +02:00
parent 45030884b0
commit fc6f452e8c
11 changed files with 97 additions and 6 deletions

View File

@ -2,6 +2,7 @@ plugins {
id 'fabric-loom' version '1.2-SNAPSHOT' apply(false)
id 'net.minecraftforge.gradle' version '[6.0,6.2)' apply(false)
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' apply(false)
id("org.spongepowered.mixin") version "0.7-SNAPSHOT" apply(false)
}
subprojects {
@ -59,7 +60,7 @@ subprojects {
}
processResources {
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'mods.toml']) {
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'mods.toml', '*.mixins.json']) {
expand project.properties
}
}

View File

@ -0,0 +1,20 @@
package com.example.examplemod.mixin;
import com.example.examplemod.Constants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
public class MixinMinecraft {
@Inject(at = @At("TAIL"), method = "<init>")
private void init(CallbackInfo info) {
Constants.LOG.info("This line is printed by an example mod common mixin!");
Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType());
}
}

View File

@ -0,0 +1,18 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.example.examplemod.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"MixinMinecraft"
],
"server": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@ -17,6 +17,9 @@ dependencies {
}
loom {
mixin {
defaultRefmapName.set("${mod_id}.refmap.json")
}
runs {
client {
client()

View File

@ -9,13 +9,12 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TitleScreen.class)
public class ExampleMixin {
public class MixinTitleScreen {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
Constants.LOG.info("This line is printed by an example mod mixin from Fabric!");
Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType());
Constants.LOG.info("Classloader: {}", this.getClass().getClassLoader());
}
}

View File

@ -2,11 +2,14 @@
"required": true,
"minVersion": "0.8",
"package": "com.example.examplemod.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"ExampleMixin"
"MixinTitleScreen"
],
"server": [
],
"injectors": {
"defaultRequire": 1

View File

@ -20,7 +20,8 @@
]
},
"mixins": [
"modid.mixins.json"
"examplemod.mixins.json",
"examplemod.fabric.mixins.json"
],
"depends": {
"fabricloader": ">=0.14",

View File

@ -2,10 +2,18 @@ plugins {
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle'
id 'org.spongepowered.mixin'
}
archivesBaseName = "${mod_name}-forge-${minecraft_version}"
mixin {
add(sourceSets.main, "${mod_id}.refmap.json")
config("${mod_id}.mixins.json")
config("${mod_id}.forge.mixins.json")
}
minecraft {
mappings channel: 'official', version: minecraft_version
@ -67,6 +75,7 @@ sourceSets.main.resources.srcDir 'src/generated/resources'
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
compileOnly project(":common")
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor")
}
tasks.withType(JavaCompile) {

View File

@ -0,0 +1,20 @@
package com.example.examplemod.mixin;
import com.example.examplemod.Constants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TitleScreen.class)
public class MixinTitleScreen {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
Constants.LOG.info("This line is printed by an example mod mixin from Forge!");
Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType());
}
}

View File

@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.example.examplemod.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"MixinTitleScreen"
],
"server": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@ -16,7 +16,7 @@ fabric_loader_version=0.14.11
# Mod options
mod_name=MultiLoader
mod_author=Jared
mod_id=multiloader
mod_id=examplemod
# Gradle
org.gradle.jvmargs=-Xmx3G