Let's get hooking!

This commit is contained in:
Christian Weeks 2012-05-05 19:52:53 -04:00
parent e0e77a6bb5
commit bca823c421
5 changed files with 73 additions and 6 deletions

View file

@ -95,7 +95,7 @@ public class ModLoader
*/
public static void addLocalization(String key, String value)
{
// TODO
addLocalization(key, "en_US", value);
}
/**
@ -107,7 +107,7 @@ public class ModLoader
*/
public static void addLocalization(String key, String lang, String value)
{
// TODO
FMLCommonHandler.instance().addStringLocalization(key, lang, value);
}
/**
@ -118,7 +118,7 @@ public class ModLoader
*/
public static void addName(Object instance, String name)
{
// TODO
addName(instance,"en_US",name);
}
/**
@ -130,7 +130,18 @@ public class ModLoader
*/
public static void addName(Object instance, String lang, String name)
{
// TODO
String objectName;
if (instance instanceof Item) {
objectName=((Item)instance).func_20009_a();
} else if (instance instanceof Block) {
objectName=((Block)instance).func_20013_i();
} else if (instance instanceof ItemStack) {
objectName=Item.field_233_c[((ItemStack)instance).field_1617_c].func_21011_b((ItemStack)instance);
} else {
throw new IllegalArgumentException(String.format("Illegal object for naming %s",instance));
}
objectName+=".name";
addLocalization(objectName, lang, name);
}
/**

View file

@ -18,9 +18,12 @@ import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;
import net.minecraft.src.StringTranslate;
/**
* The main class for non-obfuscated hook handling code
*
@ -271,4 +274,37 @@ public class FMLCommonHandler
{
return uniqueEntityListId++;
}
private Map<String,Properties> modLanguageData=new HashMap<String,Properties>();
/**
* @param key
* @param lang
* @param value
*/
public void addStringLocalization(String key, String lang, String value)
{
Properties langPack=modLanguageData.get(lang);
if (langPack==null) {
langPack=new Properties();
modLanguageData.put(lang, langPack);
}
langPack.put(key,value);
if (StringTranslate.func_20162_a().func_44024_c().equals(lang)) {
handleLanguageLoad(langPack, lang);
}
}
/**
* @param languagePack
* @param lang
*/
public void handleLanguageLoad(Properties languagePack, String lang)
{
Properties langPack=modLanguageData.get(lang);
if (langPack==null) {
return;
}
languagePack.putAll(langPack);
}
}

View file

@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="src" path="/FML-Server"/>
<classpathentry kind="lib" path="/home/cpw/projects/mcworkspace/fmltestbed/FML/target/fml-server-1.0.0.1.zip"/>
<classpathentry combineaccessrules="false" kind="src" path="/FML-Client"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -1,3 +1,4 @@
package net.minecraft.src;
public class mod_testMod extends BaseMod {

View file

@ -0,0 +1,20 @@
--- ../src-base/minecraft/net/minecraft/src/StringTranslate.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft/net/minecraft/src/StringTranslate.java 0000-00-00 00:00:00.000000000 -0000
@@ -7,6 +7,9 @@
import java.util.Properties;
import java.util.TreeMap;
+import cpw.mods.fml.client.FMLClientHandler;
+import cpw.mods.fml.common.FMLCommonHandler;
+
public class StringTranslate
{
private static StringTranslate field_20165_a = new StringTranslate();
@@ -76,6 +79,7 @@
}
}
}
+ FMLCommonHandler.instance().handleLanguageLoad(p_44025_1_,p_44025_2_);
}
public void func_44023_a(String p_44023_1_)