mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-17 15:24:52 +00:00
Use mixins to construct the TestFunctionInfo class
There's some funky things going on here, but thankfully they're limited to test code.
This commit is contained in:
parent
0be030c497
commit
23bf33c454
14
build.gradle
14
build.gradle
@ -6,12 +6,17 @@ buildscript {
|
||||
name = "forge"
|
||||
url = "https://files.minecraftforge.net/maven"
|
||||
}
|
||||
maven {
|
||||
name = "mixin"
|
||||
url = "https://dist.creeper.host/Sponge/maven"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.google.code.gson:gson:2.8.1'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.190'
|
||||
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
|
||||
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
||||
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +30,7 @@ plugins {
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'org.spongepowered.mixin'
|
||||
apply plugin: 'org.ajoberstar.grgit'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'maven'
|
||||
@ -79,6 +85,10 @@ 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 {
|
||||
cctest {
|
||||
@ -93,6 +103,10 @@ minecraft {
|
||||
accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
}
|
||||
|
||||
mixin {
|
||||
add sourceSets.test, "cctest.refmap.json"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.resources {
|
||||
srcDir 'src/generated/resources'
|
||||
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.ingame.mixin;
|
||||
|
||||
import net.minecraft.test.TestFunctionInfo;
|
||||
import net.minecraft.test.TestTrackerHolder;
|
||||
import net.minecraft.util.Rotation;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Mixin to replace final fields and some getters with non-final versions.
|
||||
*
|
||||
* Due to (I assume) the magic of proguard, some getters are replaced with constant
|
||||
* implementations. Thus we need to replace them with a sensible version.
|
||||
*/
|
||||
@Mixin( TestFunctionInfo.class )
|
||||
public class MixinTestFunctionInfo
|
||||
{
|
||||
@Shadow
|
||||
@Mutable
|
||||
private String batchName;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private String testName;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private String structureName;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private boolean required;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private Consumer<TestTrackerHolder> function;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private int maxTicks;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private long setupTicks;
|
||||
|
||||
@Shadow
|
||||
@Mutable
|
||||
private Rotation rotation;
|
||||
|
||||
@Overwrite
|
||||
public int getMaxTicks()
|
||||
{
|
||||
return this.maxTicks;
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public long getSetupTicks()
|
||||
{
|
||||
return setupTicks;
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public boolean isRequired()
|
||||
{
|
||||
return required;
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ import org.objectweb.asm.Type;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
@ -110,13 +109,6 @@ class TestLoader
|
||||
private static void setFinalField( TestFunctionInfo func, String name, Object value ) throws ReflectiveOperationException
|
||||
{
|
||||
Field field = TestFunctionInfo.class.getDeclaredField( name );
|
||||
if( (field.getModifiers() & Modifier.FINAL) != 0 )
|
||||
{
|
||||
Field modifiers = Field.class.getDeclaredField( "modifiers" );
|
||||
modifiers.setAccessible( true );
|
||||
modifiers.set( field, field.getModifiers() & ~Modifier.FINAL );
|
||||
}
|
||||
|
||||
field.setAccessible( true );
|
||||
field.set( func, value );
|
||||
}
|
||||
|
10
src/test/resources/cctest.mixin.json
Normal file
10
src/test/resources/cctest.mixin.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "dan200.computercraft.ingame.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"refmap": "cctest.refmap.json",
|
||||
"mixins": [
|
||||
"MixinTestFunctionInfo"
|
||||
],
|
||||
"minVersion": "0.8"
|
||||
}
|
Loading…
Reference in New Issue
Block a user