mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-17 21:35:04 +00:00
port mixin plugin to falsepatternlib
This commit is contained in:
8 files changed
+84
-324
No files matched your search
@@ -1,138 +1,23 @@
|
||||
package com.falsepattern.endlessids.mixin.plugin;
|
||||
|
||||
import com.falsepattern.endlessids.Tags;
|
||||
import lombok.val;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.falsepattern.lib.mixin.IMixin;
|
||||
import com.falsepattern.lib.mixin.IMixinPlugin;
|
||||
import com.falsepattern.lib.mixin.ITargetedMod;
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.nio.file.Files.walk;
|
||||
|
||||
public class MixinPlugin implements IMixinConfigPlugin {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(Tags.MODNAME + " Mixin Loader");
|
||||
private static final Path MODS_DIRECTORY_PATH = new File(Launch.minecraftHome, "mods/").toPath();
|
||||
public class MixinPlugin implements IMixinPlugin {
|
||||
@Getter
|
||||
private final Logger logger = IMixinPlugin.createLogger(Tags.MODNAME);
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
public IMixin[] getMixinEnumValues() {
|
||||
return Mixin.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||
|
||||
}
|
||||
|
||||
// This method return a List<String> of mixins. Every mixins in this list will be loaded.
|
||||
@Override
|
||||
public List<String> getMixins() {
|
||||
val isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
|
||||
|
||||
val loadedMods =
|
||||
Arrays.stream(TargetedMod.values())
|
||||
.filter(mod -> mod == TargetedMod.VANILLA
|
||||
|| (mod.loadInDevelopment && isDevelopmentEnvironment)
|
||||
|| loadJarOf(mod))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (TargetedMod mod : TargetedMod.values()) {
|
||||
if(loadedMods.contains(mod)) {
|
||||
LOG.info("Found " + mod.modName + "! Integrating now...");
|
||||
}
|
||||
else {
|
||||
LOG.info("Could not find " + mod.modName + "! Skipping integration....");
|
||||
}
|
||||
}
|
||||
|
||||
val mixins = new ArrayList<String>();
|
||||
for (val mixin : Mixin.values()) {
|
||||
if (mixin.shouldLoad(loadedMods)) {
|
||||
mixins.add(mixin.mixin);
|
||||
LOG.info("Loading mixin: " + mixin.mixin);
|
||||
}
|
||||
}
|
||||
return mixins;
|
||||
}
|
||||
|
||||
private int grimoireDetected = -1;
|
||||
|
||||
private boolean loadJarOf(final TargetedMod mod) {
|
||||
try {
|
||||
val jar = findJarOf(mod);
|
||||
if(jar == null) {
|
||||
LOG.info("Jar not found for " + mod);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG.info("Attempting to add " + jar + " to the URL Class Path");
|
||||
if (!jar.exists()) {
|
||||
throw new FileNotFoundException(jar.toString());
|
||||
}
|
||||
if (grimoireDetected < 0) {
|
||||
try {
|
||||
Class.forName("io.github.crucible.grimoire.Grimoire", false, getClass().getClassLoader());
|
||||
grimoireDetected = 1;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
grimoireDetected = 0;
|
||||
}
|
||||
}
|
||||
if (grimoireDetected == 1) {
|
||||
LOG.info("Not adding " + jar + " to the URL Class Path, because Grimoire breaks our utility class.");
|
||||
} else {
|
||||
MinecraftURLClassPath.addJar(jar);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static File findJarOf(final TargetedMod mod) {
|
||||
try {
|
||||
return walk(MODS_DIRECTORY_PATH)
|
||||
.filter(mod::isMatchingJar)
|
||||
.map(Path::toFile)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
public ITargetedMod[] getTargetedModEnumValues() {
|
||||
return TargetedMod.values();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user