From ab90aa4d999f79b66b6b4e77c06e1f21878caaa1 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 20 Aug 2012 21:44:47 -0400 Subject: [PATCH] Fix up MLProp handling for null info --- .../common/modloader/ModLoaderGuiHelper.java | 5 +--- .../fml/common/modloader/ModLoaderHelper.java | 1 - .../modloader/ModLoaderModContainer.java | 30 ++++++++++--------- .../src/net/minecraft/src/mod_testMod.java | 3 ++ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderGuiHelper.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderGuiHelper.java index 7e94c0c8d..97eba7800 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderGuiHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderGuiHelper.java @@ -21,16 +21,13 @@ public class ModLoaderGuiHelper implements IGuiHandler @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - System.out.printf("returning container %s, %d for server side\n", container, id); return container; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - Object o = ModLoaderHelper.getClientSideGui(mod, player, ID, x, y, z); - System.out.printf("fetching gui %s %d for client side\n", o, id); - return o; + return ModLoaderHelper.getClientSideGui(mod, player, ID, x, y, z); } public void injectContainer(Container container) diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index 7f8ca0db7..e20867833 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -134,7 +134,6 @@ public class ModLoaderHelper { ModLoaderGuiHelper helper = guiHelpers.get(id); helper.injectContainer(container); - System.out.printf("Opening GUI %d %s at %d %d %d\n", id, container, x,y,z); player.openGui(helper.getMod(), id, player.field_70170_p, x, y, z); } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index d91d0945b..ca86c6e84 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -105,7 +105,7 @@ public class ModLoaderModContainer implements ModContainer private void configureMod(Class modClazz, ASMDataTable asmData) { File configDir = Loader.instance().getConfigDir(); - File modConfig = new File(configDir, String.format("%s.cfg", modClazzName)); + File modConfig = new File(configDir, String.format("%s.cfg", getModId())); Properties props = new Properties(); boolean existingConfigFound = false; @@ -115,7 +115,7 @@ public class ModLoaderModContainer implements ModContainer { try { - FMLLog.fine("Reading existing configuration file for %s : %s", modClazzName, modConfig.getName()); + FMLLog.fine("Reading existing configuration file for %s : %s", getModId(), modConfig.getName()); FileReader configReader = new FileReader(modConfig); props.load(configReader); configReader.close(); @@ -142,7 +142,7 @@ public class ModLoaderModContainer implements ModContainer try { mlPropFields.add(new ModProperty(modClazz.getDeclaredField(dat.getObjectName()), dat.getAnnotationInfo())); - FMLLog.finest("Found an MLProp field %s in %s", dat.getObjectName(), modClazzName); + FMLLog.finest("Found an MLProp field %s in %s", dat.getObjectName(), getModId()); } catch (Exception e) { @@ -157,8 +157,9 @@ public class ModLoaderModContainer implements ModContainer FMLLog.info("The MLProp field %s in mod %s appears not to be static", property.field().getName(), getModId()); continue; } + FMLLog.finest("Considering MLProp field %s", property.field().getName()); Field f = property.field(); - String propertyName = property.name().length() > 0 ? property.name() : f.getName(); + String propertyName = !Strings.nullToEmpty(property.name()).isEmpty() ? property.name() : f.getName(); String propertyValue = null; Object defaultValue = null; @@ -166,7 +167,7 @@ public class ModLoaderModContainer implements ModContainer { defaultValue = f.get(null); propertyValue = props.getProperty(propertyName, extractValue(defaultValue)); - Object currentValue = parseValue(propertyValue, property, f.getType(), propertyName, modClazzName); + Object currentValue = parseValue(propertyValue, property, f.getType(), propertyName); FMLLog.finest("Configuration for %s.%s found values default: %s, configured: %s, interpreted: %s", modClazzName, propertyName, defaultValue, propertyValue, currentValue); if (currentValue != null && !currentValue.equals(defaultValue)) @@ -196,7 +197,7 @@ public class ModLoaderModContainer implements ModContainer comments.append(")"); - if (property.info().length() > 0) + if (!Strings.nullToEmpty(property.info()).isEmpty()) { comments.append(" -- ").append(property.info()); } @@ -214,22 +215,22 @@ public class ModLoaderModContainer implements ModContainer { if (!mlPropFound && !existingConfigFound) { - FMLLog.fine("No MLProp configuration for %s found or required. No file written", modClazzName); + FMLLog.fine("No MLProp configuration for %s found or required. No file written", getModId()); return; } if (!mlPropFound && existingConfigFound) { File mlPropBackup = new File(modConfig.getParent(),modConfig.getName()+".bak"); - FMLLog.fine("MLProp configuration file for %s found but not required. Attempting to rename file to %s", modClazzName, mlPropBackup.getName()); + FMLLog.fine("MLProp configuration file for %s found but not required. Attempting to rename file to %s", getModId(), mlPropBackup.getName()); boolean renamed = modConfig.renameTo(mlPropBackup); if (renamed) { - FMLLog.fine("Unused MLProp configuration file for %s renamed successfully to %s", modClazzName, mlPropBackup.getName()); + FMLLog.fine("Unused MLProp configuration file for %s renamed successfully to %s", getModId(), mlPropBackup.getName()); } else { - FMLLog.fine("Unused MLProp configuration file for %s renamed UNSUCCESSFULLY to %s", modClazzName, mlPropBackup.getName()); + FMLLog.fine("Unused MLProp configuration file for %s renamed UNSUCCESSFULLY to %s", getModId(), mlPropBackup.getName()); } return; @@ -239,7 +240,7 @@ public class ModLoaderModContainer implements ModContainer FileWriter configWriter = new FileWriter(modConfig); props.store(configWriter, comments.toString()); configWriter.close(); - FMLLog.fine("Configuration for %s written to %s", modClazzName, modConfig.getName()); + FMLLog.fine("Configuration for %s written to %s", getModId(), modConfig.getName()); } catch (IOException e) { @@ -249,7 +250,7 @@ public class ModLoaderModContainer implements ModContainer } } - private Object parseValue(String val, ModProperty property, Class type, String propertyName, String modConfigName) + private Object parseValue(String val, ModProperty property, Class type, String propertyName) { if (type.isAssignableFrom(String.class)) { @@ -292,9 +293,10 @@ public class ModLoaderModContainer implements ModContainer throw new IllegalArgumentException(String.format("MLProp declared on %s of type %s, an unsupported type",propertyName, type.getName())); } - if (n.doubleValue() < property.min() || n.doubleValue() > property.max()) + double dVal = n.doubleValue(); + if ((property.min()!=Double.MIN_VALUE && dVal < property.min()) || (property.max()!=Double.MAX_VALUE && dVal > property.max())) { - FMLLog.warning("Configuration for %s.%s found value %s outside acceptable range %s,%s", modConfigName,propertyName, n, property.min(), property.max()); + FMLLog.warning("Configuration for %s.%s found value %s outside acceptable range %s,%s", modClazzName,propertyName, n, property.min(), property.max()); return null; } else diff --git a/fml/eclipse/simpletestmod/src/net/minecraft/src/mod_testMod.java b/fml/eclipse/simpletestmod/src/net/minecraft/src/mod_testMod.java index ec57b79d6..1b5b6162c 100644 --- a/fml/eclipse/simpletestmod/src/net/minecraft/src/mod_testMod.java +++ b/fml/eclipse/simpletestmod/src/net/minecraft/src/mod_testMod.java @@ -19,6 +19,9 @@ import net.minecraft.client.Minecraft; @NetworkMod(channels={"mod_TestMod"},clientSideRequired=true,packetHandler=mod_testMod.PacketHandler.class) public class mod_testMod extends BaseMod { + + @MLProp + public static int test = 0; public static class PacketHandler implements IPacketHandler { @Override