mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 02:55:17 +00:00
Fix up MLProp handling for null info
This commit is contained in:
1 parent
3a8b047e3c
commit
38f4a22bc4
4 files changed
+20
-19
No files matched your search
@@ -21,16 +21,13 @@ public class ModLoaderGuiHelper implements IGuiHandler
|
|||||||
@Override
|
@Override
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
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;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
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);
|
return ModLoaderHelper.getClientSideGui(mod, player, ID, x, y, z);
|
||||||
System.out.printf("fetching gui %s %d for client side\n", o, id);
|
|
||||||
return o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectContainer(Container container)
|
public void injectContainer(Container container)
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ public class ModLoaderHelper
|
|||||||
{
|
{
|
||||||
ModLoaderGuiHelper helper = guiHelpers.get(id);
|
ModLoaderGuiHelper helper = guiHelpers.get(id);
|
||||||
helper.injectContainer(container);
|
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);
|
player.openGui(helper.getMod(), id, player.field_70170_p, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
private void configureMod(Class<? extends BaseModProxy> modClazz, ASMDataTable asmData)
|
private void configureMod(Class<? extends BaseModProxy> modClazz, ASMDataTable asmData)
|
||||||
{
|
{
|
||||||
File configDir = Loader.instance().getConfigDir();
|
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();
|
Properties props = new Properties();
|
||||||
|
|
||||||
boolean existingConfigFound = false;
|
boolean existingConfigFound = false;
|
||||||
@@ -115,7 +115,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
{
|
{
|
||||||
try
|
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);
|
FileReader configReader = new FileReader(modConfig);
|
||||||
props.load(configReader);
|
props.load(configReader);
|
||||||
configReader.close();
|
configReader.close();
|
||||||
@@ -142,7 +142,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
mlPropFields.add(new ModProperty(modClazz.getDeclaredField(dat.getObjectName()), dat.getAnnotationInfo()));
|
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)
|
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());
|
FMLLog.info("The MLProp field %s in mod %s appears not to be static", property.field().getName(), getModId());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
FMLLog.finest("Considering MLProp field %s", property.field().getName());
|
||||||
Field f = property.field();
|
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;
|
String propertyValue = null;
|
||||||
Object defaultValue = null;
|
Object defaultValue = null;
|
||||||
|
|
||||||
@@ -166,7 +167,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
{
|
{
|
||||||
defaultValue = f.get(null);
|
defaultValue = f.get(null);
|
||||||
propertyValue = props.getProperty(propertyName, extractValue(defaultValue));
|
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);
|
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))
|
if (currentValue != null && !currentValue.equals(defaultValue))
|
||||||
@@ -196,7 +197,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
|
|
||||||
comments.append(")");
|
comments.append(")");
|
||||||
|
|
||||||
if (property.info().length() > 0)
|
if (!Strings.nullToEmpty(property.info()).isEmpty())
|
||||||
{
|
{
|
||||||
comments.append(" -- ").append(property.info());
|
comments.append(" -- ").append(property.info());
|
||||||
}
|
}
|
||||||
@@ -214,22 +215,22 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
{
|
{
|
||||||
if (!mlPropFound && !existingConfigFound)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mlPropFound && existingConfigFound)
|
if (!mlPropFound && existingConfigFound)
|
||||||
{
|
{
|
||||||
File mlPropBackup = new File(modConfig.getParent(),modConfig.getName()+".bak");
|
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);
|
boolean renamed = modConfig.renameTo(mlPropBackup);
|
||||||
if (renamed)
|
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
|
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;
|
return;
|
||||||
@@ -239,7 +240,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
FileWriter configWriter = new FileWriter(modConfig);
|
FileWriter configWriter = new FileWriter(modConfig);
|
||||||
props.store(configWriter, comments.toString());
|
props.store(configWriter, comments.toString());
|
||||||
configWriter.close();
|
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)
|
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))
|
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()));
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ import net.minecraft.client.Minecraft;
|
|||||||
|
|
||||||
@NetworkMod(channels={"mod_TestMod"},clientSideRequired=true,packetHandler=mod_testMod.PacketHandler.class)
|
@NetworkMod(channels={"mod_TestMod"},clientSideRequired=true,packetHandler=mod_testMod.PacketHandler.class)
|
||||||
public class mod_testMod extends BaseMod {
|
public class mod_testMod extends BaseMod {
|
||||||
|
|
||||||
|
@MLProp
|
||||||
|
public static int test = 0;
|
||||||
public static class PacketHandler implements IPacketHandler
|
public static class PacketHandler implements IPacketHandler
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user