From dfd15acb6db1f20b87f53010bb357bc918f8c10c Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Thu, 31 May 2012 22:09:45 -0400 Subject: [PATCH] Reorganize for bukkit integration --- .../cpw/mods/fml/client/FMLClientHandler.java | 21 ++++- fml/client/net/minecraft/src/BaseMod.java | 2 +- .../net/minecraft/src/ClientRegistry.java | 5 +- .../minecraft/src/FMLRenderAccessLibrary.java | 7 ++ .../net/minecraft/src/MLProp.java | 0 fml/client/net/minecraft/src/ModLoader.java | 37 ++++---- .../cpw/mods/fml/common/FMLCommonHandler.java | 10 ++- .../cpw/mods/fml/common/FMLModContainer.java | 3 - .../cpw/mods/fml/common/IFMLSidedHandler.java | 4 + .../cpw/mods/fml/common/IWorldGenerator.java | 8 +- fml/common/cpw/mods/fml/common/Loader.java | 2 +- .../cpw/mods/fml/common/ModContainer.java | 3 - .../mods/fml/common/modloader/BaseMod.java | 89 +++++++++++++++++++ .../fml/common/modloader/ModLoaderHelper.java | 1 - .../modloader/ModLoaderModContainer.java | 13 ++- .../fml/common/modloader/ModProperty.java | 69 ++++++++++++++ .../fml/common/registry/FMLRegistry.java} | 13 ++- .../common/registry}/IMinecraftRegistry.java | 11 ++- .../cpw/mods/fml/server/FMLServerHandler.java | 21 ++++- fml/server/net/minecraft/src/BaseMod.java | 2 +- fml/server/net/minecraft/src/MLProp.java | 48 ++++++++++ fml/server/net/minecraft/src/ModLoader.java | 39 ++++---- .../net/minecraft/src/ServerRegistry.java | 2 + 23 files changed, 341 insertions(+), 69 deletions(-) rename fml/{common => client}/net/minecraft/src/MLProp.java (100%) create mode 100644 fml/common/cpw/mods/fml/common/modloader/BaseMod.java create mode 100644 fml/common/cpw/mods/fml/common/modloader/ModProperty.java rename fml/common/{net/minecraft/src/CommonRegistry.java => cpw/mods/fml/common/registry/FMLRegistry.java} (91%) rename fml/common/{net/minecraft/src => cpw/mods/fml/common/registry}/IMinecraftRegistry.java (81%) create mode 100644 fml/server/net/minecraft/src/MLProp.java diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index 470621af76..30db6722dd 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -44,7 +45,6 @@ import net.minecraft.src.BaseMod; import net.minecraft.src.BiomeGenBase; import net.minecraft.src.Block; import net.minecraft.src.ClientRegistry; -import net.minecraft.src.CommonRegistry; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityPlayer; import net.minecraft.src.GameSettings; @@ -55,6 +55,7 @@ import net.minecraft.src.IInventory; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.KeyBinding; +import net.minecraft.src.MLProp; import net.minecraft.src.ModTextureStatic; import net.minecraft.src.NetClientHandler; import net.minecraft.src.NetworkManager; @@ -85,6 +86,8 @@ import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.modloader.ModLoaderHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; +import cpw.mods.fml.common.modloader.ModProperty; +import cpw.mods.fml.common.registry.FMLRegistry; /** @@ -179,7 +182,7 @@ public class FMLClientHandler implements IFMLSidedHandler client = minecraft; ReflectionHelper.detectObfuscation(World.class); FMLCommonHandler.instance().registerSidedDelegate(this); - CommonRegistry.registerRegistry(new ClientRegistry()); + FMLRegistry.registerRegistry(new ClientRegistry()); Loader.instance().loadMods(); } @@ -1055,4 +1058,18 @@ public class FMLClientHandler implements IFMLSidedHandler ((ITextureFX)effect).onTextureDimensionsUpdate(dim.width, dim.height); } } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.IFMLSidedHandler#getModLoaderPropertyFor(java.lang.reflect.Field) + */ + @Override + public ModProperty getModLoaderPropertyFor(Field f) + { + if (f.isAnnotationPresent(MLProp.class)) + { + MLProp prop = f.getAnnotation(MLProp.class); + return new ModProperty(prop.info(), prop.min(), prop.max(), prop.name()); + } + return null; + } } diff --git a/fml/client/net/minecraft/src/BaseMod.java b/fml/client/net/minecraft/src/BaseMod.java index 179f2d49e4..5590dadb9c 100644 --- a/fml/client/net/minecraft/src/BaseMod.java +++ b/fml/client/net/minecraft/src/BaseMod.java @@ -26,7 +26,7 @@ import cpw.mods.fml.common.IPlayerTracker; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.ModContainer.TickType; -public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker +public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod { // CALLBACK MECHANISMS diff --git a/fml/client/net/minecraft/src/ClientRegistry.java b/fml/client/net/minecraft/src/ClientRegistry.java index 60b0afac2e..71b52f7e59 100644 --- a/fml/client/net/minecraft/src/ClientRegistry.java +++ b/fml/client/net/minecraft/src/ClientRegistry.java @@ -3,11 +3,14 @@ package net.minecraft.src; import java.util.Collections; import java.util.List; +import cpw.mods.fml.common.registry.FMLRegistry; +import cpw.mods.fml.common.registry.IMinecraftRegistry; + public class ClientRegistry implements IMinecraftRegistry { public static ClientRegistry instance() { - return (ClientRegistry) CommonRegistry.instance(); + return (ClientRegistry) FMLRegistry.instance(); } @Override public void addRecipe(ItemStack output, Object... params) diff --git a/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java b/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java index ae4c45018b..e1e2271ee9 100644 --- a/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java +++ b/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java @@ -16,8 +16,10 @@ package net.minecraft.src; import java.awt.Dimension; import java.util.List; +import java.util.logging.Logger; import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.FMLCommonHandler; /** * @@ -28,6 +30,11 @@ import cpw.mods.fml.client.FMLClientHandler; */ public class FMLRenderAccessLibrary { + public static Logger getLogger() + { + return FMLCommonHandler.instance().getFMLLogger(); + } + public static void setTextureDimensions(int textureId, int width, int height, List textureFXList) { FMLClientHandler.instance().setTextureDimensions(textureId, width, height, textureFXList); diff --git a/fml/common/net/minecraft/src/MLProp.java b/fml/client/net/minecraft/src/MLProp.java similarity index 100% rename from fml/common/net/minecraft/src/MLProp.java rename to fml/client/net/minecraft/src/MLProp.java diff --git a/fml/client/net/minecraft/src/ModLoader.java b/fml/client/net/minecraft/src/ModLoader.java index 1ac82fecbb..53c1eae6ea 100644 --- a/fml/client/net/minecraft/src/ModLoader.java +++ b/fml/client/net/minecraft/src/ModLoader.java @@ -30,6 +30,7 @@ import cpw.mods.fml.common.ModContainer.TickType; import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.modloader.ModLoaderHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; +import cpw.mods.fml.common.registry.FMLRegistry; public class ModLoader { @@ -176,7 +177,7 @@ public class ModLoader */ public static void addRecipe(ItemStack output, Object... params) { - CommonRegistry.addRecipe(output, params); + FMLRegistry.addRecipe(output, params); } /** @@ -187,7 +188,7 @@ public class ModLoader */ public static void addShapelessRecipe(ItemStack output, Object... params) { - CommonRegistry.addShapelessRecipe(output, params); + FMLRegistry.addShapelessRecipe(output, params); } /** @@ -198,7 +199,7 @@ public class ModLoader */ public static void addSmelting(int input, ItemStack output) { - CommonRegistry.addSmelting(input, output); + FMLRegistry.addSmelting(input, output); } /** @@ -212,7 +213,7 @@ public class ModLoader */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); } /** @@ -227,7 +228,7 @@ public class ModLoader */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); + FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); } /** @@ -241,7 +242,7 @@ public class ModLoader */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); } /** @@ -256,7 +257,7 @@ public class ModLoader */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); + FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); } /** @@ -342,7 +343,7 @@ public class ModLoader * * @return */ - public static List getLoadedMods() + public static List getLoadedMods() { return ModLoaderModContainer.findAll(); } @@ -525,7 +526,7 @@ public class ModLoader */ public static void registerBlock(Block block) { - CommonRegistry.registerBlock(block); + FMLRegistry.registerBlock(block); } /** @@ -536,7 +537,7 @@ public class ModLoader */ public static void registerBlock(Block block, Class itemclass) { - CommonRegistry.registerBlock(block, itemclass); + FMLRegistry.registerBlock(block, itemclass); } /** @@ -548,7 +549,7 @@ public class ModLoader */ public static void registerEntityID(Class entityClass, String entityName, int id) { - CommonRegistry.registerEntityID(entityClass, entityName, id); + FMLRegistry.registerEntityID(entityClass, entityName, id); } /** @@ -562,7 +563,7 @@ public class ModLoader */ public static void registerEntityID(Class entityClass, String entityName, int id, int background, int foreground) { - CommonRegistry.registerEntityID(entityClass, entityName, id, background, foreground); + FMLRegistry.registerEntityID(entityClass, entityName, id, background, foreground); } public static void registerKey(BaseMod mod, KeyBinding keyHandler, boolean allowRepeat) @@ -592,7 +593,7 @@ public class ModLoader */ public static void registerTileEntity(Class tileEntityClass, String id) { - CommonRegistry.registerTileEntity(tileEntityClass, id); + FMLRegistry.registerTileEntity(tileEntityClass, id); } public static void registerTileEntity(Class tileEntityClass, String id, TileEntitySpecialRenderer renderer) @@ -607,7 +608,7 @@ public class ModLoader */ public static void removeBiome(BiomeGenBase biome) { - CommonRegistry.removeBiome(biome); + FMLRegistry.removeBiome(biome); } /** @@ -618,7 +619,7 @@ public class ModLoader */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityClass, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.removeSpawn(entityClass, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); } /** @@ -630,7 +631,7 @@ public class ModLoader */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.removeSpawn(entityClass, spawnList, biomes); + FMLRegistry.removeSpawn(entityClass, spawnList, biomes); } /** @@ -641,7 +642,7 @@ public class ModLoader */ public static void removeSpawn(String entityName, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityName, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.removeSpawn(entityName, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); } /** @@ -653,7 +654,7 @@ public class ModLoader */ public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.removeSpawn(entityName, spawnList, biomes); + FMLRegistry.removeSpawn(entityName, spawnList, biomes); } @Deprecated diff --git a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java index 3eaf9b19bd..d258824e97 100644 --- a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -37,8 +37,6 @@ import java.util.zip.ZipInputStream; import cpw.mods.fml.common.ModContainer.SourceType; import cpw.mods.fml.common.ModContainer.TickType; -import net.minecraft.src.StringTranslate; - /** * The main class for non-obfuscated hook handling code * @@ -507,4 +505,12 @@ public class FMLCommonHandler } } + /** + * @return + */ + public IFMLSidedHandler getSidedDelegate() + { + return sidedDelegate; + } + } diff --git a/fml/common/cpw/mods/fml/common/FMLModContainer.java b/fml/common/cpw/mods/fml/common/FMLModContainer.java index cd64e979a0..cb6ae44144 100644 --- a/fml/common/cpw/mods/fml/common/FMLModContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModContainer.java @@ -17,9 +17,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import net.minecraft.src.Block; -import net.minecraft.src.IBlockAccess; - public class FMLModContainer implements ModContainer { private Mod modDescriptor; diff --git a/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java b/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java index d02a8f71df..cc010ad047 100644 --- a/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java +++ b/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java @@ -2,9 +2,12 @@ package cpw.mods.fml.common; import java.io.File; import java.io.InputStream; +import java.lang.reflect.Field; import java.util.Properties; import java.util.logging.Logger; +import cpw.mods.fml.common.modloader.ModProperty; + public interface IFMLSidedHandler { Logger getMinecraftLogger(); @@ -20,4 +23,5 @@ public interface IFMLSidedHandler ModMetadata readMetadataFrom(InputStream input, ModContainer mod) throws Exception; void profileStart(String profileLabel); void profileEnd(); + ModProperty getModLoaderPropertyFor(Field f); } diff --git a/fml/common/cpw/mods/fml/common/IWorldGenerator.java b/fml/common/cpw/mods/fml/common/IWorldGenerator.java index 0b3c427ace..d71293e0f2 100644 --- a/fml/common/cpw/mods/fml/common/IWorldGenerator.java +++ b/fml/common/cpw/mods/fml/common/IWorldGenerator.java @@ -27,12 +27,12 @@ public interface IWorldGenerator /** * Generate some world * - * @param random the chunk specific {@link Random} as built in {@link FMLClientHandler#onChunkPopulate(net.minecraft.src.IChunkProvider, int, int, net.minecraft.src.World, net.minecraft.src.IChunkProvider)}. + * @param random the chunk specific {@link Random}. * @param chunkX the block X coordinate of this chunk. * @param chunkZ the block Z coordinate of this chunk. - * @param world : additionalData[0] The minecraft {@link net.minecraft.src.World} we're generating for. - * @param generator : additionalData[1] The {@link net.minecraft.src.IChunkProvider} that is generating. - * @param chunkProvider : additionalData[2] {@link net.minecraft.src.IChunkProvider} that is requesting the world generation. + * @param world : additionalData[0] The minecraft {@link World} we're generating for. + * @param generator : additionalData[1] The {@link IChunkProvider} that is generating. + * @param chunkProvider : additionalData[2] {@link IChunkProvider} that is requesting the world generation. * */ public void generate(Random random, int chunkX, int chunkZ, Object...additionalData); diff --git a/fml/common/cpw/mods/fml/common/Loader.java b/fml/common/cpw/mods/fml/common/Loader.java index a8c3b7e1b5..2ffa3464bb 100644 --- a/fml/common/cpw/mods/fml/common/Loader.java +++ b/fml/common/cpw/mods/fml/common/Loader.java @@ -293,7 +293,7 @@ public class Loader * The found resources are first loaded into the {@link #modClassLoader} (always) then scanned for class resources matching the specification above. * * If they provide the {@link Mod} annotation, they will be loaded as "FML mods", which currently is effectively a NO-OP. - * If they are determined to be {@link net.minecraft.src.BaseMod} subclasses they are loaded as such. + * If they are determined to be {@link BaseMod} subclasses they are loaded as such. * * Finally, if they are successfully loaded as classes, they are then added to the available mod list. */ diff --git a/fml/common/cpw/mods/fml/common/ModContainer.java b/fml/common/cpw/mods/fml/common/ModContainer.java index a58bba0fdc..b461a8d7a2 100644 --- a/fml/common/cpw/mods/fml/common/ModContainer.java +++ b/fml/common/cpw/mods/fml/common/ModContainer.java @@ -20,9 +20,6 @@ import java.util.Map; import cpw.mods.fml.common.ModContainer.SourceType; -import net.minecraft.src.Block; -import net.minecraft.src.IBlockAccess; - /** * The container that wraps around mods in the system. *

The philosophy is that individual mod implementation technologies should not impact the actual loading and management diff --git a/fml/common/cpw/mods/fml/common/modloader/BaseMod.java b/fml/common/cpw/mods/fml/common/modloader/BaseMod.java new file mode 100644 index 0000000000..cfb85f26b6 --- /dev/null +++ b/fml/common/cpw/mods/fml/common/modloader/BaseMod.java @@ -0,0 +1,89 @@ +/* + * The FML Forge Mod Loader suite. + * Copyright (C) 2012 cpw + * + * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package cpw.mods.fml.common.modloader; + +import java.util.Map; + +import cpw.mods.fml.common.IConsoleHandler; +import cpw.mods.fml.common.ICraftingHandler; +import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.INetworkHandler; +import cpw.mods.fml.common.IPickupNotifier; +import cpw.mods.fml.common.IPlayerTracker; +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.ModContainer.TickType; + +/** + * + * Marker interface for BaseMod + * + * @author cpw + * + */ +public interface BaseMod extends IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker +{ + + /** + * + */ + void modsLoaded(); + + /** + * + */ + void load(); + + /** + * @param tick + * @param b + * @param minecraftInstance + * @param data + * @return + */ + boolean doTickInGame(TickType tick, boolean b, Object minecraftInstance, Object[] data); + + /** + * @return + */ + String getName(); + + /** + * @return + */ + String getPriorities(); + + /** + * @param itemId + * @param itemDamage + * @return + */ + int addFuel(int itemId, int itemDamage); + + /** + * @param renderers + */ + void onRenderHarvest(Map renderers); + + /** + * + */ + void onRegisterAnimations(); + + /** + * @return + */ + String getVersion(); + +} diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index e6c2f5048a..c9d0cb57b6 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -18,7 +18,6 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.Map; -import net.minecraft.src.BaseMod; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.ModContainer.TickType; diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index caa85f06cf..05e10d1aff 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -30,14 +30,11 @@ import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; -import net.minecraft.src.BaseMod; -import net.minecraft.src.Block; -import net.minecraft.src.IBlockAccess; -import net.minecraft.src.MLProp; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.IConsoleHandler; import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.IKeyHandler; import cpw.mods.fml.common.INetworkHandler; import cpw.mods.fml.common.IPickupNotifier; @@ -132,6 +129,7 @@ public class ModLoaderModContainer implements ModContainer */ private void configureMod() { + IFMLSidedHandler sideHandler = FMLCommonHandler.instance().getSidedDelegate(); File configDir = Loader.instance().getConfigDir(); String modConfigName = modClazz.getSimpleName(); File modConfig = new File(configDir, String.format("%s.cfg", modConfigName)); @@ -166,12 +164,11 @@ public class ModLoaderModContainer implements ModContainer continue; } - if (!f.isAnnotationPresent(MLProp.class)) + ModProperty property = sideHandler.getModLoaderPropertyFor(f); + if (property == null) { continue; } - - MLProp property = f.getAnnotation(MLProp.class); String propertyName = property.name().length() > 0 ? property.name() : f.getName(); String propertyValue = null; Object defaultValue = null; @@ -242,7 +239,7 @@ public class ModLoaderModContainer implements ModContainer } } - private Object parseValue(String val, MLProp property, Class type, String propertyName, String modConfigName) + private Object parseValue(String val, ModProperty property, Class type, String propertyName, String modConfigName) { if (type.isAssignableFrom(String.class)) { diff --git a/fml/common/cpw/mods/fml/common/modloader/ModProperty.java b/fml/common/cpw/mods/fml/common/modloader/ModProperty.java new file mode 100644 index 0000000000..cc62f0ab15 --- /dev/null +++ b/fml/common/cpw/mods/fml/common/modloader/ModProperty.java @@ -0,0 +1,69 @@ +/* + * The FML Forge Mod Loader suite. + * Copyright (C) 2012 cpw + * + * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package cpw.mods.fml.common.modloader; + +import java.io.File; + +/** + * @author cpw + * + */ +public class ModProperty +{ + private String info; + private double min; + private double max; + private String name; + + public ModProperty(String info, double min, double max, String name) + { + this.info = info; + this.min = min; + this.max = max; + this.name = name; + } + /** + * @return + */ + public String name() + { + // TODO Auto-generated method stub + return name; + } + /** + * @return + */ + public double min() + { + // TODO Auto-generated method stub + return min; + } + /** + * @return + */ + public double max() + { + // TODO Auto-generated method stub + return max; + } + /** + * @return + */ + public String info() + { + // TODO Auto-generated method stub + return info; + } +} diff --git a/fml/common/net/minecraft/src/CommonRegistry.java b/fml/common/cpw/mods/fml/common/registry/FMLRegistry.java similarity index 91% rename from fml/common/net/minecraft/src/CommonRegistry.java rename to fml/common/cpw/mods/fml/common/registry/FMLRegistry.java index 0ec074f2c7..8eb768f8d4 100644 --- a/fml/common/net/minecraft/src/CommonRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/FMLRegistry.java @@ -11,10 +11,19 @@ * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package net.minecraft.src; +package cpw.mods.fml.common.registry; + +import net.minecraft.src.BiomeGenBase; +import net.minecraft.src.Block; +import net.minecraft.src.Entity; +import net.minecraft.src.EntityLiving; +import net.minecraft.src.EnumCreatureType; +import net.minecraft.src.ItemBlock; +import net.minecraft.src.ItemStack; +import net.minecraft.src.TileEntity; -public class CommonRegistry +public class FMLRegistry { private static IMinecraftRegistry instance; diff --git a/fml/common/net/minecraft/src/IMinecraftRegistry.java b/fml/common/cpw/mods/fml/common/registry/IMinecraftRegistry.java similarity index 81% rename from fml/common/net/minecraft/src/IMinecraftRegistry.java rename to fml/common/cpw/mods/fml/common/registry/IMinecraftRegistry.java index cc17c0465e..5a12723513 100644 --- a/fml/common/net/minecraft/src/IMinecraftRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/IMinecraftRegistry.java @@ -1,4 +1,13 @@ -package net.minecraft.src; +package cpw.mods.fml.common.registry; + +import net.minecraft.src.BiomeGenBase; +import net.minecraft.src.Block; +import net.minecraft.src.Entity; +import net.minecraft.src.EntityLiving; +import net.minecraft.src.EnumCreatureType; +import net.minecraft.src.ItemBlock; +import net.minecraft.src.ItemStack; +import net.minecraft.src.TileEntity; public interface IMinecraftRegistry { diff --git a/fml/server/cpw/mods/fml/server/FMLServerHandler.java b/fml/server/cpw/mods/fml/server/FMLServerHandler.java index bb9ddd3f06..bc469ae124 100644 --- a/fml/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/fml/server/cpw/mods/fml/server/FMLServerHandler.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Properties; import java.util.Random; @@ -25,7 +26,6 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.src.BaseMod; import net.minecraft.src.BiomeGenBase; import net.minecraft.src.Block; -import net.minecraft.src.CommonRegistry; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayerMP; @@ -34,6 +34,7 @@ import net.minecraft.src.ICommandListener; import net.minecraft.src.IInventory; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; +import net.minecraft.src.MLProp; import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet250CustomPayload; @@ -50,6 +51,8 @@ import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; +import cpw.mods.fml.common.modloader.ModProperty; +import cpw.mods.fml.common.registry.FMLRegistry; /** * Handles primary communication from hooked code into the system @@ -126,7 +129,7 @@ public class FMLServerHandler implements IFMLSidedHandler server = minecraftServer; ReflectionHelper.detectObfuscation(World.class); FMLCommonHandler.instance().registerSidedDelegate(this); - CommonRegistry.registerRegistry(new ServerRegistry()); + FMLRegistry.registerRegistry(new ServerRegistry()); Loader.instance().loadMods(); } @@ -618,4 +621,18 @@ public class FMLServerHandler implements IFMLSidedHandler { Profiler.func_40517_a(); } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.IFMLSidedHandler#getModLoaderPropertyFor(java.lang.reflect.Field) + */ + @Override + public ModProperty getModLoaderPropertyFor(Field f) + { + if (f.isAnnotationPresent(MLProp.class)) + { + MLProp prop = f.getAnnotation(MLProp.class); + return new ModProperty(prop.info(), prop.min(), prop.max(), prop.name()); + } + return null; + } } diff --git a/fml/server/net/minecraft/src/BaseMod.java b/fml/server/net/minecraft/src/BaseMod.java index 497fe3bdf7..6817a034db 100644 --- a/fml/server/net/minecraft/src/BaseMod.java +++ b/fml/server/net/minecraft/src/BaseMod.java @@ -25,7 +25,7 @@ import cpw.mods.fml.common.IPlayerTracker; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.ModContainer.TickType; -public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker +public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod { // CALLBACK MECHANISMS diff --git a/fml/server/net/minecraft/src/MLProp.java b/fml/server/net/minecraft/src/MLProp.java new file mode 100644 index 0000000000..cc7f095ebf --- /dev/null +++ b/fml/server/net/minecraft/src/MLProp.java @@ -0,0 +1,48 @@ +/* + * The FML Forge Mod Loader suite. Copyright (C) 2012 cpw + * + * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.minecraft.src; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; + +/** + * @author cpw + * + */ +@Retention(value = RUNTIME) +@Target(value = FIELD) +public @interface MLProp +{ + /** + * Adds additional help to top of configuration file. + */ + String info() default ""; + + /** + * Maximum value allowed if field is a number. + */ + double max() default Double.MAX_VALUE; + + /** + * Minimum value allowed if field is a number. + */ + double min() default Double.MIN_VALUE; + + /** + * Overrides the field name for property key. + */ + String name() default ""; + +} diff --git a/fml/server/net/minecraft/src/ModLoader.java b/fml/server/net/minecraft/src/ModLoader.java index be5126230e..87d72da661 100644 --- a/fml/server/net/minecraft/src/ModLoader.java +++ b/fml/server/net/minecraft/src/ModLoader.java @@ -24,6 +24,7 @@ import cpw.mods.fml.common.ModContainer.TickType; import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.modloader.ModLoaderHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; +import cpw.mods.fml.common.registry.FMLRegistry; import cpw.mods.fml.server.FMLServerHandler; public class ModLoader @@ -164,7 +165,7 @@ public class ModLoader */ public static void addRecipe(ItemStack output, Object... params) { - CommonRegistry.addRecipe(output, params); + FMLRegistry.addRecipe(output, params); } /** @@ -175,7 +176,7 @@ public class ModLoader */ public static void addShapelessRecipe(ItemStack output, Object... params) { - CommonRegistry.addShapelessRecipe(output, params); + FMLRegistry.addShapelessRecipe(output, params); } /** @@ -186,7 +187,7 @@ public class ModLoader */ public static void addSmelting(int input, ItemStack output) { - CommonRegistry.addSmelting(input, output); + FMLRegistry.addSmelting(input, output); } /** @@ -200,7 +201,7 @@ public class ModLoader */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); } /** @@ -214,7 +215,7 @@ public class ModLoader */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); + FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); } /** @@ -228,7 +229,7 @@ public class ModLoader */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); } /** @@ -242,7 +243,7 @@ public class ModLoader */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); + FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); } /** @@ -328,7 +329,7 @@ public class ModLoader * * @return */ - public static List getLoadedMods() + public static List getLoadedMods() { return ModLoaderModContainer.findAll(); } @@ -509,7 +510,7 @@ public class ModLoader */ public static void registerBlock(Block block) { - CommonRegistry.registerBlock(block); + FMLRegistry.registerBlock(block); } /** @@ -520,7 +521,7 @@ public class ModLoader */ public static void registerBlock(Block block, Class itemclass) { - CommonRegistry.registerBlock(block, itemclass); + FMLRegistry.registerBlock(block, itemclass); } /** @@ -532,7 +533,7 @@ public class ModLoader */ public static void registerEntityID(Class entityClass, String entityName, int id) { - CommonRegistry.registerEntityID(entityClass, entityName, id); + FMLRegistry.registerEntityID(entityClass, entityName, id); } /** @@ -546,7 +547,7 @@ public class ModLoader */ public static void registerEntityID(Class entityClass, String entityName, int id, int background, int foreground) { - CommonRegistry.registerEntityID(entityClass, entityName, id, background, foreground); + FMLRegistry.registerEntityID(entityClass, entityName, id, background, foreground); } public static void registerKey(BaseMod mod, Object keyHandler, boolean allowRepeat) @@ -576,12 +577,12 @@ public class ModLoader */ public static void registerTileEntity(Class tileEntityClass, String id) { - CommonRegistry.registerTileEntity(tileEntityClass, id); + FMLRegistry.registerTileEntity(tileEntityClass, id); } public static void registerTileEntity(Class tileEntityClass, String id, Object renderer) { - CommonRegistry.instance().registerTileEntity(tileEntityClass, id); + FMLRegistry.instance().registerTileEntity(tileEntityClass, id); } /** @@ -591,7 +592,7 @@ public class ModLoader */ public static void removeBiome(BiomeGenBase biome) { - CommonRegistry.removeBiome(biome); + FMLRegistry.removeBiome(biome); } /** @@ -602,7 +603,7 @@ public class ModLoader */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityClass, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.removeSpawn(entityClass, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); } /** @@ -614,7 +615,7 @@ public class ModLoader */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.removeSpawn(entityClass, spawnList, biomes); + FMLRegistry.removeSpawn(entityClass, spawnList, biomes); } /** @@ -625,7 +626,7 @@ public class ModLoader */ public static void removeSpawn(String entityName, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityName, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); + FMLRegistry.removeSpawn(entityName, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes()); } /** @@ -637,7 +638,7 @@ public class ModLoader */ public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.removeSpawn(entityName, spawnList, biomes); + FMLRegistry.removeSpawn(entityName, spawnList, biomes); } @Deprecated diff --git a/fml/server/net/minecraft/src/ServerRegistry.java b/fml/server/net/minecraft/src/ServerRegistry.java index 8f0afc3709..4147dd3d88 100644 --- a/fml/server/net/minecraft/src/ServerRegistry.java +++ b/fml/server/net/minecraft/src/ServerRegistry.java @@ -3,6 +3,8 @@ package net.minecraft.src; import java.util.Collections; import java.util.List; +import cpw.mods.fml.common.registry.IMinecraftRegistry; + public class ServerRegistry implements IMinecraftRegistry {