com.llamalad7.mixinextras.transformer.MixinTransformerExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mixinextras-fabric Show documentation
Show all versions of mixinextras-fabric Show documentation
Companion library to Mixin with lots of features to improve the compatibility and concision of your mixins!
package com.llamalad7.mixinextras.transformer;
import com.llamalad7.mixinextras.sugar.impl.SugarMixinTransformer;
import com.llamalad7.mixinextras.utils.MixinInternals;
import com.llamalad7.mixinextras.wrapper.factory.FactoryRedirectWrapperMixinTransformer;
import org.apache.commons.lang3.tuple.Pair;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
import java.util.*;
public class MixinTransformerExtension implements IExtension {
private final Set preparedMixins = Collections.newSetFromMap(new WeakHashMap<>());
private final List transformers = Arrays.asList(
new FactoryRedirectWrapperMixinTransformer(), new SugarMixinTransformer()
);
@Override
public boolean checkActive(MixinEnvironment environment) {
return true;
}
@Override
public void preApply(ITargetClassContext context) {
for (Pair pair : MixinInternals.getMixinsFor(context)) {
IMixinInfo info = pair.getLeft();
ClassNode node = pair.getRight();
if (preparedMixins.contains(node)) {
// Don't scan the whole class again
continue;
}
for (MixinTransformer transformer : transformers) {
transformer.transform(info, node);
}
preparedMixins.add(node);
}
}
@Override
public void postApply(ITargetClassContext context) {
}
@Override
public void export(MixinEnvironment env, String name, boolean force, ClassNode classNode) {
}
}