All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.llamalad7.mixinextras.transformer.MixinTransformerExtension Maven / Gradle / Ivy

Go to download

Companion library to Mixin with lots of features to improve the compatibility and concision of your mixins!

There is a newer version: 0.5.0-beta.4
Show newest version
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) {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy