Skip to content

Commit

Permalink
Remove unneeded transformers and allow for different regex when using…
Browse files Browse the repository at this point in the history
… SRG names.
  • Loading branch information
= committed Jun 29, 2019
1 parent c37d9d0 commit 0947afb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected MixinWorldServerSponge(ISaveHandler a, WorldInfo b, WorldProvider c, P
throw new RuntimeException("Mixins cannot be instantiated.");
}

@DynamicMethodReplacer.RedirectMethodCalls(nameRegex = "randomTick", convertSelf = true)
@DynamicMethodReplacer.RedirectMethodCalls(nameRegexDeobf = "randomTick", nameRegexObf = "func_180645_a", convertSelf = true)
@Dynamic(value = "Overwritten by SpongeForge", mixin = org.spongepowered.common.mixin.core.world.WorldServerMixin.class)
private void randomBlockTickRedirectorVanilla(Block block, World world, BlockPos pos, IBlockState state, Random random){
long startTime = System.nanoTime();
Expand All @@ -39,7 +39,7 @@ private void randomBlockTickRedirectorVanilla(Block block, World world, BlockPos
}
}

@DynamicMethodReplacer.RedirectMethodCalls(nameRegex = "randomTickBlock")
@DynamicMethodReplacer.RedirectMethodCalls(nameRegexDeobf = "randomTickBlock", nameRegexObf = "randomTickBlock")
@Dynamic(value = "Overwritten by SpongeForge", mixin = org.spongepowered.common.mixin.core.world.WorldServerMixin.class)
private static void randomBlockTickRedirectorSponge(ServerWorldBridge bridge, Block block, BlockPos pos, IBlockState state, Random random){
long startTime = System.nanoTime();
Expand All @@ -49,7 +49,7 @@ private static void randomBlockTickRedirectorSponge(ServerWorldBridge bridge, Bl
}
}

@DynamicMethodReplacer.RedirectMethodCalls(nameRegex = "updateTick", convertSelf = true)
@DynamicMethodReplacer.RedirectMethodCalls(nameRegexDeobf = "updateTick", nameRegexObf = "func_180650_b", convertSelf = true)
@Dynamic(value = "Overwritten by SpongeForge", mixin = org.spongepowered.common.mixin.core.world.WorldServerMixin.class)
private void normalBlockTickRedirectorVanilla(Block block, World world, BlockPos pos, IBlockState state, Random random){
long startTime = System.nanoTime();
Expand All @@ -59,7 +59,7 @@ private void normalBlockTickRedirectorVanilla(Block block, World world, BlockPos
}
}

@DynamicMethodReplacer.RedirectMethodCalls(nameRegex = "updateTickBlock")
@DynamicMethodReplacer.RedirectMethodCalls(nameRegexDeobf = "updateTickBlock", nameRegexObf = "updateTickBlock")
@Dynamic(value = "Overwritten by SpongeForge", mixin = org.spongepowered.common.mixin.core.world.WorldServerMixin.class)
private static void normalBlockTickRedirectorSponge(ServerWorldBridge bridge, Block block, BlockPos pos, IBlockState state, Random random){
long startTime = System.nanoTime();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package cf.terminator.laggoggles.mixinhelper;

import cf.terminator.laggoggles.Main;
import cf.terminator.laggoggles.mixinhelper.extended.DynamicMethodFinder;
import cf.terminator.laggoggles.mixinhelper.extended.DynamicMethodReplacer;
import cf.terminator.laggoggles.mixinhelper.extended.MethodHeadInserter;
import net.minecraftforge.fml.common.FMLCommonHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -176,8 +174,6 @@ public void postApply(String target, ClassNode classNode, String mixin, IMixinIn
LOGGER.info("Applied mixin: " + mixin);
if(mixin.equals("cf.terminator.laggoggles.mixin.MixinWorldServerSponge")) {
LOGGER.info("Applying custom transformer for cf.terminator.laggoggles.mixin.MixinWorldServerSponge");
new MethodHeadInserter(classNode).transform();
new DynamicMethodFinder(classNode).transform();
new DynamicMethodReplacer(classNode).transform();
}
MIXINS_TO_LOAD.remove(mixin);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package cf.terminator.laggoggles.mixinhelper.extended;

import cf.terminator.laggoggles.mixinhelper.MixinConfigPlugin;
import net.minecraftforge.fml.common.FMLCommonHandler;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.*;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.asm.obfuscation.mapping.mcp.MappingFieldSrg;
import org.spongepowered.tools.obfuscation.mapping.mcp.MappingProviderSrg;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -12,6 +17,7 @@
import java.util.regex.Pattern;

import static cf.terminator.laggoggles.mixinhelper.MixinConfigPlugin.LOGGER;
import static cf.terminator.laggoggles.mixinhelper.MixinConfigPlugin.isProductionEnvironment;

/**
* Remaps method calls to the target method within this class,
Expand All @@ -25,7 +31,8 @@ public class DynamicMethodReplacer implements Transformer {
@Retention(RetentionPolicy.RUNTIME)
@java.lang.annotation.Target(ElementType.METHOD)
public @interface RedirectMethodCalls {
String nameRegex();
String nameRegexDeobf();
String nameRegexObf();
boolean convertSelf() default false;
}

Expand All @@ -45,24 +52,28 @@ public void transform() {
for(AnnotationNode annotation : method.visibleAnnotations){
if(annotation.desc.equals("Lcf/terminator/laggoggles/mixinhelper/extended/DynamicMethodReplacer$RedirectMethodCalls;")){
String currentKey = null;
String nameRegex = null;
String nameRegexDeobf = null;
String nameRegexObf = null;
boolean convertSelf = false;
for(Object key_value : annotation.values){
if(currentKey == null){
currentKey = (String) key_value;
}else{
if(currentKey.equals("nameRegex")){
nameRegex = (String) key_value;
if(currentKey.equals("nameRegexDeobf")){
nameRegexDeobf = (String) key_value;
}else if(currentKey.equals("nameRegexObf")){
nameRegexObf = (String) key_value;
}else if(currentKey.equals("convertSelf")){
convertSelf = (Boolean) key_value;
}
currentKey = null;
}
}
if(nameRegex == null){
if(nameRegexDeobf == null || nameRegexObf == null){
LOGGER.fatal("Invalid annotation found. (@DynamicMethodFinder.RedirectMethodCalls)");
FMLCommonHandler.instance().exitJava(-1, true);
}else{
String nameRegex = isProductionEnvironment() ? nameRegexObf : nameRegexDeobf;
for (MethodNode changedMethod : findTargets(classNode, method, nameRegex,convertSelf, 1)){
if(changedMethods.contains(changedMethod) == false){
changedMethods.add(changedMethod);
Expand Down

This file was deleted.

0 comments on commit 0947afb

Please sign in to comment.