mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-12 08:27:49 +00:00
Initial Commit
This commit is contained in:
24 files changed
+2536
No files matched your search
@@ -0,0 +1,8 @@
|
||||
package com.falsepattern.endlessids;
|
||||
|
||||
public class Tags {
|
||||
public static final String MODID = "GRADLETOKEN_MODID";
|
||||
public static final String MODNAME = "GRADLETOKEN_MODNAME";
|
||||
public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME";
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.falsepattern.endlessids.mixin.plugin;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModClassLoader;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import sun.misc.URLClassPath;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Backport from spongemixins 1.3
|
||||
*/
|
||||
public final class MinecraftURLClassPath {
|
||||
/**
|
||||
* Utility to manipulate the minecraft URL ClassPath
|
||||
*/
|
||||
|
||||
private static final Field modClassLoaderField;
|
||||
private static final Field loaderinstanceField;
|
||||
private static final Field mainClassLoaderField;
|
||||
private static final Field ucpField;
|
||||
private static final ModClassLoader modClassLoader;
|
||||
private static final LaunchClassLoader mainClassLoader;
|
||||
private static final URLClassPath ucp;
|
||||
|
||||
static {
|
||||
try {
|
||||
modClassLoaderField = Loader.class.getDeclaredField("modClassLoader");
|
||||
modClassLoaderField.setAccessible(true);
|
||||
|
||||
loaderinstanceField = Loader.class.getDeclaredField("instance");
|
||||
loaderinstanceField.setAccessible(true);
|
||||
|
||||
mainClassLoaderField = ModClassLoader.class.getDeclaredField("mainClassLoader");
|
||||
mainClassLoaderField.setAccessible(true);
|
||||
|
||||
ucpField = LaunchClassLoader.class.getSuperclass().getDeclaredField("ucp");
|
||||
ucpField.setAccessible(true);
|
||||
|
||||
Object loader = loaderinstanceField.get(null);
|
||||
modClassLoader = (ModClassLoader)modClassLoaderField.get(loader);
|
||||
mainClassLoader = (LaunchClassLoader)mainClassLoaderField.get(modClassLoader);
|
||||
ucp = (URLClassPath)ucpField.get(mainClassLoader);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a jar within the minecraft mods directory
|
||||
*/
|
||||
public static File getJarInModPath(final String jarname) {
|
||||
try {
|
||||
return java.nio.file.Files.walk(new File(Launch.minecraftHome, "mods/").toPath()).filter( p -> {
|
||||
final String filename = p.toString();
|
||||
return Files.getNameWithoutExtension(filename).contains(jarname) && Files.getFileExtension(filename).equals("jar");
|
||||
}).map(Path::toFile).findFirst().orElse(null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Jar to the Minecraft URL ClassPath
|
||||
* - Needed when using mixins on classes outside of Minecraft or other coremods
|
||||
*/
|
||||
public static void addJar(File pathToJar) throws Exception {
|
||||
ucp.addURL(pathToJar.toURI().toURL());
|
||||
}
|
||||
|
||||
private MinecraftURLClassPath() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.falsepattern.endlessids.mixin.plugin;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public enum Mixin {
|
||||
;
|
||||
|
||||
public final String mixin;
|
||||
public final Set<TargetedMod> targetedMods;
|
||||
public final Set<TargetedMod> avoidedMods;
|
||||
private final Side side;
|
||||
|
||||
Mixin(Builder builder) {
|
||||
this.mixin = builder.mixin;
|
||||
this.targetedMods = builder.targetedMods;
|
||||
this.avoidedMods = builder.avoidedMods;
|
||||
this.side = builder.side;
|
||||
}
|
||||
|
||||
public boolean shouldLoad(List<TargetedMod> loadedMods) {
|
||||
return (side == Side.COMMON
|
||||
|| side == Side.SERVER && FMLLaunchHandler.side().isServer()
|
||||
|| side == Side.CLIENT && FMLLaunchHandler.side().isClient())
|
||||
&& loadedMods.containsAll(targetedMods) && avoidedMods.stream().noneMatch(loadedMods::contains);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static Builder builder(Side side) {
|
||||
return new Builder(side);
|
||||
}
|
||||
|
||||
private static class Builder {
|
||||
public String mixin;
|
||||
public Side side;
|
||||
public Set<TargetedMod> targetedMods = new HashSet<>();
|
||||
public final Set<TargetedMod> avoidedMods = new HashSet<>();
|
||||
|
||||
public Builder(Side side) {
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public Builder mixin(String mixinClass) {
|
||||
mixin = side.name().toLowerCase() + "." + mixinClass;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder target(TargetedMod mod) {
|
||||
targetedMods.add(mod);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder avoid(TargetedMod mod) {
|
||||
avoidedMods.add(mod);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private enum Side {
|
||||
COMMON,
|
||||
CLIENT,
|
||||
SERVER
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
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 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();
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@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 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());
|
||||
}
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.falsepattern.endlessids.mixin.plugin;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import lombok.val;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public enum TargetedMod {
|
||||
|
||||
VANILLA("Minecraft", "", "", true);
|
||||
|
||||
public final String modName;
|
||||
public final String jarNamePrefixLowercase;
|
||||
public final String jarNameContainsLowercase;
|
||||
|
||||
public final boolean loadInDevelopment;
|
||||
|
||||
TargetedMod(String modName, String jarNamePrefix, String jarNameContains, boolean loadInDevelopment) {
|
||||
this.modName = modName;
|
||||
this.jarNamePrefixLowercase = jarNamePrefix.toLowerCase();
|
||||
this.jarNameContainsLowercase = jarNameContains.toLowerCase();
|
||||
this.loadInDevelopment = loadInDevelopment;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public boolean isMatchingJar(Path path) {
|
||||
val pathString = path.toString();
|
||||
val nameLowerCase = Files.getNameWithoutExtension(pathString).toLowerCase();
|
||||
val fileExtension = Files.getFileExtension(pathString);
|
||||
|
||||
return "jar".equals(fileExtension) && nameLowerCase.startsWith(jarNamePrefixLowercase) && nameLowerCase.contains(jarNameContainsLowercase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TargetedMod{" +
|
||||
"modName='" + modName + '\'' +
|
||||
", jarNamePrefixLowercase='" + jarNamePrefixLowercase + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user