From 2d3e88ef595d6d260b227924e69a696d3bf65deb Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 19 Jun 2021 12:52:07 +0100 Subject: [PATCH] Replace mixin with access transformers Hadn't realised I could use these to touch final modifiers! More importantly, Mixin doesn't work with FG 5.0, so we needed an alternative :). --- build.gradle | 19 +--------- .../computercraft/ingame/mod/TestLoader.java | 35 ++++++------------- .../resources/META-INF/accesstransformer.cfg | 8 +++++ src/test/resources/cctest.mixin.json | 10 ------ 4 files changed, 19 insertions(+), 53 deletions(-) create mode 100644 src/test/resources/META-INF/accesstransformer.cfg delete mode 100644 src/test/resources/cctest.mixin.json diff --git a/build.gradle b/build.gradle index ae3c0c7e4..f35b21c24 100644 --- a/build.gradle +++ b/build.gradle @@ -5,16 +5,10 @@ buildscript { name = "forge" url = "https://maven.minecraftforge.net" } - maven { - name = "Sponge (Mixin)" - url = "https://repo.spongepowered.org/repository/maven-public/" - content { includeGroup "org.spongepowered" } - } } dependencies { classpath 'com.google.code.gson:gson:2.8.1' classpath 'net.minecraftforge.gradle:ForgeGradle:5.0.12' - classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' } } @@ -30,7 +24,6 @@ plugins { } apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'org.spongepowered.mixin' version = mod_version @@ -68,9 +61,6 @@ minecraft { property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg" - mods { computercraft { source sourceSets.main @@ -107,9 +97,6 @@ minecraft { testServer { workingDirectory project.file('test-files/server') parent runs.server - properties 'mixin.env.disableRefMap': 'true' - - arg "-mixin.config=cctest.mixin.json" arg "--nogui" mods { @@ -123,10 +110,7 @@ minecraft { mappings channel: 'official', version: mc_version accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg') -} - -mixin { - add sourceSets.test, "cctest.refmap.json" + accessTransformer file('src/test/resources/META-INF/accesstransformer.cfg') } sourceSets { @@ -169,7 +153,6 @@ dependencies { testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72' testImplementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.72' testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8' - testAnnotationProcessor 'org.spongepowered:mixin:0.8.2:processor' cctJavadoc 'cc.tweaked:cct-javadoc:1.4.0' } diff --git a/src/test/java/dan200/computercraft/ingame/mod/TestLoader.java b/src/test/java/dan200/computercraft/ingame/mod/TestLoader.java index 9c4d7fa80..6a5ec4202 100644 --- a/src/test/java/dan200/computercraft/ingame/mod/TestLoader.java +++ b/src/test/java/dan200/computercraft/ingame/mod/TestLoader.java @@ -17,7 +17,6 @@ import net.minecraftforge.fml.unsafe.UnsafeHacks; import net.minecraftforge.forgespi.language.ModFileScanData; import org.objectweb.asm.Type; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; @@ -87,29 +86,15 @@ class TestLoader long setupTicks ) { - try - { - TestFunctionInfo func = UnsafeHacks.newInstance( TestFunctionInfo.class ); - setFinalField( func, "batchName", batchName ); - setFinalField( func, "testName", testName ); - setFinalField( func, "structureName", structureName ); - setFinalField( func, "required", required ); - setFinalField( func, "function", function ); - setFinalField( func, "maxTicks", maxTicks ); - setFinalField( func, "setupTicks", setupTicks ); - setFinalField( func, "rotation", Rotation.NONE ); - return func; - } - catch( ReflectiveOperationException e ) - { - throw new RuntimeException( e ); - } - } - - private static void setFinalField( TestFunctionInfo func, String name, Object value ) throws ReflectiveOperationException - { - Field field = TestFunctionInfo.class.getDeclaredField( name ); - field.setAccessible( true ); - field.set( func, value ); + TestFunctionInfo func = UnsafeHacks.newInstance( TestFunctionInfo.class ); + func.batchName = batchName; + func.testName = testName; + func.structureName = structureName; + func.required = required; + func.function = function; + func.maxTicks = maxTicks; + func.setupTicks = setupTicks; + func.rotation = Rotation.NONE; + return func; } } diff --git a/src/test/resources/META-INF/accesstransformer.cfg b/src/test/resources/META-INF/accesstransformer.cfg new file mode 100644 index 000000000..d066467bb --- /dev/null +++ b/src/test/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,8 @@ +public-f net.minecraft.test.TestFunctionInfo field_229650_a_ +public-f net.minecraft.test.TestFunctionInfo field_229651_b_ +public-f net.minecraft.test.TestFunctionInfo field_229652_c_ +public-f net.minecraft.test.TestFunctionInfo field_229653_d_ +public-f net.minecraft.test.TestFunctionInfo field_229654_e_ +public-f net.minecraft.test.TestFunctionInfo field_229655_f_ +public-f net.minecraft.test.TestFunctionInfo field_229656_g_ +public-f net.minecraft.test.TestFunctionInfo field_240589_h_ diff --git a/src/test/resources/cctest.mixin.json b/src/test/resources/cctest.mixin.json deleted file mode 100644 index f836d2638..000000000 --- a/src/test/resources/cctest.mixin.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "required": true, - "package": "dan200.computercraft.ingame.mixin", - "compatibilityLevel": "JAVA_8", - "refmap": "cctest.refmap.json", - "mixins": [ - "MixinTestFunctionInfo" - ], - "minVersion": "0.8" -}