From e828c1793d238f865cf592e472c015544b0c3afd Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Thu, 5 Apr 2012 10:07:52 -0400 Subject: [PATCH] Run Astyle over the FML code. Happy lex? --- fml/common/cpw/mods/fml/common/FMLHooks.java | 214 ++-- .../cpw/mods/fml/common/FMLModContainer.java | 403 ++++--- .../cpw/mods/fml/common/ICraftingHandler.java | 31 +- .../cpw/mods/fml/common/IDispenseHandler.java | 11 +- .../cpw/mods/fml/common/INetworkHandler.java | 17 +- .../cpw/mods/fml/common/IPickupNotifier.java | 11 +- .../cpw/mods/fml/common/IWorldGenerator.java | 11 +- fml/common/cpw/mods/fml/common/Loader.java | 685 ++++++----- .../cpw/mods/fml/common/LoaderException.java | 29 +- fml/common/cpw/mods/fml/common/Mod.java | 23 +- .../cpw/mods/fml/common/ModClassLoader.java | 25 +- .../cpw/mods/fml/common/ModContainer.java | 61 +- .../cpw/mods/fml/common/ReflectionHelper.java | 118 +- .../mods/fml/common/toposort/ModSorter.java | 155 +-- .../fml/common/toposort/TopologicalSort.java | 275 +++-- .../net/minecraft/src/CommonRegistry.java | 201 ++-- .../cpw/mods/fml/server/FMLHandler.java | 418 ++++--- .../fml/server/ModLoaderModContainer.java | 755 +++++++----- fml/server/net/minecraft/src/BaseMod.java | 448 +++---- fml/server/net/minecraft/src/MLProp.java | 43 +- fml/server/net/minecraft/src/ModLoader.java | 1043 +++++++++-------- 21 files changed, 2765 insertions(+), 2212 deletions(-) diff --git a/fml/common/cpw/mods/fml/common/FMLHooks.java b/fml/common/cpw/mods/fml/common/FMLHooks.java index 3eb9afba4..af149f512 100644 --- a/fml/common/cpw/mods/fml/common/FMLHooks.java +++ b/fml/common/cpw/mods/fml/common/FMLHooks.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -23,102 +23,132 @@ import net.minecraft.src.EntityPlayer; -public class FMLHooks { - private static final FMLHooks INSTANCE=new FMLHooks(); - private Map> channelList=new HashMap>(); - private Map modChannels=new HashMap(); - private Map> activeChannels=new HashMap>(); - - public void gameTickStart() { - for (ModContainer mod : Loader.getModList()) { - mod.tickStart(); - } - } - - public void gameTickEnd() { - for (ModContainer mod : Loader.getModList()) { - mod.tickEnd(); - } - } +public class FMLHooks +{ + private static final FMLHooks INSTANCE = new FMLHooks(); + private Map> channelList = new HashMap>(); + private Map modChannels = new HashMap(); + private Map> activeChannels = new HashMap>(); - /** - * @return the instance - */ - public static FMLHooks instance() { - return INSTANCE; - } + public void gameTickStart() + { + for (ModContainer mod : Loader.getModList()) + { + mod.tickStart(); + } + } - public ModContainer getModForChannel(String channel) { - return modChannels.get(channel); - } - /** - * @param modLoaderModContainer - * @return - */ - public Set getChannelListFor(ModContainer container) { - return channelList.get(container); - } - - public void registerChannel(ModContainer container, String channelName) { - if (modChannels.containsKey(channelName)) { - // NOOP + public void gameTickEnd() + { + for (ModContainer mod : Loader.getModList()) + { + mod.tickEnd(); + } } - Set list=channelList.get(container); - if (list==null) { - list=new HashSet(); - channelList.put(container, list); - } - list.add(channelName); - } - /** - * @param player - */ - public void activateChannel(Object player, String channel) { - Set active=activeChannels.get(player); - if (active==null) { - active=new HashSet(); - activeChannels.put(player, active); + /** + * @return the instance + */ + public static FMLHooks instance() + { + return INSTANCE; } - active.add(channel); - } - /** - * @param player - * @param channel - */ - public void deactivateChannel(EntityPlayer player, String channel) { - Set active=activeChannels.get(player); - if (active==null) { - active=new HashSet(); - activeChannels.put(player, active); + public ModContainer getModForChannel(String channel) + { + return modChannels.get(channel); + } + /** + * @param modLoaderModContainer + * @return + */ + public Set getChannelListFor(ModContainer container) + { + return channelList.get(container); } - active.remove(channel); - } - /** - * @return - */ - public byte[] getPacketRegistry() { - StringBuffer sb=new StringBuffer(); - for (String chan : modChannels.keySet()) { - sb.append(chan).append("\0"); - } - try { - return sb.toString().getBytes("UTF8"); - } catch (UnsupportedEncodingException e) { - Loader.log.warning("Error building registration list"); - Loader.log.throwing("FMLHooks", "getPacketRegistry", e); - return new byte[0]; - } - } + public void registerChannel(ModContainer container, String channelName) + { + if (modChannels.containsKey(channelName)) + { + // NOOP + } - /** - * @param channel - * @param player - * @return - */ - public boolean isChannelActive(String channel, Object player) { - return activeChannels.get(player).contains(channel); - } + Set list = channelList.get(container); + + if (list == null) + { + list = new HashSet(); + channelList.put(container, list); + } + + list.add(channelName); + } + + /** + * @param player + */ + public void activateChannel(Object player, String channel) + { + Set active = activeChannels.get(player); + + if (active == null) + { + active = new HashSet(); + activeChannels.put(player, active); + } + + active.add(channel); + } + + /** + * @param player + * @param channel + */ + public void deactivateChannel(EntityPlayer player, String channel) + { + Set active = activeChannels.get(player); + + if (active == null) + { + active = new HashSet(); + activeChannels.put(player, active); + } + + active.remove(channel); + } + + /** + * @return + */ + public byte[] getPacketRegistry() + { + StringBuffer sb = new StringBuffer(); + + for (String chan : modChannels.keySet()) + { + sb.append(chan).append("\0"); + } + + try + { + return sb.toString().getBytes("UTF8"); + } + catch (UnsupportedEncodingException e) + { + Loader.log.warning("Error building registration list"); + Loader.log.throwing("FMLHooks", "getPacketRegistry", e); + return new byte[0]; + } + } + + /** + * @param channel + * @param player + * @return + */ + public boolean isChannelActive(String channel, Object player) + { + return activeChannels.get(player).contains(channel); + } } diff --git a/fml/common/cpw/mods/fml/common/FMLModContainer.java b/fml/common/cpw/mods/fml/common/FMLModContainer.java index 1fde1869a..25b10cce9 100644 --- a/fml/common/cpw/mods/fml/common/FMLModContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModContainer.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -15,219 +15,250 @@ package cpw.mods.fml.common; import java.util.ArrayList; import java.util.List; -public class FMLModContainer implements ModContainer { - private Mod modDescriptor; - private Object modInstance; - private String source; +public class FMLModContainer implements ModContainer +{ + private Mod modDescriptor; + private Object modInstance; + private String source; - public FMLModContainer(String source) { - this.source=source; - } - - public FMLModContainer(Class clazz) { - if (clazz==null) { - return; + public FMLModContainer(String source) + { + this.source = source; } - modDescriptor = clazz.getAnnotation(Mod.class); - try { - modInstance = clazz.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); + public FMLModContainer(Class clazz) + { + if (clazz == null) + { + return; + } + + modDescriptor = clazz.getAnnotation(Mod.class); + + try + { + modInstance = clazz.newInstance(); + } + catch (Exception e) + { + throw new RuntimeException(e); + } } - } - @Override - public boolean wantsPreInit() { - return modDescriptor.wantsPreInit(); - } + @Override + public boolean wantsPreInit() + { + return modDescriptor.wantsPreInit(); + } - @Override - public boolean wantsPostInit() { - return modDescriptor.wantsPostInit(); - } + @Override + public boolean wantsPostInit() + { + return modDescriptor.wantsPostInit(); + } - @Override - public void preInit() { + @Override + public void preInit() + { + } - } + @Override + public void init() + { + // TODO Auto-generated method stub + } - @Override - public void init() { - // TODO Auto-generated method stub + @Override + public void postInit() + { + // TODO Auto-generated method stub + } - } + public static ModContainer buildFor(Class clazz) + { + return new FMLModContainer(clazz); + } - @Override - public void postInit() { - // TODO Auto-generated method stub + @Override + public String getName() + { + // TODO Auto-generated method stub + return null; + } - } + @Override + public void tickStart() + { + // TODO Auto-generated method stub + } - public static ModContainer buildFor(Class clazz) { - return new FMLModContainer(clazz); - } + @Override + public void tickEnd() + { + // TODO Auto-generated method stub + } - @Override - public String getName() { - // TODO Auto-generated method stub - return null; - } + @Override + public boolean matches(Object mod) + { + // TODO Auto-generated method stub + return false; + } - @Override - public void tickStart() { - // TODO Auto-generated method stub + @Override + public String getSource() + { + return source; + } - } + @Override + public Object getMod() + { + // TODO Auto-generated method stub + return null; + } - @Override - public void tickEnd() { - // TODO Auto-generated method stub + @Override + public boolean generatesWorld() + { + // TODO Auto-generated method stub + return false; + } - } + @Override + public IWorldGenerator getWorldGenerator() + { + // TODO Auto-generated method stub + return null; + } - @Override - public boolean matches(Object mod) { - // TODO Auto-generated method stub - return false; - } + @Override + public int lookupFuelValue(int itemId, int itemDamage) + { + // TODO Auto-generated method stub + return 0; + } - @Override - public String getSource() { - return source; - } + @Override + public boolean wantsPickupNotification() + { + // TODO Auto-generated method stub + return false; + } - @Override - public Object getMod() { - // TODO Auto-generated method stub - return null; - } + @Override + public IPickupNotifier getPickupNotifier() + { + // TODO Auto-generated method stub + return null; + } - @Override - public boolean generatesWorld() { - // TODO Auto-generated method stub - return false; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsToDispense() + */ + @Override + public boolean wantsToDispense() + { + // TODO Auto-generated method stub + return false; + } - @Override - public IWorldGenerator getWorldGenerator() { - // TODO Auto-generated method stub - return null; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getDispenseHandler() + */ + @Override + public IDispenseHandler getDispenseHandler() + { + // TODO Auto-generated method stub + return null; + } - @Override - public int lookupFuelValue(int itemId, int itemDamage) { - // TODO Auto-generated method stub - return 0; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification() + */ + @Override + public boolean wantsCraftingNotification() + { + // TODO Auto-generated method stub + return false; + } - @Override - public boolean wantsPickupNotification() { - // TODO Auto-generated method stub - return false; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getCraftingHandler() + */ + @Override + public ICraftingHandler getCraftingHandler() + { + // TODO Auto-generated method stub + return null; + } - @Override - public IPickupNotifier getPickupNotifier() { - // TODO Auto-generated method stub - return null; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getDependencies() + */ + @Override + public List getDependencies() + { + // TODO Auto-generated method stub + return new ArrayList(0); + } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#wantsToDispense() - */ - @Override - public boolean wantsToDispense() { - // TODO Auto-generated method stub - return false; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getPreDepends() + */ + @Override + public List getPreDepends() + { + // TODO Auto-generated method stub + return new ArrayList(0); + } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getDispenseHandler() - */ - @Override - public IDispenseHandler getDispenseHandler() { - // TODO Auto-generated method stub - return null; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getPostDepends() + */ + @Override + public List getPostDepends() + { + // TODO Auto-generated method stub + return new ArrayList(0); + } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification() - */ - @Override - public boolean wantsCraftingNotification() { - // TODO Auto-generated method stub - return false; - } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return getSource(); + } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getCraftingHandler() - */ - @Override - public ICraftingHandler getCraftingHandler() { - // TODO Auto-generated method stub - return null; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsNetworkPackets() + */ + @Override + public boolean wantsNetworkPackets() + { + // TODO Auto-generated method stub + return false; + } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getDependencies() - */ - @Override - public List getDependencies() { - // TODO Auto-generated method stub - return new ArrayList(0); - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getNetworkHandler() + */ + @Override + public INetworkHandler getNetworkHandler() + { + // TODO Auto-generated method stub + return null; + } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getPreDepends() - */ - @Override - public List getPreDepends() { - // TODO Auto-generated method stub - return new ArrayList(0); - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getPostDepends() - */ - @Override - public List getPostDepends() { - // TODO Auto-generated method stub - return new ArrayList(0); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return getSource(); - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#wantsNetworkPackets() - */ - @Override - public boolean wantsNetworkPackets() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getNetworkHandler() - */ - @Override - public INetworkHandler getNetworkHandler() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#ownsNetworkChannel(java.lang.String) - */ - @Override - public boolean ownsNetworkChannel(String channel) { - // TODO Auto-generated method stub - return false; - } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#ownsNetworkChannel(java.lang.String) + */ + @Override + public boolean ownsNetworkChannel(String channel) + { + // TODO Auto-generated method stub + return false; + } } diff --git a/fml/common/cpw/mods/fml/common/ICraftingHandler.java b/fml/common/cpw/mods/fml/common/ICraftingHandler.java index 44d0cce07..3ca514a2d 100644 --- a/fml/common/cpw/mods/fml/common/ICraftingHandler.java +++ b/fml/common/cpw/mods/fml/common/ICraftingHandler.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -17,18 +17,19 @@ package cpw.mods.fml.common; * @author cpw * */ -public interface ICraftingHandler { +public interface ICraftingHandler +{ - /** - * @param player - * @param craftedItem - * @param craftingGrid - */ - void onCrafting(Object... craftingParameters); + /** + * @param player + * @param craftedItem + * @param craftingGrid + */ + void onCrafting(Object... craftingParameters); - /** - * @param player - * @param smeltedItem - */ - void onSmelting(Object... smeltingParameters); + /** + * @param player + * @param smeltedItem + */ + void onSmelting(Object... smeltingParameters); } diff --git a/fml/common/cpw/mods/fml/common/IDispenseHandler.java b/fml/common/cpw/mods/fml/common/IDispenseHandler.java index fa6b0b542..d4ba47685 100644 --- a/fml/common/cpw/mods/fml/common/IDispenseHandler.java +++ b/fml/common/cpw/mods/fml/common/IDispenseHandler.java @@ -1,19 +1,20 @@ /* * 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; -public interface IDispenseHandler { - boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data); +public interface IDispenseHandler +{ + boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data); } diff --git a/fml/common/cpw/mods/fml/common/INetworkHandler.java b/fml/common/cpw/mods/fml/common/INetworkHandler.java index 3427ba32a..865ac95e3 100644 --- a/fml/common/cpw/mods/fml/common/INetworkHandler.java +++ b/fml/common/cpw/mods/fml/common/INetworkHandler.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -15,10 +15,11 @@ package cpw.mods.fml.common; /** * @author cpw - * + * */ -public interface INetworkHandler { - boolean onChat(Object... data); - void onPacket250Packet(Object... data); - void onLogin(Object... data); +public interface INetworkHandler +{ + boolean onChat(Object... data); + void onPacket250Packet(Object... data); + void onLogin(Object... data); } diff --git a/fml/common/cpw/mods/fml/common/IPickupNotifier.java b/fml/common/cpw/mods/fml/common/IPickupNotifier.java index 91fecf0a4..d29a36325 100644 --- a/fml/common/cpw/mods/fml/common/IPickupNotifier.java +++ b/fml/common/cpw/mods/fml/common/IPickupNotifier.java @@ -1,18 +1,19 @@ /* * 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; -public interface IPickupNotifier { - void notifyPickup(Object... pickupData); +public interface IPickupNotifier +{ + void notifyPickup(Object... pickupData); } diff --git a/fml/common/cpw/mods/fml/common/IWorldGenerator.java b/fml/common/cpw/mods/fml/common/IWorldGenerator.java index 07dd028f9..5a549b035 100644 --- a/fml/common/cpw/mods/fml/common/IWorldGenerator.java +++ b/fml/common/cpw/mods/fml/common/IWorldGenerator.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -15,6 +15,7 @@ package cpw.mods.fml.common; import java.util.Random; -public interface IWorldGenerator { - public void generate(Random random, int chunkX, int chunkZ, Object...additionalData); +public interface IWorldGenerator +{ + 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 09e980a0d..f155e43fb 100644 --- a/fml/common/cpw/mods/fml/common/Loader.java +++ b/fml/common/cpw/mods/fml/common/Loader.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -34,303 +34,408 @@ import java.util.zip.ZipFile; import cpw.mods.fml.common.toposort.ModSorter; import cpw.mods.fml.server.FMLHandler; -public class Loader { - private enum State { - NOINIT, LOADING, PREINIT, INIT, POSTINIT, UP, ERRORED - }; +public class Loader +{ + private enum State + { + NOINIT, LOADING, PREINIT, INIT, POSTINIT, UP, ERRORED + }; - private static Loader instance; - public static Logger log = Logger.getLogger("ForgeModLoader"); + private static Loader instance; + public static Logger log = Logger.getLogger("ForgeModLoader"); - private static Pattern zipJar = Pattern.compile("([^\\s]+).(zip|jar)$"); - private static Pattern modClass = Pattern.compile("(.*/?)(mod\\_[^\\s]+).class$"); + private static Pattern zipJar = Pattern.compile("([^\\s]+).(zip|jar)$"); + private static Pattern modClass = Pattern.compile("(.*/?)(mod\\_[^\\s]+).class$"); - private static String major="@MAJOR@"; - private static String minor="@MINOR@"; - private static String rev ="@REV@"; - private static String build="@BUILD@"; - private static String mcversion="@MCVERSION@"; - - private State state; - private ModClassLoader modClassLoader; - private List mods; - private Map namedMods; - private File canonicalConfigDir; - private File canonicalMinecraftDir; + private static String major = "@MAJOR@"; + private static String minor = "@MINOR@"; + private static String rev = "@REV@"; + private static String build = "@BUILD@"; + private static String mcversion = "@MCVERSION@"; - public static Loader instance() { - if (instance==null) { - instance=new Loader(); - } - return instance; - } - private Loader() { - Loader.log.setParent(FMLHandler.getMinecraftLogger()); - Loader.log.setLevel(Level.ALL); - FileHandler fileHandler; - try { - fileHandler = new FileHandler("ForgeModLoader-%g.log", 0, 3); - // We're stealing minecraft's log formatter - fileHandler.setFormatter(FMLHandler.getMinecraftLogger().getHandlers()[0].getFormatter()); - fileHandler.setLevel(Level.ALL); - Loader.log.addHandler(fileHandler); - } catch (Exception e) { - // Whatever - give up - } - log.info(String.format("Forge Mod Loader version %s.%s.%s.%s for Minecraft %s loading",major,minor,rev,build,mcversion)); - } + private State state; + private ModClassLoader modClassLoader; + private List mods; + private Map namedMods; + private File canonicalConfigDir; + private File canonicalMinecraftDir; - private void sortModList() { - log.fine("Verifying mod dependencies are satisfied"); - for (ModContainer mod : mods) { - if (!namedMods.keySet().containsAll(mod.getDependencies())) { - log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(),mod.getDependencies())); - LoaderException le=new LoaderException(); - log.throwing("Loader", "sortModList", le); - throw new LoaderException(); - } - } - log.fine("All dependencies are satisfied"); - ModSorter sorter=new ModSorter(mods,namedMods); - try { - log.fine("Sorting mods into an ordered list"); - mods=sorter.sort(); - log.fine(String.format("Mod list sorted %s",mods)); - } catch (IllegalArgumentException iae) { - log.severe("A dependency cycle was detected in the input mod set so they cannot load them in order"); - log.throwing("Loader", "sortModList", iae); - throw new LoaderException(iae); - } - } - - private void preModInit() { - state = State.PREINIT; - log.fine("Beginning mod pre-initialization"); - for (ModContainer mod : mods) { - if (mod.wantsPreInit()) { - log.finer(String.format("Pre-initializing %s", mod.getSource())); - mod.preInit(); - namedMods.put(mod.getName(), mod); - } - } - log.fine("Mod pre-initialization complete"); - } - - private void modInit() { - state = State.INIT; - log.fine("Beginning mod initialization"); - for (ModContainer mod : mods) { - log.finer(String.format("Initializing %s", mod.getName())); - mod.init(); - } - log.fine("Mod initialization complete"); - } - - private void postModInit() { - state = State.POSTINIT; - log.fine("Beginning mod post-initialization"); - for (ModContainer mod : mods) { - if (mod.wantsPostInit()) { - log.finer(String.format("Post-initializing %s", mod.getName())); - mod.postInit(); - } - } - log.fine("Mod post-initialization complete"); - } - - private void load() { - File minecraftDir = new File("."); - File modsDir = new File(minecraftDir, "mods"); - File configDir=new File(minecraftDir, "config"); - String canonicalModsPath; - String canonicalConfigPath; - try { - canonicalMinecraftDir=minecraftDir.getCanonicalFile(); - canonicalModsPath = modsDir.getCanonicalPath(); - canonicalConfigPath=configDir.getCanonicalPath(); - canonicalConfigDir=configDir.getCanonicalFile(); - } catch (IOException ioe) { - log.severe(String.format("Failed to resolve mods directory mods %s", modsDir.getAbsolutePath())); - log.throwing("fml.server.Loader", "initialize", ioe); - throw new LoaderException(ioe); - } - if (!modsDir.exists()) { - log.fine(String.format("No mod directory found, creating one: %s", canonicalModsPath)); - try { - modsDir.mkdir(); - } catch (Exception e) { - log.throwing("fml.server.Loader", "initialize", e); - throw new LoaderException(e); - } - } - if (!configDir.exists()) { - log.fine(String.format("No config directory found, creating one: %s", canonicalConfigPath)); - try { - configDir.mkdir(); - } catch (Exception e) { - log.throwing("fml.server.Loader", "initialize", e); - throw new LoaderException(e); - } - } - if (!modsDir.isDirectory()) { - log.severe(String.format("Attempting to load mods from %s, which is not a directory", canonicalModsPath)); - LoaderException loaderException = new LoaderException(); - log.throwing("fml.server.Loader", "initialize", loaderException); - throw loaderException; - } - if (!configDir.isDirectory()) { - log.severe(String.format("Attempting to load configuration from %s, which is not a directory", canonicalConfigPath)); - LoaderException loaderException = new LoaderException(); - log.throwing("fml.server.Loader", "initialize", loaderException); - throw loaderException; - } - - log.fine("Attempting to load mods contained in the minecraft jar file"); - attemptFileLoad(new File(minecraftDir,"minecraft_server.jar")); - log.fine("Minecraft jar mods loaded successfully"); - - log.info(String.format("Loading mods from %s",canonicalModsPath)); - File[] modList = modsDir.listFiles(); - // Sort the files into alphabetical order first - Arrays.sort(modList); - - state = State.LOADING; - for (File modFile : modList) { - if (modFile.isDirectory()) { - log.fine(String.format("Found a directory %s, attempting to load it", modFile.getName())); - boolean modFound=attemptDirLoad(modFile); - if (modFound) { - log.fine(String.format("Directory %s loaded successfully", modFile.getName())); - } else { - log.info(String.format("Directory %s contained no mods", modFile.getName())); + public static Loader instance() + { + if (instance == null) + { + instance = new Loader(); } - } else { - Matcher matcher = zipJar.matcher(modFile.getName()); - if (matcher.matches()) { - log.fine(String.format("Found a zip or jar file %s, attempting to load it", matcher.group(0))); - boolean modFound=attemptFileLoad(modFile); - if (modFound) { - log.fine(String.format("File %s loaded successfully", matcher.group(0))); - } else { - log.info(String.format("File %s contained no mods", matcher.group(0))); - } + + return instance; + } + private Loader() + { + Loader.log.setParent(FMLHandler.getMinecraftLogger()); + Loader.log.setLevel(Level.ALL); + FileHandler fileHandler; + + try + { + fileHandler = new FileHandler("ForgeModLoader-%g.log", 0, 3); + // We're stealing minecraft's log formatter + fileHandler.setFormatter(FMLHandler.getMinecraftLogger().getHandlers()[0].getFormatter()); + fileHandler.setLevel(Level.ALL); + Loader.log.addHandler(fileHandler); } - } - } - if (state == State.ERRORED) { - log.severe("A problem has occured during mod loading, giving up now"); - throw new RuntimeException("Giving up please"); - } - log.info(String.format("Forge Mod Loader has loaded %d mods",mods.size())); - } - - private boolean attemptDirLoad(File modDir) { - extendClassLoader(modDir); - - boolean foundAModClass=false; - File[] content = modDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return modClass.matcher(name).find(); - } - }); - for (File modClassFile : content) { - String clazzName = modClass.matcher(modClassFile.getName()).group(2); - log.fine(String.format("Found a mod class %s in directory %s, attempting to load it", clazzName, modDir.getName())); - loadModClass(modDir, modClassFile.getName(), clazzName); - log.fine(String.format("Successfully loaded mod class %s", modClassFile.getName())); - foundAModClass=true; - } - - return foundAModClass; - } - - private void loadModClass(File classSource, String classFileName, String clazzName) { - try { - Class clazz = Class.forName(clazzName, false, modClassLoader); - if (clazz.isAnnotationPresent(Mod.class)) { - // an FML mod - mods.add(FMLModContainer.buildFor(clazz)); - } else if (FMLHandler.instance().isModLoaderMod(clazz)) { - log.fine(String.format("ModLoader BaseMod class %s found, loading", clazzName)); - ModContainer mc=FMLHandler.instance().loadBaseModMod(clazz,classSource.getCanonicalPath()); - mods.add(mc); - log.fine(String.format("ModLoader BaseMod class %s loaded", clazzName)); - } else { - // Unrecognized - } - } catch (Exception e) { - log.warning(String.format("Failed to load mod class %s in %s", classFileName, classSource.getAbsoluteFile())); - log.throwing("fml.server.Loader", "attemptLoad", e); - state = State.ERRORED; - } - } - - private void extendClassLoader(File file) { - if (modClassLoader == null) { - modClassLoader = new ModClassLoader(); - } - try { - modClassLoader.addFile(file); - } catch (MalformedURLException e) { - throw new LoaderException(e); - } - } - - private boolean attemptFileLoad(File modFile) { - extendClassLoader(modFile); - - boolean foundAModClass=false; - try { - ZipFile jar = new ZipFile(modFile); - for (ZipEntry ze : Collections.list(jar.entries())) { - Matcher match = modClass.matcher(ze.getName()); - if (match.matches()) { - String pkg = match.group(1).replace('/', '.'); - String clazzName = pkg + match.group(2); - log.fine(String.format("Found a mod class %s in file %s, attempting to load it", clazzName, modFile.getName())); - loadModClass(modFile, ze.getName(), clazzName); - log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName())); - foundAModClass=true; + catch (Exception e) + { + // Whatever - give up } - } - } catch (Exception e) { - log.warning(String.format("Zip file %s failed to read properly", modFile.getName())); - log.throwing("fml.server.Loader", "attemptFileLoad", e); - state = State.ERRORED; + + log.info(String.format("Forge Mod Loader version %s.%s.%s.%s for Minecraft %s loading", major, minor, rev, build, mcversion)); } - return foundAModClass; - } - public static List getModList() { - return instance().mods; - } + private void sortModList() + { + log.fine("Verifying mod dependencies are satisfied"); - public void loadMods() { - state = State.NOINIT; - mods = new ArrayList(); - namedMods = new HashMap(); - load(); - preModInit(); - sortModList(); - // Make mod list immutable - mods=Collections.unmodifiableList(mods); - } + for (ModContainer mod : mods) + { + if (!namedMods.keySet().containsAll(mod.getDependencies())) + { + log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(), mod.getDependencies())); + LoaderException le = new LoaderException(); + log.throwing("Loader", "sortModList", le); + throw new LoaderException(); + } + } - public void initializeMods() { - modInit(); - postModInit(); - state = State.UP; - log.info(String.format("Forge Mod Loader load complete, %d mods loaded",mods.size())); - } - - public static boolean isModLoaded(String modname) { - return instance().namedMods.containsKey(modname); - } - /** - * @return - */ - public File getConfigDir() { - return canonicalConfigDir; - } + log.fine("All dependencies are satisfied"); + ModSorter sorter = new ModSorter(mods, namedMods); + + try + { + log.fine("Sorting mods into an ordered list"); + mods = sorter.sort(); + log.fine(String.format("Mod list sorted %s", mods)); + } + catch (IllegalArgumentException iae) + { + log.severe("A dependency cycle was detected in the input mod set so they cannot load them in order"); + log.throwing("Loader", "sortModList", iae); + throw new LoaderException(iae); + } + } + + private void preModInit() + { + state = State.PREINIT; + log.fine("Beginning mod pre-initialization"); + + for (ModContainer mod : mods) + { + if (mod.wantsPreInit()) + { + log.finer(String.format("Pre-initializing %s", mod.getSource())); + mod.preInit(); + namedMods.put(mod.getName(), mod); + } + } + + log.fine("Mod pre-initialization complete"); + } + + private void modInit() + { + state = State.INIT; + log.fine("Beginning mod initialization"); + + for (ModContainer mod : mods) + { + log.finer(String.format("Initializing %s", mod.getName())); + mod.init(); + } + + log.fine("Mod initialization complete"); + } + + private void postModInit() + { + state = State.POSTINIT; + log.fine("Beginning mod post-initialization"); + + for (ModContainer mod : mods) + { + if (mod.wantsPostInit()) + { + log.finer(String.format("Post-initializing %s", mod.getName())); + mod.postInit(); + } + } + + log.fine("Mod post-initialization complete"); + } + + private void load() + { + File minecraftDir = new File("."); + File modsDir = new File(minecraftDir, "mods"); + File configDir = new File(minecraftDir, "config"); + String canonicalModsPath; + String canonicalConfigPath; + + try + { + canonicalMinecraftDir = minecraftDir.getCanonicalFile(); + canonicalModsPath = modsDir.getCanonicalPath(); + canonicalConfigPath = configDir.getCanonicalPath(); + canonicalConfigDir = configDir.getCanonicalFile(); + } + catch (IOException ioe) + { + log.severe(String.format("Failed to resolve mods directory mods %s", modsDir.getAbsolutePath())); + log.throwing("fml.server.Loader", "initialize", ioe); + throw new LoaderException(ioe); + } + + if (!modsDir.exists()) + { + log.fine(String.format("No mod directory found, creating one: %s", canonicalModsPath)); + + try + { + modsDir.mkdir(); + } + catch (Exception e) + { + log.throwing("fml.server.Loader", "initialize", e); + throw new LoaderException(e); + } + } + + if (!configDir.exists()) + { + log.fine(String.format("No config directory found, creating one: %s", canonicalConfigPath)); + + try + { + configDir.mkdir(); + } + catch (Exception e) + { + log.throwing("fml.server.Loader", "initialize", e); + throw new LoaderException(e); + } + } + + if (!modsDir.isDirectory()) + { + log.severe(String.format("Attempting to load mods from %s, which is not a directory", canonicalModsPath)); + LoaderException loaderException = new LoaderException(); + log.throwing("fml.server.Loader", "initialize", loaderException); + throw loaderException; + } + + if (!configDir.isDirectory()) + { + log.severe(String.format("Attempting to load configuration from %s, which is not a directory", canonicalConfigPath)); + LoaderException loaderException = new LoaderException(); + log.throwing("fml.server.Loader", "initialize", loaderException); + throw loaderException; + } + + log.fine("Attempting to load mods contained in the minecraft jar file"); + attemptFileLoad(new File(minecraftDir, "minecraft_server.jar")); + log.fine("Minecraft jar mods loaded successfully"); + log.info(String.format("Loading mods from %s", canonicalModsPath)); + File[] modList = modsDir.listFiles(); + // Sort the files into alphabetical order first + Arrays.sort(modList); + state = State.LOADING; + + for (File modFile : modList) + { + if (modFile.isDirectory()) + { + log.fine(String.format("Found a directory %s, attempting to load it", modFile.getName())); + boolean modFound = attemptDirLoad(modFile); + + if (modFound) + { + log.fine(String.format("Directory %s loaded successfully", modFile.getName())); + } + else + { + log.info(String.format("Directory %s contained no mods", modFile.getName())); + } + } + else + { + Matcher matcher = zipJar.matcher(modFile.getName()); + + if (matcher.matches()) + { + log.fine(String.format("Found a zip or jar file %s, attempting to load it", matcher.group(0))); + boolean modFound = attemptFileLoad(modFile); + + if (modFound) + { + log.fine(String.format("File %s loaded successfully", matcher.group(0))); + } + else + { + log.info(String.format("File %s contained no mods", matcher.group(0))); + } + } + } + } + + if (state == State.ERRORED) + { + log.severe("A problem has occured during mod loading, giving up now"); + throw new RuntimeException("Giving up please"); + } + + log.info(String.format("Forge Mod Loader has loaded %d mods", mods.size())); + } + + private boolean attemptDirLoad(File modDir) + { + extendClassLoader(modDir); + boolean foundAModClass = false; + File[] content = modDir.listFiles(new FilenameFilter() + { + @Override + public boolean accept(File dir, String name) + { + return modClass.matcher(name).find(); + } + }); + + for (File modClassFile : content) + { + String clazzName = modClass.matcher(modClassFile.getName()).group(2); + log.fine(String.format("Found a mod class %s in directory %s, attempting to load it", clazzName, modDir.getName())); + loadModClass(modDir, modClassFile.getName(), clazzName); + log.fine(String.format("Successfully loaded mod class %s", modClassFile.getName())); + foundAModClass = true; + } + + return foundAModClass; + } + + private void loadModClass(File classSource, String classFileName, String clazzName) + { + try + { + Class clazz = Class.forName(clazzName, false, modClassLoader); + + if (clazz.isAnnotationPresent(Mod.class)) + { + // an FML mod + mods.add(FMLModContainer.buildFor(clazz)); + } + else if (FMLHandler.instance().isModLoaderMod(clazz)) + { + log.fine(String.format("ModLoader BaseMod class %s found, loading", clazzName)); + ModContainer mc = FMLHandler.instance().loadBaseModMod(clazz, classSource.getCanonicalPath()); + mods.add(mc); + log.fine(String.format("ModLoader BaseMod class %s loaded", clazzName)); + } + else + { + // Unrecognized + } + } + catch (Exception e) + { + log.warning(String.format("Failed to load mod class %s in %s", classFileName, classSource.getAbsoluteFile())); + log.throwing("fml.server.Loader", "attemptLoad", e); + state = State.ERRORED; + } + } + + private void extendClassLoader(File file) + { + if (modClassLoader == null) + { + modClassLoader = new ModClassLoader(); + } + + try + { + modClassLoader.addFile(file); + } + catch (MalformedURLException e) + { + throw new LoaderException(e); + } + } + + private boolean attemptFileLoad(File modFile) + { + extendClassLoader(modFile); + boolean foundAModClass = false; + + try + { + ZipFile jar = new ZipFile(modFile); + + for (ZipEntry ze : Collections.list(jar.entries())) + { + Matcher match = modClass.matcher(ze.getName()); + + if (match.matches()) + { + String pkg = match.group(1).replace('/', '.'); + String clazzName = pkg + match.group(2); + log.fine(String.format("Found a mod class %s in file %s, attempting to load it", clazzName, modFile.getName())); + loadModClass(modFile, ze.getName(), clazzName); + log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName())); + foundAModClass = true; + } + } + } + catch (Exception e) + { + log.warning(String.format("Zip file %s failed to read properly", modFile.getName())); + log.throwing("fml.server.Loader", "attemptFileLoad", e); + state = State.ERRORED; + } + + return foundAModClass; + } + + public static List getModList() + { + return instance().mods; + } + + public void loadMods() + { + state = State.NOINIT; + mods = new ArrayList(); + namedMods = new HashMap(); + load(); + preModInit(); + sortModList(); + // Make mod list immutable + mods = Collections.unmodifiableList(mods); + } + + public void initializeMods() + { + modInit(); + postModInit(); + state = State.UP; + log.info(String.format("Forge Mod Loader load complete, %d mods loaded", mods.size())); + } + + public static boolean isModLoaded(String modname) + { + return instance().namedMods.containsKey(modname); + } + /** + * @return + */ + public File getConfigDir() + { + return canonicalConfigDir; + } } diff --git a/fml/common/cpw/mods/fml/common/LoaderException.java b/fml/common/cpw/mods/fml/common/LoaderException.java index 0cfc8b007..1dfc9e86f 100644 --- a/fml/common/cpw/mods/fml/common/LoaderException.java +++ b/fml/common/cpw/mods/fml/common/LoaderException.java @@ -1,28 +1,31 @@ /* * 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; -public class LoaderException extends RuntimeException { - /** - * - */ - private static final long serialVersionUID = -5675297950958861378L; +public class LoaderException extends RuntimeException +{ + /** + * + */ + private static final long serialVersionUID = -5675297950958861378L; - public LoaderException(Exception wrapped) { - super(wrapped); - } + public LoaderException(Exception wrapped) + { + super(wrapped); + } - public LoaderException() { - } + public LoaderException() + { + } } \ No newline at end of file diff --git a/fml/common/cpw/mods/fml/common/Mod.java b/fml/common/cpw/mods/fml/common/Mod.java index 47f8a53d4..f045b3017 100644 --- a/fml/common/cpw/mods/fml/common/Mod.java +++ b/fml/common/cpw/mods/fml/common/Mod.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -17,12 +17,13 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) -public @interface Mod { - String name() default ""; - String version() default ""; - boolean wantsPreInit() default false; - boolean wantsPostInit() default false; - public @interface PreInit {} - public @interface Init {} - public @interface PostInit {} +public @interface Mod +{ +String name() default ""; +String version() default ""; +boolean wantsPreInit() default false; +boolean wantsPostInit() default false; + public @interface PreInit {} + public @interface Init {} + public @interface PostInit {} } diff --git a/fml/common/cpw/mods/fml/common/ModClassLoader.java b/fml/common/cpw/mods/fml/common/ModClassLoader.java index 6b5e976e1..14dad36c7 100644 --- a/fml/common/cpw/mods/fml/common/ModClassLoader.java +++ b/fml/common/cpw/mods/fml/common/ModClassLoader.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -18,14 +18,17 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -public class ModClassLoader extends URLClassLoader { +public class ModClassLoader extends URLClassLoader +{ - public ModClassLoader() { - super(new URL[0],ModClassLoader.class.getClassLoader()); - } + public ModClassLoader() + { + super(new URL[0], ModClassLoader.class.getClassLoader()); + } - public void addFile(File modFile) throws MalformedURLException { - URL url=modFile.toURI().toURL(); - super.addURL(url); - } + public void addFile(File modFile) throws MalformedURLException + { + URL url = modFile.toURI().toURL(); + super.addURL(url); + } } diff --git a/fml/common/cpw/mods/fml/common/ModContainer.java b/fml/common/cpw/mods/fml/common/ModContainer.java index a09f15dc3..6700b8641 100644 --- a/fml/common/cpw/mods/fml/common/ModContainer.java +++ b/fml/common/cpw/mods/fml/common/ModContainer.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -17,31 +17,32 @@ import java.util.List; -public interface ModContainer { - boolean wantsPreInit(); - boolean wantsPostInit(); - void preInit(); - void init(); - void postInit(); - String getName(); - void tickStart(); - void tickEnd(); - boolean matches(Object mod); - String getSource(); - Object getMod(); - boolean generatesWorld(); - IWorldGenerator getWorldGenerator(); - int lookupFuelValue(int itemId, int itemDamage); - boolean wantsPickupNotification(); - IPickupNotifier getPickupNotifier(); - boolean wantsToDispense(); - IDispenseHandler getDispenseHandler(); - boolean wantsCraftingNotification(); - ICraftingHandler getCraftingHandler(); - List getDependencies(); - List getPreDepends(); - List getPostDepends(); - boolean wantsNetworkPackets(); - INetworkHandler getNetworkHandler(); - boolean ownsNetworkChannel(String channel); +public interface ModContainer +{ + boolean wantsPreInit(); + boolean wantsPostInit(); + void preInit(); + void init(); + void postInit(); + String getName(); + void tickStart(); + void tickEnd(); + boolean matches(Object mod); + String getSource(); + Object getMod(); + boolean generatesWorld(); + IWorldGenerator getWorldGenerator(); + int lookupFuelValue(int itemId, int itemDamage); + boolean wantsPickupNotification(); + IPickupNotifier getPickupNotifier(); + boolean wantsToDispense(); + IDispenseHandler getDispenseHandler(); + boolean wantsCraftingNotification(); + ICraftingHandler getCraftingHandler(); + List getDependencies(); + List getPreDepends(); + List getPostDepends(); + boolean wantsNetworkPackets(); + INetworkHandler getNetworkHandler(); + boolean ownsNetworkChannel(String channel); } diff --git a/fml/common/cpw/mods/fml/common/ReflectionHelper.java b/fml/common/cpw/mods/fml/common/ReflectionHelper.java index 5635706d4..7aceeae98 100644 --- a/fml/common/cpw/mods/fml/common/ReflectionHelper.java +++ b/fml/common/cpw/mods/fml/common/ReflectionHelper.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -16,56 +16,72 @@ import java.lang.reflect.Field; import cpw.mods.fml.server.FMLHandler; -public class ReflectionHelper { - @SuppressWarnings("unchecked") - public static T getPrivateValue(Class classToAccess, E instance, int fieldIndex) { - try { - Field f = classToAccess.getDeclaredFields()[fieldIndex]; - f.setAccessible(true); - return (T) f.get(instance); - } catch (Exception e) { - FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %d from %s", fieldIndex, classToAccess.getName())); - FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") - public static T getPrivateValue(Class classToAccess, E instance, String fieldName) { - try { - Field f = classToAccess.getDeclaredField(fieldName); - f.setAccessible(true); - return (T) f.get(instance); - } catch (Exception e) { - FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName())); - FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); - throw new RuntimeException(e); - } - } - - public static void setPrivateValue(Class classToAccess, T instance, int fieldIndex, E value) { - try { - Field f = classToAccess.getDeclaredFields()[fieldIndex]; - f.setAccessible(true); - f.set(instance, value); - } catch (Exception e) { - FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %d from %s", fieldIndex, classToAccess.getName())); - FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); - throw new RuntimeException(e); +public class ReflectionHelper +{ + @SuppressWarnings("unchecked") + public static T getPrivateValue(Class classToAccess, E instance, int fieldIndex) + { + try + { + Field f = classToAccess.getDeclaredFields()[fieldIndex]; + f.setAccessible(true); + return (T) f.get(instance); + } + catch (Exception e) + { + FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %d from %s", fieldIndex, classToAccess.getName())); + FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + throw new RuntimeException(e); + } } - } - - public static void setPrivateValue(Class classToAccess, T instance, String fieldName, E value) { - try { - Field f = classToAccess.getDeclaredField(fieldName); - f.setAccessible(true); - f.set(instance, value); - } catch (Exception e) { - FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %s from %s", fieldName, classToAccess.getName())); - FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); - throw new RuntimeException(e); + @SuppressWarnings("unchecked") + public static T getPrivateValue(Class classToAccess, E instance, String fieldName) + { + try + { + Field f = classToAccess.getDeclaredField(fieldName); + f.setAccessible(true); + return (T) f.get(instance); + } + catch (Exception e) + { + FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName())); + FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + throw new RuntimeException(e); + } + } + + public static void setPrivateValue(Class classToAccess, T instance, int fieldIndex, E value) + { + try + { + Field f = classToAccess.getDeclaredFields()[fieldIndex]; + f.setAccessible(true); + f.set(instance, value); + } + catch (Exception e) + { + FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %d from %s", fieldIndex, classToAccess.getName())); + FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + throw new RuntimeException(e); + } + } + + public static void setPrivateValue(Class classToAccess, T instance, String fieldName, E value) + { + try + { + Field f = classToAccess.getDeclaredField(fieldName); + f.setAccessible(true); + f.set(instance, value); + } + catch (Exception e) + { + FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %s from %s", fieldName, classToAccess.getName())); + FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + throw new RuntimeException(e); + } } - } } diff --git a/fml/common/cpw/mods/fml/common/toposort/ModSorter.java b/fml/common/cpw/mods/fml/common/toposort/ModSorter.java index 5115fb49e..b55789395 100644 --- a/fml/common/cpw/mods/fml/common/toposort/ModSorter.java +++ b/fml/common/cpw/mods/fml/common/toposort/ModSorter.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -22,72 +22,95 @@ import cpw.mods.fml.common.toposort.TopologicalSort.DirectedGraph; /** * @author cpw - * + * */ -public class ModSorter { - private DirectedGraph modGraph; +public class ModSorter +{ + private DirectedGraph modGraph; - private ModContainer beforeAll = new FMLModContainer("DummyBeforeAll"); - private ModContainer afterAll = new FMLModContainer("DummyAfterAll"); - private ModContainer before = new FMLModContainer("DummyBefore"); - private ModContainer after = new FMLModContainer("DummyAfter"); + private ModContainer beforeAll = new FMLModContainer("DummyBeforeAll"); + private ModContainer afterAll = new FMLModContainer("DummyAfterAll"); + private ModContainer before = new FMLModContainer("DummyBefore"); + private ModContainer after = new FMLModContainer("DummyAfter"); - public ModSorter(List modList, Map nameLookup) { - buildGraph(modList, nameLookup); - } - - private void buildGraph(List modList, Map nameLookup) { - modGraph = new DirectedGraph(); - modGraph.addNode(beforeAll); - modGraph.addNode(before); - modGraph.addNode(afterAll); - modGraph.addNode(after); - - modGraph.addEdge(before, after); - modGraph.addEdge(beforeAll, before); - modGraph.addEdge(after, afterAll); - for (ModContainer mod : modList) { - modGraph.addNode(mod); + public ModSorter(List modList, Map nameLookup) + { + buildGraph(modList, nameLookup); } - for (ModContainer mod : modList) { - boolean preDepAdded=false; - boolean postDepAdded=false; - for (String dep : mod.getPreDepends()) { - preDepAdded=true; - if (dep.equals("*")) { - // We are "after" everything - modGraph.addEdge(mod, afterAll); - modGraph.addEdge(after, mod); - postDepAdded=true; - } else { - modGraph.addEdge(before, mod); - modGraph.addEdge(nameLookup.get(dep), mod); - } - } - for (String dep : mod.getPostDepends()) { - postDepAdded=true; - if (dep.equals("*")) { - // We are "before" everything - modGraph.addEdge(beforeAll, mod); - modGraph.addEdge(mod, before); - preDepAdded=true; - } else { - modGraph.addEdge(mod, after); - modGraph.addEdge(mod, nameLookup.get(dep)); - } - } - if (!preDepAdded) { - modGraph.addEdge(before, mod); - } - if (!postDepAdded) { - modGraph.addEdge(mod, after); - } - } - } - public List sort() { - List sortedList=TopologicalSort.topologicalSort(modGraph); - sortedList.removeAll(Arrays.asList(new ModContainer[] {beforeAll,before,after,afterAll})); - return sortedList; - } + private void buildGraph(List modList, Map nameLookup) + { + modGraph = new DirectedGraph(); + modGraph.addNode(beforeAll); + modGraph.addNode(before); + modGraph.addNode(afterAll); + modGraph.addNode(after); + modGraph.addEdge(before, after); + modGraph.addEdge(beforeAll, before); + modGraph.addEdge(after, afterAll); + + for (ModContainer mod : modList) + { + modGraph.addNode(mod); + } + + for (ModContainer mod : modList) + { + boolean preDepAdded = false; + boolean postDepAdded = false; + + for (String dep : mod.getPreDepends()) + { + preDepAdded = true; + + if (dep.equals("*")) + { + // We are "after" everything + modGraph.addEdge(mod, afterAll); + modGraph.addEdge(after, mod); + postDepAdded = true; + } + else + { + modGraph.addEdge(before, mod); + modGraph.addEdge(nameLookup.get(dep), mod); + } + } + + for (String dep : mod.getPostDepends()) + { + postDepAdded = true; + + if (dep.equals("*")) + { + // We are "before" everything + modGraph.addEdge(beforeAll, mod); + modGraph.addEdge(mod, before); + preDepAdded = true; + } + else + { + modGraph.addEdge(mod, after); + modGraph.addEdge(mod, nameLookup.get(dep)); + } + } + + if (!preDepAdded) + { + modGraph.addEdge(before, mod); + } + + if (!postDepAdded) + { + modGraph.addEdge(mod, after); + } + } + } + + public List sort() + { + List sortedList = TopologicalSort.topologicalSort(modGraph); + sortedList.removeAll(Arrays.asList(new ModContainer[] {beforeAll, before, after, afterAll})); + return sortedList; + } } diff --git a/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java b/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java index 37b5bf2af..2eafae234 100644 --- a/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java +++ b/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -25,131 +25,162 @@ import java.util.Set; /** * Topological sort for mod loading - * + * * Based on a variety of sources, including http://keithschwarz.com/interesting/code/?dir=topological-sort * @author cpw * */ -public class TopologicalSort { - public static class DirectedGraph implements Iterable { - private final Map> graph=new HashMap>(); - - public boolean addNode(T node) { - // Ignore nodes already added - if (graph.containsKey(node)) { - return false; - } - graph.put(node, new HashSet()); - return true; +public class TopologicalSort +{ + public static class DirectedGraph implements Iterable + { + private final Map> graph = new HashMap>(); + + public boolean addNode(T node) + { + // Ignore nodes already added + if (graph.containsKey(node)) + { + return false; + } + + graph.put(node, new HashSet()); + return true; + } + + public void addEdge(T from, T to) + { + if (!(graph.containsKey(from) && graph.containsKey(to))) + { + throw new NoSuchElementException("Missing nodes from graph"); + } + + graph.get(from).add(to); + } + + public void removeEdge(T from, T to) + { + if (!(graph.containsKey(from) && graph.containsKey(to))) + { + throw new NoSuchElementException("Missing nodes from graph"); + } + + graph.get(from).remove(to); + } + + public boolean edgeExists(T from, T to) + { + if (!(graph.containsKey(from) && graph.containsKey(to))) + { + throw new NoSuchElementException("Missing nodes from graph"); + } + + return graph.get(from).contains(to); + } + + public Set edgesFrom(T from) + { + if (!graph.containsKey(from)) + { + throw new NoSuchElementException("Missing node from graph"); + } + + return Collections.unmodifiableSet(graph.get(from)); + } + @Override + public Iterator iterator() + { + return graph.keySet().iterator(); + } + + public int size() + { + return graph.size(); + } + + public boolean isEmpty() + { + return graph.isEmpty(); + } + + @Override + public String toString() + { + return graph.toString(); + } } - - public void addEdge(T from, T to) { - if (!(graph.containsKey(from) && graph.containsKey(to))) { - throw new NoSuchElementException("Missing nodes from graph"); - } - graph.get(from).add(to); + + /** + * Sort the input graph into a topologically sorted list + * + * Uses the reverse depth first search as outlined in ... + * @param graph + * @return + */ + public static List topologicalSort(DirectedGraph graph) + { + DirectedGraph rGraph = reverse(graph); + List sortedResult = new ArrayList(); + Set visitedNodes = new HashSet(); + // A list of "fully explored" nodes. Leftovers in here indicate cycles in the graph + Set expandedNodes = new HashSet(); + + for (T node : rGraph) + { + explore(node, rGraph, sortedResult, visitedNodes, expandedNodes); + } + + return sortedResult; } - - public void removeEdge(T from, T to) { - if (!(graph.containsKey(from) && graph.containsKey(to))) { - throw new NoSuchElementException("Missing nodes from graph"); - } - graph.get(from).remove(to); + + public static DirectedGraph reverse(DirectedGraph graph) + { + DirectedGraph result = new DirectedGraph(); + + for (T node : graph) + { + result.addNode(node); + } + + for (T from : graph) + { + for (T to : graph.edgesFrom(from)) + { + result.addEdge(to, from); + } + } + + return result; } - - public boolean edgeExists(T from, T to) { - if (!(graph.containsKey(from) && graph.containsKey(to))) { - throw new NoSuchElementException("Missing nodes from graph"); - } - return graph.get(from).contains(to); + + public static void explore(T node, DirectedGraph graph, List sortedResult, Set visitedNodes, Set expandedNodes) + { + // Have we been here before? + if (visitedNodes.contains(node)) + { + // And have completed this node before + if (expandedNodes.contains(node)) + { + // Then we're fine + return; + } + + System.out.printf("%s: %s\n%s\n%s\n", node, sortedResult, visitedNodes, expandedNodes); + throw new IllegalArgumentException("There was a cycle detected in the input graph, sorting is not possible"); + } + + // Visit this node + visitedNodes.add(node); + + // Recursively explore inbound edges + for (T inbound : graph.edgesFrom(node)) + { + explore(inbound, graph, sortedResult, visitedNodes, expandedNodes); + } + + // Add ourselves now + sortedResult.add(node); + // And mark ourselves as explored + expandedNodes.add(node); } - - public Set edgesFrom(T from) { - if (!graph.containsKey(from)) { - throw new NoSuchElementException("Missing node from graph"); - } - return Collections.unmodifiableSet(graph.get(from)); - } - @Override - public Iterator iterator() { - return graph.keySet().iterator(); - } - - public int size() { - return graph.size(); - } - - public boolean isEmpty() { - return graph.isEmpty(); - } - - @Override - public String toString() { - return graph.toString(); - } - } - - /** - * Sort the input graph into a topologically sorted list - * - * Uses the reverse depth first search as outlined in ... - * @param graph - * @return - */ - public static List topologicalSort(DirectedGraph graph) { - DirectedGraph rGraph=reverse(graph); - - List sortedResult=new ArrayList(); - Set visitedNodes=new HashSet(); - - // A list of "fully explored" nodes. Leftovers in here indicate cycles in the graph - Set expandedNodes=new HashSet(); - - for (T node : rGraph) { - explore(node, rGraph, sortedResult, visitedNodes, expandedNodes); - } - - return sortedResult; - } - - public static DirectedGraph reverse(DirectedGraph graph) { - DirectedGraph result=new DirectedGraph(); - for (T node : graph) { - result.addNode(node); - } - for (T from : graph) { - for (T to : graph.edgesFrom(from)) { - result.addEdge(to, from); - } - } - - return result; - } - - public static void explore(T node, DirectedGraph graph, List sortedResult, Set visitedNodes, Set expandedNodes) { - // Have we been here before? - if (visitedNodes.contains(node)) { - // And have completed this node before - if (expandedNodes.contains(node)) { - // Then we're fine - return; - } - System.out.printf("%s: %s\n%s\n%s\n",node,sortedResult,visitedNodes,expandedNodes); - throw new IllegalArgumentException("There was a cycle detected in the input graph, sorting is not possible"); - } - - // Visit this node - visitedNodes.add(node); - - // Recursively explore inbound edges - for (T inbound : graph.edgesFrom(node)) { - explore(inbound, graph, sortedResult, visitedNodes, expandedNodes); - } - - // Add ourselves now - sortedResult.add(node); - - // And mark ourselves as explored - expandedNodes.add(node); - } } diff --git a/fml/common/net/minecraft/src/CommonRegistry.java b/fml/common/net/minecraft/src/CommonRegistry.java index 77d78422b..652a85583 100644 --- a/fml/common/net/minecraft/src/CommonRegistry.java +++ b/fml/common/net/minecraft/src/CommonRegistry.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -16,97 +16,128 @@ package net.minecraft.src; import java.util.Collections; import java.util.List; -public class CommonRegistry { - public static void addRecipe(ItemStack output, Object... params) { - CraftingManager.func_20151_a().func_20153_a(output, params); - } - - public static void addShapelessRecipe(ItemStack output, Object... params) { - CraftingManager.func_20151_a().func_21146_b(output, params); - } - - public static void addSmelting(int input, ItemStack output) { - FurnaceRecipes.func_21162_a().func_21160_a(input, output); - } - - public static void registerBlock(Block block) { - registerBlock(block,ItemBlock.class); - } - - public static void registerBlock(Block block, Class itemclass) { - try { - assert block!=null : "registerBlock: block cannot be null"; - assert itemclass!=null : "registerBlock: itemclass cannot be null"; - int blockItemId=block.field_573_bc-256; - itemclass.getConstructor(int.class).newInstance(blockItemId); - } catch (Exception e) { - //HMMM +public class CommonRegistry +{ + public static void addRecipe(ItemStack output, Object... params) + { + CraftingManager.func_20151_a().func_20153_a(output, params); } - } - public static void registerEntityID(Class entityClass, String entityName, int id) { - EntityList.addNewEntityListMapping(entityClass, entityName, id); - } + public static void addShapelessRecipe(ItemStack output, Object... params) + { + CraftingManager.func_20151_a().func_21146_b(output, params); + } - public static void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) { - EntityList.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); - } + public static void addSmelting(int input, ItemStack output) + { + FurnaceRecipes.func_21162_a().func_21160_a(input, output); + } - public static void registerTileEntity(Class tileEntityClass, String id) { - TileEntity.addNewTileEntityMapping(tileEntityClass, id); - } + public static void registerBlock(Block block) + { + registerBlock(block, ItemBlock.class); + } - public static void addBiome(BiomeGenBase biome) { - //NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already. - } - - public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { - for (BiomeGenBase biome : biomes) { - @SuppressWarnings("unchecked") - List spawns=biome.func_25055_a(typeOfCreature); - for (SpawnListEntry entry : spawns) { - //Adjusting an existing spawn entry - if (entry.field_25145_a==entityClass) { - entry.field_35483_d=weightedProb; - entry.field_35484_b=min; - entry.field_35485_c=max; - break; + public static void registerBlock(Block block, Class itemclass) + { + try + { + assert block != null : "registerBlock: block cannot be null"; + assert itemclass != null : "registerBlock: itemclass cannot be null"; + int blockItemId = block.field_573_bc - 256; + itemclass.getConstructor(int.class).newInstance(blockItemId); } - } - spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max)); - } - } - - @SuppressWarnings("unchecked") - public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - Class entityClazz=EntityList.getEntityToClassMapping().get(entityName); - if (EntityLiving.class.isAssignableFrom(entityClazz)) { - addSpawn((Class) entityClazz,weightedProb,min,max,spawnList,biomes); - } - } - - public static void removeBiome(BiomeGenBase biome) { - // NOOP because broken - } - - public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { - for (BiomeGenBase biome : biomes) { - @SuppressWarnings("unchecked") - List spawns=biome.func_25055_a(typeOfCreature); - for (SpawnListEntry entry : Collections.unmodifiableList(spawns)) { - if (entry.field_25145_a==entityClass) { - spawns.remove(entry); + catch (Exception e) + { + //HMMM } - } } - } - @SuppressWarnings("unchecked") - public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { - Class entityClazz=EntityList.getEntityToClassMapping().get(entityName); - if (EntityLiving.class.isAssignableFrom(entityClazz)) { - removeSpawn((Class) entityClazz,spawnList,biomes); + public static void registerEntityID(Class entityClass, String entityName, int id) + { + EntityList.addNewEntityListMapping(entityClass, entityName, id); + } + + public static void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) + { + EntityList.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); + } + + public static void registerTileEntity(Class tileEntityClass, String id) + { + TileEntity.addNewTileEntityMapping(tileEntityClass, id); + } + + public static void addBiome(BiomeGenBase biome) + { + //NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already. + } + + public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + { + for (BiomeGenBase biome : biomes) + { + @SuppressWarnings("unchecked") + List spawns = biome.func_25055_a(typeOfCreature); + + for (SpawnListEntry entry : spawns) + { + //Adjusting an existing spawn entry + if (entry.field_25145_a == entityClass) + { + entry.field_35483_d = weightedProb; + entry.field_35484_b = min; + entry.field_35485_c = max; + break; + } + } + + spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max)); + } + } + + @SuppressWarnings("unchecked") + public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + Class entityClazz = EntityList.getEntityToClassMapping().get(entityName); + + if (EntityLiving.class.isAssignableFrom(entityClazz)) + { + addSpawn((Class ) entityClazz, weightedProb, min, max, spawnList, biomes); + } + } + + public static void removeBiome(BiomeGenBase biome) + { + // NOOP because broken + } + + public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + { + for (BiomeGenBase biome : biomes) + { + @SuppressWarnings("unchecked") + List spawns = biome.func_25055_a(typeOfCreature); + + for (SpawnListEntry entry : Collections.unmodifiableList(spawns)) + { + if (entry.field_25145_a == entityClass) + { + spawns.remove(entry); + } + } + } + } + + @SuppressWarnings("unchecked") + public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + Class entityClazz = EntityList.getEntityToClassMapping().get(entityName); + + if (EntityLiving.class.isAssignableFrom(entityClazz)) + { + removeSpawn((Class ) entityClazz, spawnList, biomes); + } } - } } diff --git a/fml/server/cpw/mods/fml/server/FMLHandler.java b/fml/server/cpw/mods/fml/server/FMLHandler.java index cfe84cfd8..f7013f1ac 100644 --- a/fml/server/cpw/mods/fml/server/FMLHandler.java +++ b/fml/server/cpw/mods/fml/server/FMLHandler.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -34,198 +34,260 @@ import cpw.mods.fml.common.FMLHooks; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; -public class FMLHandler { - private static final FMLHandler INSTANCE=new FMLHandler(); - - private MinecraftServer server; +public class FMLHandler +{ + private static final FMLHandler INSTANCE = new FMLHandler(); - private BiomeGenBase[] defaultOverworldBiomes; + private MinecraftServer server; - public void onPreLoad(MinecraftServer minecraftServer) { - server = minecraftServer; - Loader.instance().loadMods(); - } + private BiomeGenBase[] defaultOverworldBiomes; - public void onLoadComplete() { - Loader.instance().initializeMods(); - } - - public void onPreTick() { - FMLHooks.instance().gameTickStart(); - } - - public void onPostTick() { - FMLHooks.instance().gameTickEnd(); - } - - public MinecraftServer getServer() { - return server; - } - - public static Logger getMinecraftLogger() { - return MinecraftServer.field_6038_a; - } - - public void onChunkPopulate(IChunkProvider chunkProvider, int chunkX, int chunkZ, World world, IChunkProvider generator) { - Random fmlRandom = new Random(world.func_22079_j()); - long xSeed = fmlRandom.nextLong() >> 2 + 1L; - long zSeed = fmlRandom.nextLong() >> 2 + 1L; - - fmlRandom.setSeed((xSeed * chunkX + zSeed * chunkZ) ^ world.func_22079_j()); - - for (ModContainer mod : Loader.getModList()) { - if (mod.generatesWorld()) { - mod.getWorldGenerator().generate(fmlRandom, chunkX, chunkZ, world, generator, chunkProvider); - } + public void onPreLoad(MinecraftServer minecraftServer) + { + server = minecraftServer; + Loader.instance().loadMods(); } - } - public int fuelLookup(int itemId, int itemDamage) { - int fv = 0; - for (ModContainer mod : Loader.getModList()) { - fv = Math.max(fv, mod.lookupFuelValue(itemId, itemDamage)); + public void onLoadComplete() + { + Loader.instance().initializeMods(); } - return fv; - } - public boolean isModLoaderMod(Class clazz) { - return BaseMod.class.isAssignableFrom(clazz); - } - - public ModContainer loadBaseModMod(Class clazz, String canonicalPath) { - @SuppressWarnings("unchecked") - Class bmClazz = (Class) clazz; - return new ModLoaderModContainer(bmClazz, canonicalPath); - } - - public void notifyItemPickup(EntityItem entityItem, EntityPlayer entityPlayer) { - for (ModContainer mod : Loader.getModList()) { - if (mod.wantsPickupNotification()) { - mod.getPickupNotifier().notifyPickup(entityItem, entityPlayer); - } + public void onPreTick() + { + FMLHooks.instance().gameTickStart(); } - } - public static Logger getFMLLogger() { - return Loader.log; - } - - public void raiseException(Throwable exception, String message, boolean stopGame) { - getFMLLogger().throwing("FMLHandler", "raiseException", exception); - throw new RuntimeException(exception); - } - - /** - * @param p_21036_1_ - * @param var13 - * @param var15 - * @param var17 - * @param var9 - * @param var10 - * @param var12 - * @return - */ - public boolean tryDispensingEntity(World world, double x, double y, double z, byte xVelocity, byte zVelocity, ItemStack item) { - for (ModContainer mod : Loader.getModList()) { - if (mod.wantsToDispense() && mod.getDispenseHandler().dispense(x, y, z, xVelocity, zVelocity, world, item)) { - return true; - } + public void onPostTick() + { + FMLHooks.instance().gameTickEnd(); } - return false; - } - /** - * @return the instance - */ - public static FMLHandler instance() { - return INSTANCE; - } + public MinecraftServer getServer() + { + return server; + } - /** - * @return - */ - public BiomeGenBase[] getDefaultOverworldBiomes() { - if (defaultOverworldBiomes==null) { - ArrayList biomes=new ArrayList(20); - for (int i=0; i<23; i++) { - if ("Sky".equals(BiomeGenBase.field_35521_a[i].field_6163_m) || "Hell".equals(BiomeGenBase.field_35521_a[i].field_6163_m)) { - continue; + public static Logger getMinecraftLogger() + { + return MinecraftServer.field_6038_a; + } + + public void onChunkPopulate(IChunkProvider chunkProvider, int chunkX, int chunkZ, World world, IChunkProvider generator) + { + Random fmlRandom = new Random(world.func_22079_j()); + long xSeed = fmlRandom.nextLong() >> 2 + 1L; + long zSeed = fmlRandom.nextLong() >> 2 + 1L; + fmlRandom.setSeed((xSeed * chunkX + zSeed * chunkZ) ^ world.func_22079_j()); + + for (ModContainer mod : Loader.getModList()) + { + if (mod.generatesWorld()) + { + mod.getWorldGenerator().generate(fmlRandom, chunkX, chunkZ, world, generator, chunkProvider); + } } - biomes.add(BiomeGenBase.field_35521_a[i]); - } - defaultOverworldBiomes=new BiomeGenBase[biomes.size()]; - biomes.toArray(defaultOverworldBiomes); } - return defaultOverworldBiomes; - } - - public void onItemCrafted(EntityPlayer player, ItemStack craftedItem, IInventory craftingGrid) { - for (ModContainer mod : Loader.getModList()) { - if (mod.wantsCraftingNotification()) { - mod.getCraftingHandler().onCrafting(player,craftedItem,craftingGrid); - } - } - } - - public void onItemSmelted(EntityPlayer player, ItemStack smeltedItem) { - for (ModContainer mod : Loader.getModList()) { - if (mod.wantsCraftingNotification()) { - mod.getCraftingHandler().onSmelting(player,smeltedItem); - } - } - } - public boolean handleChatPacket(Packet3Chat chat, EntityPlayer player) { - for (ModContainer mod : Loader.getModList()) { - if (mod.wantsNetworkPackets() && mod.getNetworkHandler().onChat(chat,player)) { - return true; - } - } - return false; - } - - public void handlePacket250(Packet250CustomPayload packet, EntityPlayer player) { - if ("REGISTER".equals(packet.field_44005_a) || "UNREGISTER".equals(packet.field_44005_a)) { - handleClientRegistration(packet, player); - return; - } - ModContainer mod = FMLHooks.instance().getModForChannel(packet.field_44005_a); - if (mod!=null) { - mod.getNetworkHandler().onPacket250Packet(packet, player); - } - } + public int fuelLookup(int itemId, int itemDamage) + { + int fv = 0; - /** - * @param packet - */ - private void handleClientRegistration(Packet250CustomPayload packet, EntityPlayer player) { - try { - for (String channel : new String(packet.field_44004_c,"UTF8").split("\0")) { - // Skip it if we don't know it - if (FMLHooks.instance().getModForChannel(channel)==null) { - continue; + for (ModContainer mod : Loader.getModList()) + { + fv = Math.max(fv, mod.lookupFuelValue(itemId, itemDamage)); } - if ("REGISTER".equals(packet.field_44005_a)) { - FMLHooks.instance().activateChannel(player,channel); - } else { - FMLHooks.instance().deactivateChannel(player,channel); - } - } - } catch (UnsupportedEncodingException e) { - getMinecraftLogger().warning("Received invalid registration packet"); - } - } - public void handleLogin(Packet1Login loginPacket, NetworkManager networkManager) { - for (ModContainer mod : Loader.getModList()) { - if (mod.wantsNetworkPackets()) { - mod.getNetworkHandler().onLogin(loginPacket, networkManager); - } + return fv; + } + + public boolean isModLoaderMod(Class clazz) + { + return BaseMod.class.isAssignableFrom(clazz); + } + + public ModContainer loadBaseModMod(Class clazz, String canonicalPath) + { + @SuppressWarnings("unchecked") + Class bmClazz = (Class ) clazz; + return new ModLoaderModContainer(bmClazz, canonicalPath); + } + + public void notifyItemPickup(EntityItem entityItem, EntityPlayer entityPlayer) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsPickupNotification()) + { + mod.getPickupNotifier().notifyPickup(entityItem, entityPlayer); + } + } + } + + public static Logger getFMLLogger() + { + return Loader.log; + } + + public void raiseException(Throwable exception, String message, boolean stopGame) + { + getFMLLogger().throwing("FMLHandler", "raiseException", exception); + throw new RuntimeException(exception); + } + + /** + * @param p_21036_1_ + * @param var13 + * @param var15 + * @param var17 + * @param var9 + * @param var10 + * @param var12 + * @return + */ + public boolean tryDispensingEntity(World world, double x, double y, double z, byte xVelocity, byte zVelocity, ItemStack item) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsToDispense() && mod.getDispenseHandler().dispense(x, y, z, xVelocity, zVelocity, world, item)) + { + return true; + } + } + + return false; + } + + /** + * @return the instance + */ + public static FMLHandler instance() + { + return INSTANCE; + } + + /** + * @return + */ + public BiomeGenBase[] getDefaultOverworldBiomes() + { + if (defaultOverworldBiomes == null) + { + ArrayList biomes = new ArrayList(20); + + for (int i = 0; i < 23; i++) + { + if ("Sky".equals(BiomeGenBase.field_35521_a[i].field_6163_m) || "Hell".equals(BiomeGenBase.field_35521_a[i].field_6163_m)) + { + continue; + } + + biomes.add(BiomeGenBase.field_35521_a[i]); + } + + defaultOverworldBiomes = new BiomeGenBase[biomes.size()]; + biomes.toArray(defaultOverworldBiomes); + } + + return defaultOverworldBiomes; + } + + public void onItemCrafted(EntityPlayer player, ItemStack craftedItem, IInventory craftingGrid) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsCraftingNotification()) + { + mod.getCraftingHandler().onCrafting(player, craftedItem, craftingGrid); + } + } + } + + public void onItemSmelted(EntityPlayer player, ItemStack smeltedItem) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsCraftingNotification()) + { + mod.getCraftingHandler().onSmelting(player, smeltedItem); + } + } + } + + public boolean handleChatPacket(Packet3Chat chat, EntityPlayer player) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsNetworkPackets() && mod.getNetworkHandler().onChat(chat, player)) + { + return true; + } + } + + return false; + } + + public void handlePacket250(Packet250CustomPayload packet, EntityPlayer player) + { + if ("REGISTER".equals(packet.field_44005_a) || "UNREGISTER".equals(packet.field_44005_a)) + { + handleClientRegistration(packet, player); + return; + } + + ModContainer mod = FMLHooks.instance().getModForChannel(packet.field_44005_a); + + if (mod != null) + { + mod.getNetworkHandler().onPacket250Packet(packet, player); + } + } + + /** + * @param packet + */ + private void handleClientRegistration(Packet250CustomPayload packet, EntityPlayer player) + { + try + { + for (String channel : new String(packet.field_44004_c, "UTF8").split("\0")) + { + // Skip it if we don't know it + if (FMLHooks.instance().getModForChannel(channel) == null) + { + continue; + } + + if ("REGISTER".equals(packet.field_44005_a)) + { + FMLHooks.instance().activateChannel(player, channel); + } + else + { + FMLHooks.instance().deactivateChannel(player, channel); + } + } + } + catch (UnsupportedEncodingException e) + { + getMinecraftLogger().warning("Received invalid registration packet"); + } + } + + public void handleLogin(Packet1Login loginPacket, NetworkManager networkManager) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsNetworkPackets()) + { + mod.getNetworkHandler().onLogin(loginPacket, networkManager); + } + } + + Packet250CustomPayload packet = new Packet250CustomPayload(); + packet.field_44005_a = "REGISTER"; + packet.field_44004_c = FMLHooks.instance().getPacketRegistry(); + packet.field_44003_b = packet.field_44004_c.length; + networkManager.func_745_a(packet); } - Packet250CustomPayload packet=new Packet250CustomPayload(); - packet.field_44005_a="REGISTER"; - packet.field_44004_c=FMLHooks.instance().getPacketRegistry(); - packet.field_44003_b=packet.field_44004_c.length; - networkManager.func_745_a(packet); - } } diff --git a/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java b/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java index f8caea04b..d31bdcf24 100644 --- a/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java +++ b/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java @@ -1,13 +1,13 @@ /* * 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 */ @@ -36,343 +36,468 @@ import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.LoaderException; import cpw.mods.fml.common.ModContainer; -public class ModLoaderModContainer implements ModContainer { - private Class modClazz; - private BaseMod mod; - private boolean isTicking; - private String modSource ; - private ArrayList dependencies; - private ArrayList preDependencies; - private ArrayList postDependencies; - public ModLoaderModContainer(Class modClazz, String modSource) { - this.modClazz=modClazz; - this.modSource =modSource; - } - - public boolean wantsPreInit() { - return true; - } - - public boolean wantsPostInit() { - return true; - } - - @Override - public void preInit() { - try { - configureMod(); - mod=modClazz.newInstance(); - } catch (Exception e) { - throw new LoaderException(e); +public class ModLoaderModContainer implements ModContainer +{ + private Class modClazz; + private BaseMod mod; + private boolean isTicking; + private String modSource ; + private ArrayList dependencies; + private ArrayList preDependencies; + private ArrayList postDependencies; + public ModLoaderModContainer(Class modClazz, String modSource) + { + this.modClazz = modClazz; + this.modSource = modSource; } - } - /** - * - */ - private void configureMod() { - File configDir=Loader.instance().getConfigDir(); - File modConfig=new File(configDir,String.format("%s.cfg", modClazz.getSimpleName())); - Properties props=new Properties(); - if (modConfig.exists()) { - try { - FileReader configReader = new FileReader(modConfig); - props.load(configReader); - configReader.close(); - } catch (Exception e) { - Loader.log.severe(String.format("Error occured reading mod configuration file %s",modConfig.getName())); - Loader.log.throwing("ModLoaderModContainer", "configureMod", e); - throw new LoaderException(e); - } + public boolean wantsPreInit() + { + return true; } - - StringBuffer comments = new StringBuffer(); - comments.append("MLProperties: name (type:default) min:max -- information\n"); - try { - for (Field f : modClazz.getDeclaredFields()) { - if (!Modifier.isStatic(f.getModifiers())) { - continue; + + public boolean wantsPostInit() + { + return true; + } + + @Override + public void preInit() + { + try + { + configureMod(); + mod = modClazz.newInstance(); + } + catch (Exception e) + { + throw new LoaderException(e); + } + } + + /** + * + */ + private void configureMod() + { + File configDir = Loader.instance().getConfigDir(); + File modConfig = new File(configDir, String.format("%s.cfg", modClazz.getSimpleName())); + Properties props = new Properties(); + + if (modConfig.exists()) + { + try + { + FileReader configReader = new FileReader(modConfig); + props.load(configReader); + configReader.close(); + } + catch (Exception e) + { + Loader.log.severe(String.format("Error occured reading mod configuration file %s", modConfig.getName())); + Loader.log.throwing("ModLoaderModContainer", "configureMod", e); + throw new LoaderException(e); + } } - if (!f.isAnnotationPresent(MLProp.class)) { - continue; - } + StringBuffer comments = new StringBuffer(); + comments.append("MLProperties: name (type:default) min:max -- information\n"); - MLProp property = f.getAnnotation(MLProp.class); - String propertyName = property.name().length() > 0 ? property.name() : f.getName(); - String propertyValue = null; - Object defaultValue = null; - try { - defaultValue = f.get(null); - propertyValue = props.getProperty(propertyName, extractValue(defaultValue)); - Object currentValue = parseValue(propertyValue, property, f.getType()); - if (currentValue != null && !currentValue.equals(defaultValue)) { - f.set(null, currentValue); - } - } catch (Exception e) { - Loader.log.severe(String.format("Invalid configuration found for %s in %s", propertyName, modConfig.getName())); - Loader.log.throwing("ModLoaderModContainer", "configureMod", e); - throw new LoaderException(e); - } finally { - comments.append(String.format("MLProp : %s (%s:%s", propertyName, f.getType().getName(), defaultValue)); - if (property.min() != Double.MIN_VALUE) { - comments.append(",>=").append(String.format("%.1f", property.min())); - } - if (property.max() != Double.MAX_VALUE) { - comments.append(",<=").append(String.format("%.1f", property.max())); - } - comments.append(")"); - if (property.info().length() > 0) { - comments.append(" -- ").append(property.info()); - } - if (propertyValue != null) { - props.setProperty(propertyName, extractValue(propertyValue)); - } + try + { + for (Field f : modClazz.getDeclaredFields()) + { + if (!Modifier.isStatic(f.getModifiers())) + { + continue; + } + + if (!f.isAnnotationPresent(MLProp.class)) + { + continue; + } + + MLProp property = f.getAnnotation(MLProp.class); + String propertyName = property.name().length() > 0 ? property.name() : f.getName(); + String propertyValue = null; + Object defaultValue = null; + + try + { + defaultValue = f.get(null); + propertyValue = props.getProperty(propertyName, extractValue(defaultValue)); + Object currentValue = parseValue(propertyValue, property, f.getType()); + + if (currentValue != null && !currentValue.equals(defaultValue)) + { + f.set(null, currentValue); + } + } + catch (Exception e) + { + Loader.log.severe(String.format("Invalid configuration found for %s in %s", propertyName, modConfig.getName())); + Loader.log.throwing("ModLoaderModContainer", "configureMod", e); + throw new LoaderException(e); + } + finally + { + comments.append(String.format("MLProp : %s (%s:%s", propertyName, f.getType().getName(), defaultValue)); + + if (property.min() != Double.MIN_VALUE) + { + comments.append(",>=").append(String.format("%.1f", property.min())); + } + + if (property.max() != Double.MAX_VALUE) + { + comments.append(",<=").append(String.format("%.1f", property.max())); + } + + comments.append(")"); + + if (property.info().length() > 0) + { + comments.append(" -- ").append(property.info()); + } + + if (propertyValue != null) + { + props.setProperty(propertyName, extractValue(propertyValue)); + } + } + } + } + finally + { + try + { + FileWriter configWriter = new FileWriter(modConfig); + props.store(configWriter, comments.toString()); + configWriter.close(); + } + catch (IOException e) + { + Loader.log.warning(String.format("Error trying to write the config file %s", modConfig.getName())); + Loader.log.throwing("ModLoaderModContainer", "configureMod", e); + throw new LoaderException(e); + } } - } - } finally { - try { - FileWriter configWriter=new FileWriter(modConfig); - props.store(configWriter, comments.toString()); - configWriter.close(); - } catch (IOException e) { - Loader.log.warning(String.format("Error trying to write the config file %s",modConfig.getName())); - Loader.log.throwing("ModLoaderModContainer", "configureMod", e); - throw new LoaderException(e); - } } - } - private Object parseValue(String val, MLProp property, Class type) { - if (type.isAssignableFrom(String.class)) { - return (String)val; - } else if (type.isAssignableFrom(Boolean.TYPE)) { - return Boolean.parseBoolean(val); - } else if (Number.class.isAssignableFrom(type)) { - Number n=null; - if (type.isAssignableFrom(Double.TYPE)) { - n=Double.parseDouble(val); - } else if (type.isAssignableFrom(Float.TYPE)) { - n=Float.parseFloat(val); - } else if (type.isAssignableFrom(Long.TYPE)) { - n=Long.parseLong(val); - } else if (type.isAssignableFrom(Integer.TYPE)) { - n=Integer.parseInt(val); - } else if (type.isAssignableFrom(Short.TYPE)) { - n=Short.parseShort(val); - } else if (type.isAssignableFrom(Byte.TYPE)) { - n=Byte.parseByte(val); - } else { - throw new IllegalArgumentException("MLProp declared on non-standard type"); - } - if (n.doubleValue()property.max()) { + private Object parseValue(String val, MLProp property, Class type) + { + if (type.isAssignableFrom(String.class)) + { + return (String)val; + } + else if (type.isAssignableFrom(Boolean.TYPE)) + { + return Boolean.parseBoolean(val); + } + else if (Number.class.isAssignableFrom(type)) + { + Number n = null; + + if (type.isAssignableFrom(Double.TYPE)) + { + n = Double.parseDouble(val); + } + else if (type.isAssignableFrom(Float.TYPE)) + { + n = Float.parseFloat(val); + } + else if (type.isAssignableFrom(Long.TYPE)) + { + n = Long.parseLong(val); + } + else if (type.isAssignableFrom(Integer.TYPE)) + { + n = Integer.parseInt(val); + } + else if (type.isAssignableFrom(Short.TYPE)) + { + n = Short.parseShort(val); + } + else if (type.isAssignableFrom(Byte.TYPE)) + { + n = Byte.parseByte(val); + } + else + { + throw new IllegalArgumentException("MLProp declared on non-standard type"); + } + + if (n.doubleValue() < property.min() || n.doubleValue() > property.max()) + { + return null; + } + else + { + return n; + } + } + return null; - } else { - return n; - } } - return null; - } - private String extractValue(Object value) { - if (String.class.isInstance(value)) { - return (String)value; - } else if (Number.class.isInstance(value)) { - return String.valueOf(value); - } else { - throw new IllegalArgumentException("MLProp declared on non-standard type"); + private String extractValue(Object value) + { + if (String.class.isInstance(value)) + { + return (String)value; + } + else if (Number.class.isInstance(value)) + { + return String.valueOf(value); + } + else + { + throw new IllegalArgumentException("MLProp declared on non-standard type"); + } } - } - @Override - public void init() { - mod.load(); - } - - @Override - public void postInit() { - mod.modsLoaded(); - } - - @Override - public void tickStart() { - if (isTicking) { - isTicking=mod.onTickInGame(FMLHandler.instance().getServer()); + @Override + public void init() + { + mod.load(); } - } - @Override - public void tickEnd() { - // NOOP for modloader - } - @Override - public String getName() { - return mod!=null?mod.getName():null; - } - - public static ModContainer findContainerFor(BaseMod mod) { - for (ModContainer mc :Loader.getModList()) { - if (mc.matches(mod)) { - return mc; - } + @Override + public void postInit() + { + mod.modsLoaded(); } - return null; - } - @Override - public boolean matches(Object mod) { - return modClazz.isInstance(mod); - } - - public void setTicking(boolean enable) { - isTicking=enable; - } - - public static List findAll() { - ArrayList modList=new ArrayList(); - for (ModContainer mc : Loader.getModList()) { - if (mc instanceof ModLoaderModContainer) { - modList.add(((ModLoaderModContainer)mc).mod); - } + @Override + public void tickStart() + { + if (isTicking) + { + isTicking = mod.onTickInGame(FMLHandler.instance().getServer()); + } } - return modList; - } - - @Override - public String getSource() { - return modSource; - } - - @Override - public Object getMod() { - return mod; - } - - @Override - public boolean generatesWorld() { - return true; - } - - @Override - public IWorldGenerator getWorldGenerator() { - return mod; - } - - @Override - public int lookupFuelValue(int itemId, int itemDamage) { - return mod.addFuel(itemId, itemDamage); - } - - @Override - public boolean wantsPickupNotification() { - return true; - } - - @Override - public IPickupNotifier getPickupNotifier() { - return mod; - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#wantsToDispense() - */ - @Override - public boolean wantsToDispense() { - return true; - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getDispenseHandler() - */ - @Override - public IDispenseHandler getDispenseHandler() { - return mod; - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification() - */ - @Override - public boolean wantsCraftingNotification() { - return true; - } - - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getCraftingHandler() - */ - @Override - public ICraftingHandler getCraftingHandler() { - return mod; - } - - private void computeDependencies() { - dependencies = new ArrayList(); - preDependencies = new ArrayList(); - postDependencies = new ArrayList(); - if (mod.getPriorities()==null || mod.getPriorities().length()==0) { - return; + @Override + public void tickEnd() + { + // NOOP for modloader } - StringTokenizer st=new StringTokenizer(mod.getPriorities(),";"); - for (; st.hasMoreTokens(); ) { - String dep=st.nextToken(); - String[] depparts=dep.split(":"); - if (depparts.length<2) { - throw new LoaderException(); - } - if ("required-before".equals(depparts[0]) || "required-after".equals(depparts[0])) { - dependencies.add(depparts[1]); - } - - if ("required-before".equals(depparts[0]) || "before".equals(depparts[0])) { - preDependencies.add(depparts[1]); - } - - if ("required-after".equals(depparts[0]) || "after".equals(depparts[0])) { - postDependencies.add(depparts[1]); - } + + @Override + public String getName() + { + return mod != null ? mod.getName() : null; } - } - /* (non-Javadoc) - * @see cpw.mods.fml.common.ModContainer#getDependencies() - */ - @Override - public List getDependencies() { - if (dependencies==null) { - computeDependencies(); + + public static ModContainer findContainerFor(BaseMod mod) + { + for (ModContainer mc : Loader.getModList()) + { + if (mc.matches(mod)) + { + return mc; + } + } + + return null; } - return dependencies; - } - @Override - public List getPreDepends() { - if (dependencies==null) { - computeDependencies(); + @Override + public boolean matches(Object mod) + { + return modClazz.isInstance(mod); } - return preDependencies; - } - @Override - public List getPostDepends() { - if (dependencies==null) { - computeDependencies(); + public void setTicking(boolean enable) + { + isTicking = enable; } - return postDependencies; - } - - public String toString() { - return modSource; - } - @Override - public boolean wantsNetworkPackets() { - return true; - } + public static List findAll() + { + ArrayList modList = new ArrayList(); - @Override - public INetworkHandler getNetworkHandler() { - return mod; - } + for (ModContainer mc : Loader.getModList()) + { + if (mc instanceof ModLoaderModContainer) + { + modList.add(((ModLoaderModContainer)mc).mod); + } + } - @Override - public boolean ownsNetworkChannel(String channel) { - return FMLHooks.instance().getChannelListFor(this).contains(channel); - } + return modList; + } + + @Override + public String getSource() + { + return modSource; + } + + @Override + public Object getMod() + { + return mod; + } + + @Override + public boolean generatesWorld() + { + return true; + } + + @Override + public IWorldGenerator getWorldGenerator() + { + return mod; + } + + @Override + public int lookupFuelValue(int itemId, int itemDamage) + { + return mod.addFuel(itemId, itemDamage); + } + + @Override + public boolean wantsPickupNotification() + { + return true; + } + + @Override + public IPickupNotifier getPickupNotifier() + { + return mod; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsToDispense() + */ + @Override + public boolean wantsToDispense() + { + return true; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getDispenseHandler() + */ + @Override + public IDispenseHandler getDispenseHandler() + { + return mod; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification() + */ + @Override + public boolean wantsCraftingNotification() + { + return true; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getCraftingHandler() + */ + @Override + public ICraftingHandler getCraftingHandler() + { + return mod; + } + + private void computeDependencies() + { + dependencies = new ArrayList(); + preDependencies = new ArrayList(); + postDependencies = new ArrayList(); + + if (mod.getPriorities() == null || mod.getPriorities().length() == 0) + { + return; + } + + StringTokenizer st = new StringTokenizer(mod.getPriorities(), ";"); + + for (; st.hasMoreTokens();) + { + String dep = st.nextToken(); + String[] depparts = dep.split(":"); + + if (depparts.length < 2) + { + throw new LoaderException(); + } + + if ("required-before".equals(depparts[0]) || "required-after".equals(depparts[0])) + { + dependencies.add(depparts[1]); + } + + if ("required-before".equals(depparts[0]) || "before".equals(depparts[0])) + { + preDependencies.add(depparts[1]); + } + + if ("required-after".equals(depparts[0]) || "after".equals(depparts[0])) + { + postDependencies.add(depparts[1]); + } + } + } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getDependencies() + */ + @Override + public List getDependencies() + { + if (dependencies == null) + { + computeDependencies(); + } + + return dependencies; + } + + @Override + public List getPreDepends() + { + if (dependencies == null) + { + computeDependencies(); + } + + return preDependencies; + } + + @Override + public List getPostDepends() + { + if (dependencies == null) + { + computeDependencies(); + } + + return postDependencies; + } + + public String toString() + { + return modSource; + } + + @Override + public boolean wantsNetworkPackets() + { + return true; + } + + @Override + public INetworkHandler getNetworkHandler() + { + return mod; + } + + @Override + public boolean ownsNetworkChannel(String channel) + { + return FMLHooks.instance().getChannelListFor(this).contains(channel); + } } diff --git a/fml/server/net/minecraft/src/BaseMod.java b/fml/server/net/minecraft/src/BaseMod.java index 9651d4d52..0e2155d0a 100644 --- a/fml/server/net/minecraft/src/BaseMod.java +++ b/fml/server/net/minecraft/src/BaseMod.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -21,230 +21,256 @@ import cpw.mods.fml.common.INetworkHandler; import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; -public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler { - // CALLBACK MECHANISMS - @Override - public final void onCrafting(Object... craftingParameters) { - takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); - } - - @Override - public final void onSmelting(Object... smeltingParameters) { - takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]); - } - @Override - public final boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data) { - return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]); - } - - @Override - public final boolean onChat(Object... data) { - return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]); - } - @Override - public final void onLogin(Object... data) { - onClientLogin((Packet1Login)data[0],(NetworkManager)data[1]); - } - - @Override - public final void onPacket250Packet(Object... data) { - onPacket250Received((EntityPlayer)data[1], (Packet250CustomPayload)data[0]); - } - - @Override - public final void notifyPickup(Object... pickupData) { - EntityItem item=(EntityItem) pickupData[0]; - EntityPlayer player=(EntityPlayer) pickupData[1]; - onItemPickup(player, item.field_429_a); - } - - @Override - public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData) { - World w=(World) additionalData[0]; - IChunkProvider cp=(IChunkProvider) additionalData[1]; - - if (cp instanceof ChunkProviderGenerate) { - generateSurface(w, random, chunkX<<4, chunkZ<<4); - } else if (cp instanceof ChunkProviderHell){ - generateNether(w, random, chunkX<<4, chunkZ<<4); +public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler +{ + // CALLBACK MECHANISMS + @Override + public final void onCrafting(Object... craftingParameters) + { + takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); } - } - - // BASEMOD API - /** - * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item - * @param id - * @param metadata - * @return - */ - public int addFuel(int id, int metadata) { - return 0; - } - /** - * Override if you wish to perform some action other than just dispensing the item from the dispenser - * @param world - * @param x - * @param y - * @param z - * @param xVel - * @param zVel - * @param item - * @return - */ - public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) { - return false; - } + @Override + public final void onSmelting(Object... smeltingParameters) + { + takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]); + } + @Override + public final boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data) + { + return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]); + } - /** - * Override if you wish to generate Nether (Hell biome) blocks - * @param world - * @param random - * @param chunkX - * @param chunkZ - */ - public void generateNether(World world, Random random, int chunkX, int chunkZ) { - } + @Override + public final boolean onChat(Object... data) + { + return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]); + } + @Override + public final void onLogin(Object... data) + { + onClientLogin((Packet1Login)data[0], (NetworkManager)data[1]); + } - /** - * Override if you wish to generate Overworld (not hell or the end) blocks - * @param world - * @param random - * @param chunkX - * @param chunkZ - */ - public void generateSurface(World world, Random random, int chunkX, int chunkZ) { - } + @Override + public final void onPacket250Packet(Object... data) + { + onPacket250Received((EntityPlayer)data[1], (Packet250CustomPayload)data[0]); + } - /** - * Return the name of your mod. Defaults to the class name - * @return - */ - public String getName() { - return getClass().getSimpleName(); - } + @Override + public final void notifyPickup(Object... pickupData) + { + EntityItem item = (EntityItem) pickupData[0]; + EntityPlayer player = (EntityPlayer) pickupData[1]; + onItemPickup(player, item.field_429_a); + } - /** - * Get your mod priorities - * @return - */ - public String getPriorities() { - return null; - } + @Override + public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData) + { + World w = (World) additionalData[0]; + IChunkProvider cp = (IChunkProvider) additionalData[1]; - /** - * Return the version of your mod - * @return - */ - public abstract String getVersion(); + if (cp instanceof ChunkProviderGenerate) + { + generateSurface(w, random, chunkX << 4, chunkZ << 4); + } + else if (cp instanceof ChunkProviderHell) + { + generateNether(w, random, chunkX << 4, chunkZ << 4); + } + } - /** - * Load your mod - */ - public abstract void load(); + // BASEMOD API + /** + * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item + * @param id + * @param metadata + * @return + */ + public int addFuel(int id, int metadata) + { + return 0; + } - /** - * Finish loading your mod - */ - public void modsLoaded() { - } + /** + * Override if you wish to perform some action other than just dispensing the item from the dispenser + * @param world + * @param x + * @param y + * @param z + * @param xVel + * @param zVel + * @param item + * @return + */ + public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) + { + return false; + } - /** - * Handle item pickup - * @param player - * @param item - */ - public void onItemPickup(EntityPlayer player, ItemStack item) { - } + /** + * Override if you wish to generate Nether (Hell biome) blocks + * @param world + * @param random + * @param chunkX + * @param chunkZ + */ + public void generateNether(World world, Random random, int chunkX, int chunkZ) + { + } - /** - * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)} - * @param minecraftServer the server - * @return true to continue receiving ticks - */ - public boolean onTickInGame(MinecraftServer minecraftServer) { - return false; - } + /** + * Override if you wish to generate Overworld (not hell or the end) blocks + * @param world + * @param random + * @param chunkX + * @param chunkZ + */ + public void generateSurface(World world, Random random, int chunkX, int chunkZ) + { + } - /** - * Not implemented because on the server you don't know who it's from - * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} - * @param text - */ - @Deprecated - public void receiveChatPacket(String text) { - } + /** + * Return the name of your mod. Defaults to the class name + * @return + */ + public String getName() + { + return getClass().getSimpleName(); + } - /** - * Not implemented because on the server you don't know who it's from - * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} - * @param packet - */ - @Deprecated - public void receiveCustomPacket(Packet250CustomPayload packet) { - } + /** + * Get your mod priorities + * @return + */ + public String getPriorities() + { + return null; + } - /** - * Called when someone crafts an item from a crafting table - * @param player - * @param item - * @param matrix - */ - public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) { - } + /** + * Return the version of your mod + * @return + */ + public abstract String getVersion(); - /** - * Called when someone takes a smelted item from a furnace - * - * @param player - * @param item - */ - public void takenFromFurnace(EntityPlayer player, ItemStack item) { + /** + * Load your mod + */ + public abstract void load(); - } + /** + * Finish loading your mod + */ + public void modsLoaded() + { + } - /** - * The identifier string for the mod- used in client<->server negotiation - */ - @Override - public String toString() { - return getName()+" "+getVersion(); - } + /** + * Handle item pickup + * @param player + * @param item + */ + public void onItemPickup(EntityPlayer player, ItemStack item) + { + } - /** - * Called when a 250 packet is received on a channel registered to this mod - * - * @param source - * @param payload - */ - public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload) { - - } - - /** - * Called when a new client logs in. Make sure modloader knows about your channels - * @param login - * @param data - */ - public void onClientLogin(Packet1Login login, NetworkManager data) { - - } - - /** - * Called when a chat message is received. Return true to stop further processing - * @param source - * @param chat - * @return - */ - public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat) { - return false; - } - // Spare client junk - // ------- - // void addRenderer(Map, Render> renderers); - // void registerAnimation(Minecraft game); - // void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID); - // boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID); - // boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui); - // void keyboardEvent(KeyBinding event); + /** + * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)} + * @param minecraftServer the server + * @return true to continue receiving ticks + */ + public boolean onTickInGame(MinecraftServer minecraftServer) + { + return false; + } + + /** + * Not implemented because on the server you don't know who it's from + * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} + * @param text + */ + @Deprecated + public void receiveChatPacket(String text) + { + } + + /** + * Not implemented because on the server you don't know who it's from + * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} + * @param packet + */ + @Deprecated + public void receiveCustomPacket(Packet250CustomPayload packet) + { + } + + /** + * Called when someone crafts an item from a crafting table + * @param player + * @param item + * @param matrix + */ + public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) + { + } + + /** + * Called when someone takes a smelted item from a furnace + * + * @param player + * @param item + */ + public void takenFromFurnace(EntityPlayer player, ItemStack item) + { + } + + /** + * The identifier string for the mod- used in client<->server negotiation + */ + @Override + public String toString() + { + return getName() + " " + getVersion(); + } + + /** + * Called when a 250 packet is received on a channel registered to this mod + * + * @param source + * @param payload + */ + public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload) + { + } + + /** + * Called when a new client logs in. Make sure modloader knows about your channels + * @param login + * @param data + */ + public void onClientLogin(Packet1Login login, NetworkManager data) + { + } + + /** + * Called when a chat message is received. Return true to stop further processing + * @param source + * @param chat + * @return + */ + public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat) + { + return false; + } + // Spare client junk + // ------- + // void addRenderer(Map, Render> renderers); + // void registerAnimation(Minecraft game); + // void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID); + // boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID); + // boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui); + // void keyboardEvent(KeyBinding event); } diff --git a/fml/server/net/minecraft/src/MLProp.java b/fml/server/net/minecraft/src/MLProp.java index e13ce7cbb..d3d19695e 100644 --- a/fml/server/net/minecraft/src/MLProp.java +++ b/fml/server/net/minecraft/src/MLProp.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -19,29 +19,30 @@ 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 ""; +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 1D; + /** + * Maximum value allowed if field is a number. + */ +double max() default 1D; - /** - * Minimum value allowed if field is a number. - */ - double min() default -1D; + /** + * Minimum value allowed if field is a number. + */ +double min() default -1D; - /** - * Overrides the field name for property key. - */ - String name() default ""; + /** + * 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 bc08a2af4..64e4a8ccf 100644 --- a/fml/server/net/minecraft/src/ModLoader.java +++ b/fml/server/net/minecraft/src/ModLoader.java @@ -1,12 +1,12 @@ /* * 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 */ @@ -22,529 +22,588 @@ import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.server.FMLHandler; import cpw.mods.fml.server.ModLoaderModContainer; -public class ModLoader { - /** - * Not used on the server. - * - * @param achievement - * @param name - * @param description - */ - public static void addAchievementDesc(Achievement achievement, String name, String description) { - } - - /** - * This method is a call in hook from modified external code. Implemented elsewhere. - * - * {@link FMLHandler#fuelLookup(int, int)} - * @param id - * @param metadata - * @return - */ - @Deprecated - public static int addAllFuel(int id, int metadata) { - return 0; - } - - /** - * This method is unimplemented in server versions to date. - * - * @param armor - * @return - */ - @Deprecated - public static int addArmor(String armor) { - return 0; - } - - /** - * This method does not work. Creation of a BiomeGenBase is sufficient to populate this array. Using this method will likely corrupt worlds. - * - * @param biome - */ - @Deprecated - public static void addBiome(BiomeGenBase biome) { - } - - /** - * Unimplemented on the server as it does not generate names - * @param key - * @param value - */ - @Deprecated - public static void addLocalization(String key, String value) { - } - - /** - * Unimplemented on the server as it does not generate names - * @param key - * @param lang - * @param value - */ - @Deprecated - public static void addLocalization(String key, String lang, String value) { - } - - /** - * Unimplemented on the server as it does not generate names - * @param instance - * @param name - */ - @Deprecated - public static void addName(Object instance, String name) { - } - - /** - * Unimplemented on the server as it does not generate names - * @param instance - * @param lang - * @param name - */ - @Deprecated - public static void addName(Object instance, String lang, String name) { - } - - /** - * Unimplemented on the server as it does not render textures - * @param fileToOverride - * @param fileToAdd - * @return - */ - @Deprecated - public static int addOverride(String fileToOverride, String fileToAdd) { - return 0; - } - - /** - * Unimplemented on the server as it does not render textures - * @param path - * @param overlayPath - * @param index - */ - @Deprecated - public static void addOverride(String path, String overlayPath, int index) { - } - - /** - * Add a Shaped Recipe - * @param output - * @param params - */ - public static void addRecipe(ItemStack output, Object... params) { - CommonRegistry.addRecipe(output, params); - } - - /** - * Add a shapeless recipe - * @param output - * @param params - */ - public static void addShapelessRecipe(ItemStack output, Object... params) { - CommonRegistry.addShapelessRecipe(output, params); - } - - /** - * Add a new product to be smelted - * @param input - * @param output - */ - public static void addSmelting(int input, ItemStack output) { - CommonRegistry.addSmelting(input, output); - } - - /** - * Add a mob to the spawn list - * @param entityClass - * @param weightedProb - * @param min - * @param max - * @param spawnList - */ - public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); - } - - /** - * Add a mob to the spawn list - * @param entityClass - * @param weightedProb - * @param min - * @param max - * @param spawnList - * @param biomes - */ - public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); - } - - /** - * Add a mob to the spawn list - * @param entityName - * @param weightedProb - * @param min - * @param max - * @param spawnList - */ - public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); - } - - /** - * Add a mob to the spawn list - * @param entityName - * @param weightedProb - * @param min - * @param max - * @param spawnList - * @param biomes - */ - public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); - } - - /** - * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLHandler#tryDispensingEntity(World, double, double, double, byte, byte, ItemStack)} - * @param world - * @param x - * @param y - * @param z - * @param xVel - * @param zVel - * @param item - * @return - */ - @Deprecated - public static boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) { - return false; - } - - /** - * Remove a container and drop all the items in it on the ground around - * @param world - * @param x - * @param y - * @param z - */ - public static void genericContainerRemoval(World world, int x, int y, int z) { - TileEntity te=world.func_451_k(x, y, z); - if (!(te instanceof IInventory)) { - return; - } - IInventory inv=(IInventory)te; - for (int l = 0; l < inv.func_83_a(); l++) +public class ModLoader +{ + /** + * Not used on the server. + * + * @param achievement + * @param name + * @param description + */ + public static void addAchievementDesc(Achievement achievement, String name, String description) { - ItemStack itemstack = inv.func_82_a(l); - if (itemstack == null) + } + + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * + * {@link FMLHandler#fuelLookup(int, int)} + * @param id + * @param metadata + * @return + */ + @Deprecated + public static int addAllFuel(int id, int metadata) + { + return 0; + } + + /** + * This method is unimplemented in server versions to date. + * + * @param armor + * @return + */ + @Deprecated + public static int addArmor(String armor) + { + return 0; + } + + /** + * This method does not work. Creation of a BiomeGenBase is sufficient to populate this array. Using this method will likely corrupt worlds. + * + * @param biome + */ + @Deprecated + public static void addBiome(BiomeGenBase biome) + { + } + + /** + * Unimplemented on the server as it does not generate names + * @param key + * @param value + */ + @Deprecated + public static void addLocalization(String key, String value) + { + } + + /** + * Unimplemented on the server as it does not generate names + * @param key + * @param lang + * @param value + */ + @Deprecated + public static void addLocalization(String key, String lang, String value) + { + } + + /** + * Unimplemented on the server as it does not generate names + * @param instance + * @param name + */ + @Deprecated + public static void addName(Object instance, String name) + { + } + + /** + * Unimplemented on the server as it does not generate names + * @param instance + * @param lang + * @param name + */ + @Deprecated + public static void addName(Object instance, String lang, String name) + { + } + + /** + * Unimplemented on the server as it does not render textures + * @param fileToOverride + * @param fileToAdd + * @return + */ + @Deprecated + public static int addOverride(String fileToOverride, String fileToAdd) + { + return 0; + } + + /** + * Unimplemented on the server as it does not render textures + * @param path + * @param overlayPath + * @param index + */ + @Deprecated + public static void addOverride(String path, String overlayPath, int index) + { + } + + /** + * Add a Shaped Recipe + * @param output + * @param params + */ + public static void addRecipe(ItemStack output, Object... params) + { + CommonRegistry.addRecipe(output, params); + } + + /** + * Add a shapeless recipe + * @param output + * @param params + */ + public static void addShapelessRecipe(ItemStack output, Object... params) + { + CommonRegistry.addShapelessRecipe(output, params); + } + + /** + * Add a new product to be smelted + * @param input + * @param output + */ + public static void addSmelting(int input, ItemStack output) + { + CommonRegistry.addSmelting(input, output); + } + + /** + * Add a mob to the spawn list + * @param entityClass + * @param weightedProb + * @param min + * @param max + * @param spawnList + */ + public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) + { + CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); + } + + /** + * Add a mob to the spawn list + * @param entityClass + * @param weightedProb + * @param min + * @param max + * @param spawnList + * @param biomes + */ + public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); + } + + /** + * Add a mob to the spawn list + * @param entityName + * @param weightedProb + * @param min + * @param max + * @param spawnList + */ + public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) + { + CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); + } + + /** + * Add a mob to the spawn list + * @param entityName + * @param weightedProb + * @param min + * @param max + * @param spawnList + * @param biomes + */ + public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); + } + + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * {@link FMLHandler#tryDispensingEntity(World, double, double, double, byte, byte, ItemStack)} + * @param world + * @param x + * @param y + * @param z + * @param xVel + * @param zVel + * @param item + * @return + */ + @Deprecated + public static boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) + { + return false; + } + + /** + * Remove a container and drop all the items in it on the ground around + * @param world + * @param x + * @param y + * @param z + */ + public static void genericContainerRemoval(World world, int x, int y, int z) + { + TileEntity te = world.func_451_k(x, y, z); + + if (!(te instanceof IInventory)) { - continue; + return; } - float f = world.field_803_m.nextFloat() * 0.8F + 0.1F; - float f1 = world.field_803_m.nextFloat() * 0.8F + 0.1F; - float f2 = world.field_803_m.nextFloat() * 0.8F + 0.1F; - while (itemstack.field_853_a > 0) + + IInventory inv = (IInventory)te; + + for (int l = 0; l < inv.func_83_a(); l++) { - int i1 = world.field_803_m.nextInt(21) + 10; - if (i1 > itemstack.field_853_a) + ItemStack itemstack = inv.func_82_a(l); + + if (itemstack == null) { - i1 = itemstack.field_853_a ; + continue; } - itemstack.field_853_a -= i1; - EntityItem entityitem = new EntityItem(world, (float)te.field_478_b + f, (float)te.field_483_c + f1, (float)te.field_482_d + f2, new ItemStack(itemstack.field_855_c, i1, itemstack.func_21125_h())); - float f3 = 0.05F; - entityitem.field_319_o = (float)world.field_803_m.nextGaussian() * f3; - entityitem.field_318_p = (float)world.field_803_m.nextGaussian() * f3 + 0.2F; - entityitem.field_317_q = (float)world.field_803_m.nextGaussian() * f3; - if (itemstack.func_40608_n()) + + float f = world.field_803_m.nextFloat() * 0.8F + 0.1F; + float f1 = world.field_803_m.nextFloat() * 0.8F + 0.1F; + float f2 = world.field_803_m.nextFloat() * 0.8F + 0.1F; + + while (itemstack.field_853_a > 0) { - entityitem.field_429_a.func_40604_d((NBTTagCompound)itemstack.func_40607_o().func_40468_b()); + int i1 = world.field_803_m.nextInt(21) + 10; + + if (i1 > itemstack.field_853_a) + { + i1 = itemstack.field_853_a ; + } + + itemstack.field_853_a -= i1; + EntityItem entityitem = new EntityItem(world, (float)te.field_478_b + f, (float)te.field_483_c + f1, (float)te.field_482_d + f2, new ItemStack(itemstack.field_855_c, i1, itemstack.func_21125_h())); + float f3 = 0.05F; + entityitem.field_319_o = (float)world.field_803_m.nextGaussian() * f3; + entityitem.field_318_p = (float)world.field_803_m.nextGaussian() * f3 + 0.2F; + entityitem.field_317_q = (float)world.field_803_m.nextGaussian() * f3; + + if (itemstack.func_40608_n()) + { + entityitem.field_429_a.func_40604_d((NBTTagCompound)itemstack.func_40607_o().func_40468_b()); + } + + world.func_526_a(entityitem); } - world.func_526_a(entityitem); } } - } - /** - * Get a list of all BaseMod loaded into the system - * {@link ModLoaderModContainer#findAll} - * @return - */ - public static List getLoadedMods() { - return ModLoaderModContainer.findAll(); - } + /** + * Get a list of all BaseMod loaded into the system + * {@link ModLoaderModContainer#findAll} + * @return + */ + public static List getLoadedMods() + { + return ModLoaderModContainer.findAll(); + } - /** - * Get a logger instance - * {@link FMLHandler#getFMLLogger()} - * @return - */ - public static Logger getLogger() { - return FMLHandler.getFMLLogger(); - } + /** + * Get a logger instance + * {@link FMLHandler#getFMLLogger()} + * @return + */ + public static Logger getLogger() + { + return FMLHandler.getFMLLogger(); + } - /** - * Get a value from a field using reflection - * {@link ReflectionHelper#getPrivateValue(Class, Object, int)} - * @param instanceclass - * @param instance - * @param fieldindex - * @return - */ - public static T getPrivateValue(Class instanceclass, E instance, int fieldindex) { - return ReflectionHelper.getPrivateValue(instanceclass, instance, fieldindex); - } + /** + * Get a value from a field using reflection + * {@link ReflectionHelper#getPrivateValue(Class, Object, int)} + * @param instanceclass + * @param instance + * @param fieldindex + * @return + */ + public static T getPrivateValue(Class instanceclass, E instance, int fieldindex) + { + return ReflectionHelper.getPrivateValue(instanceclass, instance, fieldindex); + } - /** - * Get a value from a field using reflection - * {@link ReflectionHelper#getPrivateValue(Class, Object, String)} - * @param instanceclass - * @param instance - * @param field - * @return - */ - public static T getPrivateValue(Class instanceclass, E instance, String field) { - return ReflectionHelper.getPrivateValue(instanceclass, instance, field); - } + /** + * Get a value from a field using reflection + * {@link ReflectionHelper#getPrivateValue(Class, Object, String)} + * @param instanceclass + * @param instance + * @param field + * @return + */ + public static T getPrivateValue(Class instanceclass, E instance, String field) + { + return ReflectionHelper.getPrivateValue(instanceclass, instance, field); + } - /** - * Get a new unique entity id - * {@link Entity#getNextId()} - * @return - */ - public static int getUniqueEntityId() { - return Entity.getNextId(); - } + /** + * Get a new unique entity id + * {@link Entity#getNextId()} + * @return + */ + public static int getUniqueEntityId() + { + return Entity.getNextId(); + } - /** - * Is the named mod loaded? - * {@link Loader#isModLoaded(String)} - * @param modname - * @return - */ - public static boolean isModLoaded(String modname) { - return Loader.isModLoaded(modname); - } + /** + * Is the named mod loaded? + * {@link Loader#isModLoaded(String)} + * @param modname + * @return + */ + public static boolean isModLoaded(String modname) + { + return Loader.isModLoaded(modname); + } - /** - * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLHandler#handlePacket250(Packet250CustomPayload, EntityPlayer)} - * @param packet - */ - @Deprecated - public static void receivePacket(Packet250CustomPayload packet) { - } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * {@link FMLHandler#handlePacket250(Packet250CustomPayload, EntityPlayer)} + * @param packet + */ + @Deprecated + public static void receivePacket(Packet250CustomPayload packet) + { + } - /** - * Register a new block - * @param block - */ - public static void registerBlock(Block block) { - CommonRegistry.registerBlock(block); - } + /** + * Register a new block + * @param block + */ + public static void registerBlock(Block block) + { + CommonRegistry.registerBlock(block); + } - /** - * Register a new block - * @param block - * @param itemclass - */ - public static void registerBlock(Block block, Class itemclass) { - CommonRegistry.registerBlock(block, itemclass); - } + /** + * Register a new block + * @param block + * @param itemclass + */ + public static void registerBlock(Block block, Class itemclass) + { + CommonRegistry.registerBlock(block, itemclass); + } - /** - * Register a new entity ID - * @param entityClass - * @param entityName - * @param id - */ - public static void registerEntityID(Class entityClass, String entityName, int id) { - CommonRegistry.registerEntityID(entityClass, entityName, id); - } + /** + * Register a new entity ID + * @param entityClass + * @param entityName + * @param id + */ + public static void registerEntityID(Class entityClass, String entityName, int id) + { + CommonRegistry.registerEntityID(entityClass, entityName, id); + } - /** - * Register a new entity ID - * @param entityClass - * @param entityName - * @param id - * @param background - * @param foreground - */ - public static void registerEntityID(Class entityClass, String entityName, int id, int background, int foreground) { - CommonRegistry.registerEntityID(entityClass, entityName, id, background, foreground); - } + /** + * Register a new entity ID + * @param entityClass + * @param entityName + * @param id + * @param background + * @param foreground + */ + public static void registerEntityID(Class entityClass, String entityName, int id, int background, int foreground) + { + CommonRegistry.registerEntityID(entityClass, entityName, id, background, foreground); + } - /** - * Register the mod for packets on this channel. This only registers the channel with Forge Mod Loader, not - * with clients connecting- use BaseMod.onClientLogin to tell them about your custom channel - * {@link FMLHooks#registerChannel(cpw.mods.fml.common.ModContainer, String)} - * @param mod - * @param channel - */ - public static void registerPacketChannel(BaseMod mod, String channel) { - FMLHooks.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod),channel); - } + /** + * Register the mod for packets on this channel. This only registers the channel with Forge Mod Loader, not + * with clients connecting- use BaseMod.onClientLogin to tell them about your custom channel + * {@link FMLHooks#registerChannel(cpw.mods.fml.common.ModContainer, String)} + * @param mod + * @param channel + */ + public static void registerPacketChannel(BaseMod mod, String channel) + { + FMLHooks.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod), channel); + } - /** - * Register a new tile entity class - * @param tileEntityClass - * @param id - */ - public static void registerTileEntity(Class tileEntityClass, String id) { - CommonRegistry.registerTileEntity(tileEntityClass, id); - } + /** + * Register a new tile entity class + * @param tileEntityClass + * @param id + */ + public static void registerTileEntity(Class tileEntityClass, String id) + { + CommonRegistry.registerTileEntity(tileEntityClass, id); + } - /** - * Remove a biome. This code will probably not work correctly and will likely corrupt worlds. - * @param biome - */ - @Deprecated - public static void removeBiome(BiomeGenBase biome) { - CommonRegistry.removeBiome(biome); - } + /** + * Remove a biome. This code will probably not work correctly and will likely corrupt worlds. + * @param biome + */ + @Deprecated + public static void removeBiome(BiomeGenBase biome) + { + CommonRegistry.removeBiome(biome); + } - /** - * Remove a spawn - * @param entityClass - * @param spawnList - */ - public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityClass, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); - } + /** + * Remove a spawn + * @param entityClass + * @param spawnList + */ + public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) + { + CommonRegistry.removeSpawn(entityClass, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); + } - /** - * Remove a spawn - * @param entityClass - * @param spawnList - * @param biomes - */ - public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.removeSpawn(entityClass, spawnList, biomes); - } + /** + * Remove a spawn + * @param entityClass + * @param spawnList + * @param biomes + */ + public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + CommonRegistry.removeSpawn(entityClass, spawnList, biomes); + } - /** - * Remove a spawn - * @param entityName - * @param spawnList - */ - public static void removeSpawn(String entityName, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityName, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); - } + /** + * Remove a spawn + * @param entityName + * @param spawnList + */ + public static void removeSpawn(String entityName, EnumCreatureType spawnList) + { + CommonRegistry.removeSpawn(entityName, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); + } - /** - * Remove a spawn - * @param entityName - * @param spawnList - * @param biomes - */ - public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { - CommonRegistry.removeSpawn(entityName, spawnList, biomes); - } + /** + * Remove a spawn + * @param entityName + * @param spawnList + * @param biomes + */ + public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + CommonRegistry.removeSpawn(entityName, spawnList, biomes); + } - /** - * Configuration is handled elsewhere - * {@link ModLoaderModContainer} - */ - @Deprecated - public static void saveConfig() { - } + /** + * Configuration is handled elsewhere + * {@link ModLoaderModContainer} + */ + @Deprecated + public static void saveConfig() + { + } - /** - * This method is unimplemented on the server: it is meant for clients to send chat to the server - * {@link FMLHandler#handleChatPacket(Packet3Chat, EntityPlayer)} - * @param text - */ - @Deprecated - public static void serverChat(String text) { - } + /** + * This method is unimplemented on the server: it is meant for clients to send chat to the server + * {@link FMLHandler#handleChatPacket(Packet3Chat, EntityPlayer)} + * @param text + */ + @Deprecated + public static void serverChat(String text) + { + } - /** - * Indicate that you want to receive ticks - * - * @param mod - * receiving the events - * @param enable - * indicates whether you want to recieve them or not - * @param useClock - * Not used in server side: all ticks are sent on the server side (no render subticks) - */ - public static void setInGameHook(BaseMod mod, boolean enable, boolean useClock) { - ModLoaderModContainer mlmc = (ModLoaderModContainer) ModLoaderModContainer.findContainerFor(mod); - mlmc.setTicking(enable); - } + /** + * Indicate that you want to receive ticks + * + * @param mod + * receiving the events + * @param enable + * indicates whether you want to recieve them or not + * @param useClock + * Not used in server side: all ticks are sent on the server side (no render subticks) + */ + public static void setInGameHook(BaseMod mod, boolean enable, boolean useClock) + { + ModLoaderModContainer mlmc = (ModLoaderModContainer) ModLoaderModContainer.findContainerFor(mod); + mlmc.setTicking(enable); + } - /** - * Set a private field to a value using reflection - * {@link ReflectionHelper#setPrivateValue(Class, Object, int, Object)} - * @param instanceclass - * @param instance - * @param fieldindex - * @param value - */ - public static void setPrivateValue(Class instanceclass, T instance, int fieldindex, E value) { - ReflectionHelper.setPrivateValue(instanceclass, instance, fieldindex, value); - } - - /** - * Set a private field to a value using reflection - * {@link ReflectionHelper#setPrivateValue(Class, Object, String, Object)} - * @param instanceclass - * @param instance - * @param field - * @param value - */ - public static void setPrivateValue(Class instanceclass, T instance, String field, E value) { - ReflectionHelper.setPrivateValue(instanceclass, instance, field, value); - } + /** + * Set a private field to a value using reflection + * {@link ReflectionHelper#setPrivateValue(Class, Object, int, Object)} + * @param instanceclass + * @param instance + * @param fieldindex + * @param value + */ + public static void setPrivateValue(Class instanceclass, T instance, int fieldindex, E value) + { + ReflectionHelper.setPrivateValue(instanceclass, instance, fieldindex, value); + } - /** - * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLHandler#onItemCrafted(EntityPlayer, ItemStack, IInventory)} - * @param player - * @param item - * @param matrix - */ - @Deprecated - public static void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) { - } + /** + * Set a private field to a value using reflection + * {@link ReflectionHelper#setPrivateValue(Class, Object, String, Object)} + * @param instanceclass + * @param instance + * @param field + * @param value + */ + public static void setPrivateValue(Class instanceclass, T instance, String field, E value) + { + ReflectionHelper.setPrivateValue(instanceclass, instance, field, value); + } - /** - * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLHandler#onItemSmelted(EntityPlayer, ItemStack)} - * @param player - * @param item - */ - @Deprecated - public static void takenFromFurnace(EntityPlayer player, ItemStack item) { - } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * {@link FMLHandler#onItemCrafted(EntityPlayer, ItemStack, IInventory)} + * @param player + * @param item + * @param matrix + */ + @Deprecated + public static void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) + { + } - /** - * Throw the offered exception. Likely will stop the game. - * {@link FMLHandler#raiseException(Throwable, String, boolean)} - * @param message - * @param e - */ - public static void throwException(String message, Throwable e) { - FMLHandler.instance().raiseException(e, message, true); - } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * {@link FMLHandler#onItemSmelted(EntityPlayer, ItemStack)} + * @param player + * @param item + */ + @Deprecated + public static void takenFromFurnace(EntityPlayer player, ItemStack item) + { + } - /** - * Get the minecraft server instance - * {@link FMLHandler#getServer()} - * @return - */ - public static MinecraftServer getMinecraftServerInstance() { - return FMLHandler.instance().getServer(); - } - - /** - * To properly implement packet 250 protocol you should always check your channel - * is active prior to sending the packet - * - * @param player - * @param channel - * @return - */ - public static boolean isChannelActive(EntityPlayer player, String channel) { - return FMLHooks.instance().isChannelActive(channel,player); - } + /** + * Throw the offered exception. Likely will stop the game. + * {@link FMLHandler#raiseException(Throwable, String, boolean)} + * @param message + * @param e + */ + public static void throwException(String message, Throwable e) + { + FMLHandler.instance().raiseException(e, message, true); + } + + /** + * Get the minecraft server instance + * {@link FMLHandler#getServer()} + * @return + */ + public static MinecraftServer getMinecraftServerInstance() + { + return FMLHandler.instance().getServer(); + } + + /** + * To properly implement packet 250 protocol you should always check your channel + * is active prior to sending the packet + * + * @param player + * @param channel + * @return + */ + public static boolean isChannelActive(EntityPlayer player, String channel) + { + return FMLHooks.instance().isChannelActive(channel, player); + } } \ No newline at end of file