Add I18n accessor, fix up some mod log messages, make the EnumExtender work.

This commit is contained in:
cpw 2018-09-09 23:16:51 -04:00
parent 334d925972
commit a4f2802306
10 changed files with 97 additions and 33 deletions

View File

@ -117,6 +117,7 @@ project(':forge') {
into "$buildDir/classes/java/main"
}
}
// jvmArgs = ['-verbose:class']
classpath sourceSets.main.runtimeClasspath
main 'net.minecraftforge.fml.LaunchTesting'
systemProperties target:'fmldevclient'

View File

@ -0,0 +1,10 @@
--- a/net/minecraft/client/resources/I18n.java
+++ b/net/minecraft/client/resources/I18n.java
@@ -9,6 +9,7 @@
static void setLocale(Locale i18nLocaleIn) {
i18nLocale = i18nLocaleIn;
+ net.minecraftforge.fml.ForgeI18n.loadLanguageData(i18nLocale.properties);
}
public static String format(String translateKey, Object... parameters) {

View File

@ -88,8 +88,6 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
public static boolean fixVanillaCascading = false; // There are various places in vanilla that cause cascading worldgen. Enabling this WILL change where blocks are placed to prevent this.
// DO NOT contact Forge about worldgen not 'matching' vanilla if this flag is set.
static final Logger log = LogManager.getLogger(ForgeVersion.MOD_ID);
private static Configuration config;
private static ForgeMod INSTANCE;
public static ForgeMod getInstance()

View File

@ -20,6 +20,7 @@ package net.minecraftforge.common.asm;
import java.nio.file.Path;
import net.minecraftforge.fml.AdvancedLogMessageAdapter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Opcodes;
@ -65,7 +66,7 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
if ((classNode.access & Opcodes.ACC_ENUM) == 0)
return classNode;
Type array = Type.getType("[" + classType.getInternalName());
Type array = Type.getType("[" + classType.getDescriptor());
final int flags = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC;
FieldNode values = classNode.fields.stream().filter(f -> f.desc.contentEquals(array.getDescriptor()) && ((f.access & flags) == flags)).findFirst().orElse(null);
@ -87,16 +88,21 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
MethodNode ctr = classNode.methods.stream().filter(m -> m.name.equals("<init>") && m.desc.equals(desc)).findFirst().orElse(null);
if (ctr == null)
{
LOGGER.error("Enum has create method with no matching constructor:");
LOGGER.error(" Target: " + desc);
classNode.methods.stream().filter(m -> m.name.equals("<init>")).forEach(m -> LOGGER.error(" :" + m.desc));
LOGGER.error(()->new AdvancedLogMessageAdapter(sb-> {
sb.append("Enum has create method with no matching constructor:\n");
sb.append(" Target: ").append(desc).append("\n");
classNode.methods.stream().filter(m -> m.name.equals("<init>")).forEach(m -> sb.append(" :").append(m.desc).append("\n"));
}));
throw new IllegalStateException("Enum has create method with no matching constructor: " + desc);
}
if (values == null)
{
LOGGER.error("Enum has create method but we could not find $VALUES:");
classNode.fields.stream().filter(f -> (f.access & Opcodes.ACC_STATIC) != 0).forEach(m -> LOGGER.error(" " + m.name + " " + m.desc));
LOGGER.error(()->new AdvancedLogMessageAdapter(sb-> {
sb.append("Enum has create method but we could not find $VALUES. Found:\n");
classNode.fields.stream().filter(f -> (f.access & Opcodes.ACC_STATIC) != 0).
forEach(m -> sb.append(" ").append(m.name).append(" ").append(m.desc).append("\n"));
}));
throw new IllegalStateException("Enum has create method but we could not find $VALUES");
}
@ -109,17 +115,18 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
ins.dup();
ins.load(0, STRING);
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.arraylength();
ins.iconst(1);
ins.add(Type.INT_TYPE);
for (int x = 1; x < args.length; x++)
ins.load(x, args[x]);
ins.invokespecial(classType.getDescriptor(), "<init>", desc, false);
ins.invokespecial(classType.getInternalName(), "<init>", desc, false);
ins.store(1, classType);
// VALUES = ArrayUtils.add(VALUES, ret)
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.load(1, classType);
ins.invokestatic(ARRAY_UTILS.getDescriptor(), "add", ADD_DESC, false);
ins.checkcast(array);
ins.invokestatic(ARRAY_UTILS.getInternalName(), "add", ADD_DESC, false);
ins.checkcast(Type.getType(values.desc));
ins.putstatic(classType.getInternalName(), values.name, values.desc);
//EnumHelper.cleanEnumCache(ThisType.class)
ins.visitLdcInsn(classType);

View File

@ -0,0 +1,41 @@
package net.minecraftforge.fml;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.util.StringBuilderFormattable;
import java.util.function.Consumer;
public class AdvancedLogMessageAdapter implements Message, StringBuilderFormattable {
private static final Object[] EMPTY = new Object[0];
private final Consumer<StringBuilder> logMessageBuilder;
public AdvancedLogMessageAdapter(final Consumer<StringBuilder> logMessageBuilder) {
this.logMessageBuilder = logMessageBuilder;
}
@Override
public String getFormattedMessage() {
return "";
}
@Override
public String getFormat() {
return "";
}
@Override
public Object[] getParameters() {
return EMPTY;
}
@Override
public Throwable getThrowable() {
return null;
}
@Override
public void formatTo(final StringBuilder buffer) {
logMessageBuilder.accept(buffer);
}
}

View File

@ -22,7 +22,6 @@ package net.minecraftforge.fml;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.ModList;
import java.text.MessageFormat;
import java.util.Arrays;
@ -47,7 +46,7 @@ public class BrandingControl
brd.add("Forge " + ForgeVersion.getVersion());
int tModCount = ModList.get().size();
brd.add(MessageFormat.format("{0,choice,0#No mods|1#1 mod|1<{0} mods} loaded", tModCount));
brd.add(MessageFormat.format(ForgeI18n.getPattern("fml.menu.loadingmods"), tModCount));
brandings = brd.build();
brandingsNoMC = brandings.subList(1, brandings.size());
}

