diff --git a/core/src/main/java/net/neoforged/fml/ModLoader.java b/core/src/main/java/net/neoforged/fml/ModLoader.java
index 176280e07..aa892a90a 100644
--- a/core/src/main/java/net/neoforged/fml/ModLoader.java
+++ b/core/src/main/java/net/neoforged/fml/ModLoader.java
@@ -113,7 +113,6 @@ private ModLoader()
this.stateManager = new ModStateManager();
CrashReportCallables.registerCrashCallable("ModLauncher", FMLLoader::getLauncherInfo);
CrashReportCallables.registerCrashCallable("ModLauncher launch target", FMLLoader::launcherHandlerName);
- CrashReportCallables.registerCrashCallable("ModLauncher naming", FMLLoader::getNaming);
CrashReportCallables.registerCrashCallable("ModLauncher services", this::computeModLauncherServiceList);
CrashReportCallables.registerCrashCallable("FML Language Providers", this::computeLanguageList);
}
diff --git a/core/src/main/java/net/neoforged/fml/util/ObfuscationReflectionHelper.java b/core/src/main/java/net/neoforged/fml/util/ObfuscationReflectionHelper.java
index 152af4dc0..6f8da4990 100644
--- a/core/src/main/java/net/neoforged/fml/util/ObfuscationReflectionHelper.java
+++ b/core/src/main/java/net/neoforged/fml/util/ObfuscationReflectionHelper.java
@@ -7,227 +7,84 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.util.StringJoiner;
import cpw.mods.modlauncher.api.INameMappingService;
-import net.neoforged.fml.loading.FMLLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
-import com.google.common.base.Preconditions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
- * Some reflection helper code.
- * This may not work properly in Java 9 with its new, more restrictive, reflection management.
- * As such, if issues are encountered, please report them and we can see what we can do to expand
- * the compatibility.
- *
- * In other cases, AccessTransformers may be used.
- *
- * All field and method names should be passed in as SRG names, and this will automatically resolve if MCP mappings are detected.
- *
+ * @deprecated Since name remapping is no longer present, use {@link ReflectionHelper} or any other
+ * reflection utility instead.
*/
-@SuppressWarnings({"serial", "unchecked", "unused", "WeakerAccess"})
+@SuppressWarnings({"unused"})
+@Deprecated(forRemoval = true)
public class ObfuscationReflectionHelper
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Marker REFLECTION = MarkerManager.getMarker("REFLECTION");
/**
- * Remaps a name using the SRG naming function
- * @param domain The {@link INameMappingService.Domain} to use to remap the name.
- * @param name The name to try and remap.
- * @return The remapped name, or the original name if it couldn't be remapped.
+ * @deprecated Remapping has been removed, use {@code name} directly.
*/
@NotNull
public static String remapName(INameMappingService.Domain domain, String name)
{
- return FMLLoader.getNameFunction("srg").map(f->f.apply(domain, name)).orElse(name);
+ return name;
}
/**
- * Gets the value a field with the specified name in the given class.
- * Note: For performance, use {@link #findField(Class, String)} if you are getting the value more than once.
- *
- * Throws an exception if the field is not found or the value of the field cannot be gotten.
- *
- * @param classToAccess The class to find the field on.
- * @param instance The instance of the {@code classToAccess}.
- * @param fieldName The SRG (unmapped) name of the field to find (e.g. "f_46443_").
- * @param The type of the value.
- * @param The type of the {@code classToAccess}.
- * @return The value of the field with the specified name in the {@code classToAccess}.
- * @throws UnableToAccessFieldException If there was a problem getting the field.
- * @throws UnableToAccessFieldException If there was a problem getting the value.
+ * @deprecated Use {@link ReflectionHelper#getPrivateValue}.
*/
@Nullable
public static T getPrivateValue(Class super E> classToAccess, E instance, String fieldName)
{
- try
- {
- return (T) findField(classToAccess, fieldName).get(instance);
- }
- catch (UnableToFindFieldException e)
- {
- LOGGER.error(REFLECTION,"Unable to locate field {} ({}) on type {}", fieldName, remapName(INameMappingService.Domain.FIELD, fieldName), classToAccess.getName(), e);
- throw e;
- }
- catch (IllegalAccessException e)
- {
- LOGGER.error(REFLECTION,"Unable to access field {} ({}) on type {}", fieldName, remapName(INameMappingService.Domain.FIELD, fieldName), classToAccess.getName(), e);
- throw new UnableToAccessFieldException(e);
- }
+ return ReflectionHelper.getPrivateValue(classToAccess, instance, fieldName);
}
/**
- * Sets the value a field with the specified name in the given class.
- * Note: For performance, use {@link #findField(Class, String)} if you are setting the value more than once.
- *
- * Throws an exception if the field is not found or the value of the field cannot be set.
- *
- * @param classToAccess The class to find the field on.
- * @param instance The instance of the {@code classToAccess}.
- * @param value The new value for the field
- * @param fieldName The name of the field in the {@code classToAccess}.
- * @param The type of the value.
- * @param The type of the {@code classToAccess}.
- * @throws UnableToFindFieldException If there was a problem getting the field.
- * @throws UnableToAccessFieldException If there was a problem setting the value of the field.
+ * @deprecated Use {@link ReflectionHelper#setPrivateValue}.
*/
public static void setPrivateValue(@NotNull final Class super T> classToAccess, @NotNull final T instance, @Nullable final E value, @NotNull final String fieldName)
{
- try
- {
- findField(classToAccess, fieldName).set(instance, value);
- }
- catch (UnableToFindFieldException e)
- {
- LOGGER.error("Unable to locate any field {} on type {}", fieldName, classToAccess.getName(), e);
- throw e;
- }
- catch (IllegalAccessException e)
- {
- LOGGER.error("Unable to set any field {} on type {}", fieldName, classToAccess.getName(), e);
- throw new UnableToAccessFieldException(e);
- }
+ ReflectionHelper.setPrivateValue(classToAccess, instance, value, fieldName);
}
/**
- * Finds a method with the specified name and parameters in the given class and makes it accessible.
- * Note: For performance, store the returned value and avoid calling this repeatedly.
- *
- * Throws an exception if the method is not found.
- *
- * @param clazz The class to find the method on.
- * @param methodName The SRG (unmapped) name of the method to find (e.g. "m_5776_").
- * @param parameterTypes The parameter types of the method to find.
- * @return The method with the specified name and parameters in the given class.
- * @throws NullPointerException If {@code clazz} is null.
- * @throws NullPointerException If {@code methodName} is null.
- * @throws IllegalArgumentException If {@code methodName} is empty.
- * @throws NullPointerException If {@code parameterTypes} is null.
- * @throws UnableToFindMethodException If the method could not be found.
+ * @deprecated Use {@link ReflectionHelper#findMethod}.
*/
@NotNull
public static Method findMethod(@NotNull final Class> clazz, @NotNull final String methodName, @NotNull final Class>... parameterTypes)
{
- Preconditions.checkNotNull(clazz, "Class to find method on cannot be null.");
- Preconditions.checkNotNull(methodName, "Name of method to find cannot be null.");
- Preconditions.checkArgument(!methodName.isEmpty(), "Name of method to find cannot be empty.");
- Preconditions.checkNotNull(parameterTypes, "Parameter types of method to find cannot be null.");
-
- try
- {
- Method m = clazz.getDeclaredMethod(remapName(INameMappingService.Domain.METHOD, methodName), parameterTypes);
- m.setAccessible(true);
- return m;
- }
- catch (Exception e)
- {
- throw new UnableToFindMethodException(e);
- }
+ return ReflectionHelper.findMethod(clazz, methodName, parameterTypes);
}
/**
- * Finds a constructor with the specified parameter types in the given class and makes it accessible.
- * Note: For performance, store the returned value and avoid calling this repeatedly.
- *
- * Throws an exception if the constructor is not found.
- *
- * @param clazz The class to find the constructor in.
- * @param parameterTypes The parameter types of the constructor.
- * @param The type.
- * @return The constructor with the specified parameters in the given class.
- * @throws NullPointerException If {@code clazz} is null.
- * @throws NullPointerException If {@code parameterTypes} is null.
- * @throws UnknownConstructorException If the constructor could not be found.
+ * @deprecated Use {@link ReflectionHelper#findConstructor} instead.
*/
@NotNull
public static Constructor findConstructor(@NotNull final Class clazz, @NotNull final Class>... parameterTypes)
{
- Preconditions.checkNotNull(clazz, "Class to find constructor on cannot be null.");
- Preconditions.checkNotNull(parameterTypes, "Parameter types of constructor to find cannot be null.");
-
- try
- {
- Constructor constructor = clazz.getDeclaredConstructor(parameterTypes);
- constructor.setAccessible(true);
- return constructor;
- }
- catch (final NoSuchMethodException e)
- {
- final StringBuilder desc = new StringBuilder();
- desc.append(clazz.getSimpleName());
-
- StringJoiner joiner = new StringJoiner(", ", "(", ")");
- for (Class> type : parameterTypes)
- {
- joiner.add(type.getSimpleName());
- }
- desc.append(joiner);
-
- throw new UnknownConstructorException("Could not find constructor '" + desc.toString() + "' in " + clazz);
- }
+ return ReflectionHelper.findConstructor(clazz, parameterTypes);
}
/**
- * Finds a field with the specified name in the given class and makes it accessible.
- * Note: For performance, store the returned value and avoid calling this repeatedly.
- *
- * Throws an exception if the field is not found.
- *
- * @param clazz The class to find the field on.
- * @param fieldName The SRG (unmapped) name of the field to find (e.g. "f_46443_").
- * @param The type.
- * @return The constructor with the specified parameters in the given class.
- * @throws NullPointerException If {@code clazz} is null.
- * @throws NullPointerException If {@code fieldName} is null.
- * @throws IllegalArgumentException If {@code fieldName} is empty.
- * @throws UnableToFindFieldException If the field could not be found.
+ * @deprecated Use {@link ReflectionHelper#findField}
*/
@NotNull
public static Field findField(@NotNull final Class super T> clazz, @NotNull final String fieldName)
{
- Preconditions.checkNotNull(clazz, "Class to find field on cannot be null.");
- Preconditions.checkNotNull(fieldName, "Name of field to find cannot be null.");
- Preconditions.checkArgument(!fieldName.isEmpty(), "Name of field to find cannot be empty.");
-
- try
- {
- Field f = clazz.getDeclaredField(remapName(INameMappingService.Domain.FIELD, fieldName));
- f.setAccessible(true);
- return f;
- }
- catch (Exception e)
- {
- throw new UnableToFindFieldException(e);
- }
+ return ReflectionHelper.findField(clazz, fieldName);
}
+ /**
+ * @deprecated Use {@link net.neoforged.fml.util.ReflectionHelper.UnableToAccessFieldException} instead.
+ */
+ @Deprecated(forRemoval = true)
public static class UnableToAccessFieldException extends RuntimeException
{
private UnableToAccessFieldException(Exception e)
@@ -236,6 +93,10 @@ private UnableToAccessFieldException(Exception e)
}
}
+ /**
+ * @deprecated Use {@link net.neoforged.fml.util.ReflectionHelper.UnableToFindFieldException} instead.
+ */
+ @Deprecated(forRemoval = true)
public static class UnableToFindFieldException extends RuntimeException
{
private UnableToFindFieldException(Exception e)
@@ -244,6 +105,10 @@ private UnableToFindFieldException(Exception e)
}
}
+ /**
+ * @deprecated Use {@link net.neoforged.fml.util.ReflectionHelper.UnableToFindMethodException} instead.
+ */
+ @Deprecated(forRemoval = true)
public static class UnableToFindMethodException extends RuntimeException
{
public UnableToFindMethodException(Throwable failed)
@@ -252,6 +117,10 @@ public UnableToFindMethodException(Throwable failed)
}
}
+ /**
+ * @deprecated Use {@link net.neoforged.fml.util.ReflectionHelper.UnknownConstructorException} instead.
+ */
+ @Deprecated(forRemoval = true)
public static class UnknownConstructorException extends RuntimeException
{
public UnknownConstructorException(final String message)
diff --git a/core/src/main/java/net/neoforged/fml/util/ReflectionHelper.java b/core/src/main/java/net/neoforged/fml/util/ReflectionHelper.java
new file mode 100644
index 000000000..c0322735d
--- /dev/null
+++ b/core/src/main/java/net/neoforged/fml/util/ReflectionHelper.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) Forge Development LLC and contributors
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+package net.neoforged.fml.util;
+
+import com.google.common.base.Preconditions;
+import cpw.mods.modlauncher.api.INameMappingService;
+import net.neoforged.fml.loading.FMLLoader;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.StringJoiner;
+
+/**
+ * Some reflection helper code.
+ * This may not work properly in Java 9 with its new, more restrictive, reflection management.
+ * As such, if issues are encountered, please report them and we can see what we can do to expand
+ * the compatibility.
+ *
+ * In other cases, AccessTransformers may be used.
+ */
+@SuppressWarnings({"unchecked", "unused", "WeakerAccess"})
+public class ReflectionHelper
+{
+ private static final Logger LOGGER = LogManager.getLogger();
+ private static final Marker REFLECTION = MarkerManager.getMarker("REFLECTION");
+
+ /**
+ * Gets the value a field with the specified name in the given class.
+ * Note: For performance, use {@link #findField(Class, String)} if you are getting the value more than once.
+ *
+ * Throws an exception if the field is not found or the value of the field cannot be gotten.
+ *
+ * @param classToAccess The class to find the field on.
+ * @param instance The instance of the {@code classToAccess} or {@code null} to access static fields.
+ * @param fieldName The name of the field to find.
+ * @param The type of the value.
+ * @param The type of the {@code classToAccess}.
+ * @return The value of the field with the specified name in the {@code classToAccess}.
+ * @throws UnableToAccessFieldException If there was a problem getting the field or its value.
+ */
+ @Nullable
+ public static T getPrivateValue(@NotNull Class super E> classToAccess, @Nullable E instance, @NotNull String fieldName)
+ {
+ try
+ {
+ return (T) findField(classToAccess, fieldName).get(instance);
+ }
+ catch (UnableToFindFieldException e)
+ {
+ LOGGER.error(REFLECTION,"Unable to locate field {} ({}) on type {}", fieldName, fieldName, classToAccess.getName(), e);
+ throw e;
+ }
+ catch (IllegalAccessException e)
+ {
+ LOGGER.error(REFLECTION,"Unable to access field {} ({}) on type {}", fieldName, fieldName, classToAccess.getName(), e);
+ throw new UnableToAccessFieldException(e);
+ }
+ }
+
+ /**
+ * Sets the value a field with the specified name in the given class.
+ * Note: For performance, use {@link #findField(Class, String)} if you are setting the value more than once.
+ *
+ * Throws an exception if the field is not found or the value of the field cannot be set.
+ *
+ * @param classToAccess The class to find the field on.
+ * @param instance The instance of the {@code classToAccess} or {@code null} to access static fields.
+ * @param value The new value for the field
+ * @param fieldName The name of the field in the {@code classToAccess}.
+ * @param The type of the value.
+ * @param The type of the {@code classToAccess}.
+ * @throws UnableToFindFieldException If there was a problem getting the field.
+ * @throws UnableToAccessFieldException If there was a problem setting the value of the field.
+ */
+ public static void setPrivateValue(@NotNull final Class super T> classToAccess, @Nullable final T instance, @Nullable final E value, @NotNull final String fieldName)
+ {
+ try
+ {
+ findField(classToAccess, fieldName).set(instance, value);
+ }
+ catch (UnableToFindFieldException e)
+ {
+ LOGGER.error("Unable to locate any field {} on type {}", fieldName, classToAccess.getName(), e);
+ throw e;
+ }
+ catch (IllegalAccessException e)
+ {
+ LOGGER.error("Unable to set any field {} on type {}", fieldName, classToAccess.getName(), e);
+ throw new UnableToAccessFieldException(e);
+ }
+ }
+
+ /**
+ * Finds a method with the specified name and parameters in the given class and makes it accessible.
+ * Note: For performance, store the returned value and avoid calling this repeatedly.
+ *
+ * Throws an exception if the method is not found.
+ *
+ * @param clazz The class to find the method on.
+ * @param methodName The name of the method to find.
+ * @param parameterTypes The parameter types of the method to find.
+ * @return The method with the specified name and parameters in the given class.
+ * @throws NullPointerException If {@code clazz} is null.
+ * @throws NullPointerException If {@code methodName} is null.
+ * @throws IllegalArgumentException If {@code methodName} is empty.
+ * @throws NullPointerException If {@code parameterTypes} is null.
+ * @throws UnableToFindMethodException If the method could not be found.
+ */
+ @NotNull
+ public static Method findMethod(@NotNull final Class> clazz, @NotNull final String methodName, @NotNull final Class>... parameterTypes)
+ {
+ Preconditions.checkNotNull(clazz, "Class to find method on cannot be null.");
+ Preconditions.checkNotNull(methodName, "Name of method to find cannot be null.");
+ Preconditions.checkArgument(!methodName.isEmpty(), "Name of method to find cannot be empty.");
+ Preconditions.checkNotNull(parameterTypes, "Parameter types of method to find cannot be null.");
+
+ try
+ {
+ Method m = clazz.getDeclaredMethod(methodName, parameterTypes);
+ m.setAccessible(true);
+ return m;
+ }
+ catch (Exception e)
+ {
+ throw new UnableToFindMethodException(e);
+ }
+ }
+
+ /**
+ * Finds a constructor with the specified parameter types in the given class and makes it accessible.
+ * Note: For performance, store the returned value and avoid calling this repeatedly.
+ *
+ * Throws an exception if the constructor is not found.
+ *
+ * @param clazz The class to find the constructor in.
+ * @param parameterTypes The parameter types of the constructor.
+ * @param The type.
+ * @return The constructor with the specified parameters in the given class.
+ * @throws NullPointerException If {@code clazz} is null.
+ * @throws NullPointerException If {@code parameterTypes} is null.
+ * @throws UnknownConstructorException If the constructor could not be found.
+ */
+ @NotNull
+ public static Constructor findConstructor(@NotNull final Class clazz, @NotNull final Class>... parameterTypes)
+ {
+ Preconditions.checkNotNull(clazz, "Class to find constructor on cannot be null.");
+ Preconditions.checkNotNull(parameterTypes, "Parameter types of constructor to find cannot be null.");
+
+ try
+ {
+ Constructor constructor = clazz.getDeclaredConstructor(parameterTypes);
+ constructor.setAccessible(true);
+ return constructor;
+ }
+ catch (final NoSuchMethodException e)
+ {
+ final StringBuilder desc = new StringBuilder();
+ desc.append(clazz.getSimpleName());
+
+ StringJoiner joiner = new StringJoiner(", ", "(", ")");
+ for (Class> type : parameterTypes)
+ {
+ joiner.add(type.getSimpleName());
+ }
+ desc.append(joiner);
+
+ throw new UnknownConstructorException("Could not find constructor '" + desc + "' in " + clazz);
+ }
+ }
+
+ /**
+ * Finds a field with the specified name in the given class and makes it accessible.
+ * Note: For performance, store the returned value and avoid calling this repeatedly.
+ *
+ * Throws an exception if the field is not found.
+ *
+ * @param clazz The class to find the field on.
+ * @param fieldName The name of the field to find.
+ * @param The type.
+ * @return The constructor with the specified parameters in the given class.
+ * @throws NullPointerException If {@code clazz} is null.
+ * @throws NullPointerException If {@code fieldName} is null.
+ * @throws IllegalArgumentException If {@code fieldName} is empty.
+ * @throws UnableToFindFieldException If the field could not be found.
+ */
+ @NotNull
+ public static Field findField(@NotNull final Class super T> clazz, @NotNull final String fieldName)
+ {
+ Preconditions.checkNotNull(clazz, "Class to find field on cannot be null.");
+ Preconditions.checkNotNull(fieldName, "Name of field to find cannot be null.");
+ Preconditions.checkArgument(!fieldName.isEmpty(), "Name of field to find cannot be empty.");
+
+ try
+ {
+ Field f = clazz.getDeclaredField(fieldName);
+ f.setAccessible(true);
+ return f;
+ }
+ catch (Exception e)
+ {
+ throw new UnableToFindFieldException(e);
+ }
+ }
+
+ public static class UnableToAccessFieldException extends RuntimeException
+ {
+ private UnableToAccessFieldException(Exception e)
+ {
+ super(e);
+ }
+ }
+
+ public static class UnableToFindFieldException extends RuntimeException
+ {
+ private UnableToFindFieldException(Exception e)
+ {
+ super(e);
+ }
+ }
+
+ public static class UnableToFindMethodException extends RuntimeException
+ {
+ public UnableToFindMethodException(Throwable failed)
+ {
+ super(failed);
+ }
+ }
+
+ public static class UnknownConstructorException extends RuntimeException
+ {
+ public UnknownConstructorException(final String message)
+ {
+ super(message);
+ }
+ }
+}
diff --git a/loader/src/main/java/net/neoforged/fml/loading/FMLEnvironment.java b/loader/src/main/java/net/neoforged/fml/loading/FMLEnvironment.java
index ee5725b3e..5c39fc958 100644
--- a/loader/src/main/java/net/neoforged/fml/loading/FMLEnvironment.java
+++ b/loader/src/main/java/net/neoforged/fml/loading/FMLEnvironment.java
@@ -15,16 +15,10 @@
public class FMLEnvironment
{
public static final Dist dist = FMLLoader.getDist();
- public static final String naming = FMLLoader.getNaming();
public static final boolean production = FMLLoader.isProduction() || System.getProperties().containsKey("production");
public static final boolean secureJarsEnabled = FMLLoader.isSecureJarEnabled();
static void setupInteropEnvironment(IEnvironment environment) {
- environment.computePropertyIfAbsent(IEnvironment.Keys.NAMING.get(), v->naming);
environment.computePropertyIfAbsent(Environment.Keys.DIST.get(), v->dist);
}
-
- public static class Keys {
- public static final Supplier> LOCATORCLASSLOADER = IEnvironment.buildKey("LOCATORCLASSLOADER",ClassLoader.class);
- }
}
diff --git a/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java b/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java
index a1efb7d2e..0f67e19cb 100644
--- a/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java
+++ b/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java
@@ -27,7 +27,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
-import java.util.function.BiFunction;
import java.util.stream.Collectors;
public class FMLLoader
@@ -38,7 +37,6 @@ public class FMLLoader
private static ICoreModProvider coreModProvider;
private static LanguageLoadingProvider languageLoadingProvider;
private static Dist dist;
- private static String naming;
private static LoadingModList loadingModList;
private static RuntimeDistCleaner runtimeDistCleaner;
private static Path gamePath;
@@ -138,7 +136,6 @@ static void setupLaunchHandler(final IEnvironment environment, final Map> getNameFunction(final String naming) {
- return Launcher.INSTANCE.environment().findNameMapping(naming);
- }
-
public static String getLauncherInfo() {
return Launcher.INSTANCE.environment().getProperty(IEnvironment.Keys.MLIMPL_VERSION.get()).orElse("MISSING");
}
diff --git a/loader/src/main/java/net/neoforged/fml/loading/MCPNamingService.java b/loader/src/main/java/net/neoforged/fml/loading/MCPNamingService.java
deleted file mode 100644
index b10b54069..000000000
--- a/loader/src/main/java/net/neoforged/fml/loading/MCPNamingService.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) Forge Development LLC and contributors
- * SPDX-License-Identifier: LGPL-2.1-only
- */
-
-package net.neoforged.fml.loading;
-
-import com.mojang.logging.LogUtils;
-import cpw.mods.modlauncher.api.INameMappingService;
-import org.apache.commons.lang3.tuple.Pair;
-import org.slf4j.Logger;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-
-public class MCPNamingService implements INameMappingService {
- private static final Logger LOGGER = LogUtils.getLogger();
- private HashMap methods;
- private HashMap fields;
-
- @Override
- public String mappingName() {
- return "srgtomcp";
- }
-
- @Override
- public String mappingVersion() {
- return "1234"; //TODO: Minecraft Version?
- }
-
- @Override
- public Map.Entry understanding() {
- return Pair.of("srg", "mcp");
- }
-
- @Override
- public BiFunction namingFunction() {
- return this::findMapping;
- }
-
- private String findMapping(final Domain domain, final String srgName) {
- switch (domain) {
- case CLASS:
- return srgName;
- case FIELD:
- return findFieldMapping(srgName);
- case METHOD:
- return findMethodMapping(srgName);
- }
- return srgName;
- }
-
- private String findMethodMapping(final String origin) {
- if (methods == null) {
- HashMap tmpmethods = new HashMap<>(1000);
- loadMappings("methods.csv", tmpmethods::put);
- methods = tmpmethods;
- LOGGER.debug(LogMarkers.CORE, "Loaded {} method mappings from methods.csv", methods.size());
- }
- return methods.getOrDefault(origin, origin);
- }
-
- private String findFieldMapping(final String origin) {
- if (fields == null) {
- HashMap tmpfields = new HashMap<>(1000);
- loadMappings("fields.csv", tmpfields::put);
- fields = tmpfields;
- LOGGER.debug(LogMarkers.CORE, "Loaded {} field mappings from fields.csv", fields.size());
- }
- return fields.getOrDefault(origin, origin);
- }
-
- private static void loadMappings(final String mappingFileName, BiConsumer mapStore) {
- URL path = ClassLoader.getSystemResource(mappingFileName); //We EXPLICITLY go through the SystemClassLoader here because this is dev-time only. And will be on the root classpath.
- if (path == null)
- return;
-
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(path.openStream()))) {
- reader.lines().skip(1).map(e -> e.split(",")).forEach(e -> mapStore.accept(e[0], e[1]));
- } catch (IOException e1) {
- LOGGER.error(LogMarkers.CORE, "Error reading mappings", e1);
- }
- }
-}
diff --git a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonClientLaunchHandler.java b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonClientLaunchHandler.java
index f59b95fa5..9e717deba 100644
--- a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonClientLaunchHandler.java
+++ b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonClientLaunchHandler.java
@@ -16,7 +16,6 @@
public abstract class CommonClientLaunchHandler extends CommonLaunchHandler {
@Override public Dist getDist() { return Dist.CLIENT; }
- @Override public String getNaming() { return "srg"; }
@Override public boolean isProduction() { return true; }
@Override
diff --git a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonDevLaunchHandler.java b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonDevLaunchHandler.java
index 55bc5cfbb..9138fee32 100644
--- a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonDevLaunchHandler.java
+++ b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonDevLaunchHandler.java
@@ -20,7 +20,6 @@
import java.util.stream.Stream;
public abstract class CommonDevLaunchHandler extends CommonLaunchHandler {
- @Override public String getNaming() { return "mcp"; }
@Override public boolean isProduction() { return false; }
@Override
diff --git a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonLaunchHandler.java b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonLaunchHandler.java
index ecdf54167..48c38419b 100644
--- a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonLaunchHandler.java
+++ b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonLaunchHandler.java
@@ -39,8 +39,6 @@ public record LocatedPaths(List minecraftPaths, UnionPathFilter minecraftF
public abstract Dist getDist();
- public abstract String getNaming();
-
public boolean isProduction() {
return false;
}
diff --git a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonServerLaunchHandler.java b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonServerLaunchHandler.java
index b2fe86d00..733e47b75 100644
--- a/loader/src/main/java/net/neoforged/fml/loading/targets/CommonServerLaunchHandler.java
+++ b/loader/src/main/java/net/neoforged/fml/loading/targets/CommonServerLaunchHandler.java
@@ -18,7 +18,6 @@
public abstract class CommonServerLaunchHandler extends CommonLaunchHandler {
@Override public Dist getDist() { return Dist.DEDICATED_SERVER; }
- @Override public String getNaming() { return "srg"; }
@Override public boolean isProduction() { return true; }
@Override
diff --git a/loader/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.INameMappingService b/loader/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.INameMappingService
deleted file mode 100644
index 4994ff917..000000000
--- a/loader/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.INameMappingService
+++ /dev/null
@@ -1 +0,0 @@
-net.neoforged.fml.loading.MCPNamingService