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

com.llamalad7.mixinextras.injector.LateApplyingInjectorInfo 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.5
Show newest version
package com.llamalad7.mixinextras.injector;

import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.service.MixinExtrasService;
import com.llamalad7.mixinextras.sugar.impl.SugarWrapperInjectionInfo;
import com.llamalad7.mixinextras.utils.MixinExtrasLogger;
import com.llamalad7.mixinextras.utils.ProxyUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

public interface LateApplyingInjectorInfo {
    void lateInject();

    void latePostInject();

    @SuppressWarnings("unused")
    void wrap(LateApplyingInjectorInfo outer);

    /**
     * Will be called by 0.2.0-beta.1 when enqueueing a {@link SugarWrapperInjectionInfo} for a {@link WrapOperation}.
     */
    @Deprecated
    default void lateApply() {
        lateInject();
        MixinExtrasLogger logger = MixinExtrasLogger.get("Sugar");
        logger.warn("Skipping post injection checks for {} since it is from 0.2.0-beta.1 and cannot be saved", this);
    }

    /**
     * Handles the inner injection info being from a different package to ours.
     */
    static boolean wrap(Object inner, LateApplyingInjectorInfo outer) {
        Class theirInterface = Arrays.stream(inner.getClass().getInterfaces())
                .filter(it -> it.getName().endsWith(".LateApplyingInjectorInfo")).findFirst().orElse(null);
        if (theirInterface == null || !MixinExtrasService.getInstance().isClassOwned(theirInterface.getName())) {
            return false;
        }
        try {
            inner.getClass().getMethod("wrap", theirInterface).invoke(inner, ProxyUtils.getProxy(outer, theirInterface));
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Failed to wrap InjectionInfo: ", e);
        }
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy