mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 10:17:29 +00:00
move minecraft home path retrieval to separate util class
This commit is contained in:
5 files changed
+27
-10
No files matched your search
@@ -3,10 +3,13 @@ package com.falsepattern.lib.config;
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.internal.FalsePatternLib;
|
||||
import com.falsepattern.lib.util.FileUtil;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Path;
|
||||
@@ -24,6 +27,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
@@ -49,6 +53,7 @@ public class ConfigurationManager {
|
||||
* @param configClass The class to register.
|
||||
*/
|
||||
public static void registerConfig(Class<?> configClass) throws ConfigException {
|
||||
init();
|
||||
val cfg = Optional.ofNullable(configClass.getAnnotation(Config.class))
|
||||
.orElseThrow(() -> new ConfigException(
|
||||
"Class " + configClass.getName() + " does not have a @Config annotation!"));
|
||||
@@ -192,6 +197,7 @@ public class ConfigurationManager {
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static List<IConfigElement> getConfigElements(Class<?> configClass) throws ConfigException {
|
||||
init();
|
||||
val cfg = Optional.ofNullable(configClass.getAnnotation(Config.class))
|
||||
.orElseThrow(() -> new ConfigException(
|
||||
"Class " + configClass.getName() + " does not have a @Config annotation!"));
|
||||
@@ -217,14 +223,11 @@ public class ConfigurationManager {
|
||||
})).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal, do not use.
|
||||
*/
|
||||
public static void init() {
|
||||
private static void init() {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
configDir = CoreLoadingPlugin.mcDir.toPath().resolve("config");
|
||||
configDir = FileUtil.getMinecraftHome().toPath().resolve("config");
|
||||
FMLCommonHandler.instance().bus().register(instance);
|
||||
initialized = true;
|
||||
}
|
||||
@@ -236,6 +239,7 @@ public class ConfigurationManager {
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
init();
|
||||
val config = configs.get(event.modID);
|
||||
if (config == null) {
|
||||
return;
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.falsepattern.lib.util.FileUtil;
|
||||
import lombok.*;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
@@ -84,7 +85,7 @@ public class DependencyLoader {
|
||||
}
|
||||
return;
|
||||
}
|
||||
val modsDir = new File(CoreLoadingPlugin.mcDir, "mods");
|
||||
val modsDir = new File(FileUtil.getMinecraftHome(), "mods");
|
||||
val mavenJarName =
|
||||
String.format("%s-%s%s.jar", artifactId, preferredVersion, (suffix != null) ? ("-" + suffix) : "");
|
||||
val jarName = groupId + "-" + mavenJarName;
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Map;
|
||||
@Name(Tags.MODID)
|
||||
@SortingIndex(500)
|
||||
public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
public static File mcDir;
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
@@ -31,8 +30,6 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
mcDir = (File) data.get("mcLocation");
|
||||
ConfigurationManager.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.falsepattern.lib.util.FileUtil;
|
||||
import lombok.val;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -23,7 +25,7 @@ import static java.nio.file.Files.walk;
|
||||
|
||||
@StableAPI(since = "0.8.0")
|
||||
public interface IMixinPlugin extends IMixinConfigPlugin {
|
||||
Path MODS_DIRECTORY_PATH = CoreLoadingPlugin.mcDir.toPath().resolve("mods");
|
||||
Path MODS_DIRECTORY_PATH = FileUtil.getMinecraftHome().toPath().resolve("mods");
|
||||
|
||||
static Logger createLogger(String modName) {
|
||||
return LogManager.getLogger(modName + " Mixin Loader");
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.falsepattern.lib.util;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@StableAPI(since = "0.8.2")
|
||||
public class FileUtil {
|
||||
public static File getMinecraftHome() {
|
||||
return Launch.minecraftHome == null ? new File(".") : Launch.minecraftHome;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user