View File

@ -0,0 +1,15 @@
package net.minecraftforge.fml;
import java.util.Map;
public class ForgeI18n {
private static Map<String,String> i18n;
static String getPattern(final String patternName) {
return i18n.get(patternName);
}
public static void loadLanguageData(final Map<String, String> properties) {
i18n = properties;
}
}

View File

@ -46,7 +46,8 @@ public class ResourcePackLoader
public static IResourcePack getResourcePackFor(String modId)
{
return modResourcePacks.get(ModList.get().getModFileById(modId).getFile());
if (modId == "forge") return forgePack;
else return modResourcePacks.get(ModList.get().getModFileById(modId).getFile());
}
@SuppressWarnings("unchecked")

View File

@ -30,7 +30,7 @@ import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.client.IDisplayableError;
import net.minecraftforge.fml.client.gui.GuiDupesFound;
public class DuplicateModsFoundException extends LoaderException implements IDisplayableError
public class DuplicateModsFoundException extends LoaderException
{
private static final long serialVersionUID = 1L;
public SetMultimap<ModContainer, File> dupes;
@ -38,22 +38,4 @@ public class DuplicateModsFoundException extends LoaderException implements IDis
public DuplicateModsFoundException(SetMultimap<ModContainer, File> dupes) {
this.dupes = dupes;
}
@Override
protected void printStackTrace(WrappedPrintStream stream)
{
stream.println("Duplicate Mods:");
for (Entry<ModContainer, File> e : dupes.entries())
{
stream.println(String.format("\t%s : %s", e.getKey().getModId(), e.getValue().getAbsolutePath()));
}
stream.println("");
}
@Override
@OnlyIn(Dist.CLIENT)
public GuiScreen createGui()
{
return new GuiDupesFound(this);
}
}

View File

@ -0,0 +1,10 @@
{
"fml.menu.mods": "Mods",
"fml.menu.mods.normal": "Off",
"fml.menu.mods.search": "Search",
"fml.menu.mods.a_to_z": "A-Z",
"fml.menu.mods.z_to_a": "Z-A",
"fml.menu.mods.config": "Config",
"fml.menu.modoptions": "Mod Options...",
"fml.menu.loadingmods": "{0,choice,0#No mods|1#1 mod|1<{0} mods} loaded"
}