Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Add findJarInClassPath, Bump version #7

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ buildscript {
}
}
dependencies {
classpath 'com.github.GTNH2:ForgeGradle:FG_1.2-SNAPSHOT'
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.4'
}
}

apply plugin: 'forge'

version = "1.3.3"
version = "1.4.0"
group = "ru.timeconqueror" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "SpongeMixins"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Path;

import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import com.google.common.io.Files;
Expand All @@ -15,7 +17,7 @@ public final class MinecraftURLClassPath {
/**
* Utility to manipulate the minecraft URL ClassPath
*/

private static final Path MOD_DIRECTORY_PATH = new File(Launch.minecraftHome, "mods/").toPath();
private static final Field modClassLoaderField;
private static final Field loaderinstanceField;
private static final Field mainClassLoaderField;
Expand Down Expand Up @@ -50,18 +52,42 @@ public final class MinecraftURLClassPath {
/**
* Get a jar within the minecraft mods directory
*/
@SuppressWarnings("All")
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);
return java.nio.file.Files.walk(MOD_DIRECTORY_PATH)
.filter( p -> {
final String filename = p.toString();
final String extension = Files.getFileExtension(filename);

return Files.getNameWithoutExtension(filename).contains(jarname) && ("jar".equals(extension) || "litemod".equals(extension));
})
.map(Path::toFile)
.findFirst()
.orElse(null);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

/**
* Returns true if the given mod is found within the class path; generally useful for identifying if a mod has been loaded
* while running in dev due to a compile dependency
*/
@SuppressWarnings("All")
public static boolean findJarInClassPath(final String jarname) {
for(URL url : ucp.getURLs()) {
final String filename = url.getFile();
final String extension = Files.getFileExtension(filename);

if(Files.getNameWithoutExtension(filename).contains(jarname) && ("jar".equals(extension) || "litemod".equals(extension))) {
return true;
}
}
return false;
}

/**
* Adds a Jar to the Minecraft URL ClassPath
* - Needed when using mixins on classes outside of Minecraft or other coremods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = SpongeMixins.MODID, version = "1.3.0", name = SpongeMixins.NAME, acceptableRemoteVersions = "*")
@Mod(modid = SpongeMixins.MODID, version = "1.4.0", name = SpongeMixins.NAME, acceptableRemoteVersions = "*")
public class SpongeMixins {
public static final String NAME = "SpongeMixins Loader";
public static final String MODID = "spongemixins";
Expand Down