Reorganize the code a little bit- move some stuff that was on FMLHandler to the common handler. Add a delegate

into the common handler that delegates to the right sided handler
This commit is contained in:
Christian Weeks committed 2012-04-05 11:34:57 -04:00
1 parent 86f8bbd47d
commit 7bf22659e7
18 files changed
+235 -183

No files matched your search

@@ -30,13 +30,14 @@ import net.minecraft.src.Packet1Login;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.Packet3Chat;
import net.minecraft.src.World;
import cpw.mods.fml.common.FMLHooks;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IFMLSidedHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
public class FMLHandler
public class FMLServerHandler implements IFMLSidedHandler
{
private static final FMLHandler INSTANCE = new FMLHandler();
private static final FMLServerHandler INSTANCE = new FMLServerHandler();
private MinecraftServer server;
@@ -55,12 +56,12 @@ public class FMLHandler
public void onPreTick()
{
FMLHooks.instance().gameTickStart();
FMLCommonHandler.instance().gameTickStart();
}
public void onPostTick()
{
FMLHooks.instance().gameTickEnd();
FMLCommonHandler.instance().gameTickEnd();
}
public MinecraftServer getServer()
@@ -68,7 +69,7 @@ public class FMLHandler
return server;
}
public static Logger getMinecraftLogger()
public Logger getMinecraftLogger()
{
return MinecraftServer.field_6038_a;
}
@@ -124,14 +125,9 @@ public class FMLHandler
}
}
public static Logger getFMLLogger()
{
return Loader.log;
}
public void raiseException(Throwable exception, String message, boolean stopGame)
{
getFMLLogger().throwing("FMLHandler", "raiseException", exception);
FMLCommonHandler.instance().getFMLLogger().throwing("FMLHandler", "raiseException", exception);
throw new RuntimeException(exception);
}
@@ -161,7 +157,7 @@ public class FMLHandler
/**
* @return the instance
*/
public static FMLHandler instance()
public static FMLServerHandler instance()
{
return INSTANCE;
}
@@ -235,7 +231,7 @@ public class FMLHandler
return;
}
ModContainer mod = FMLHooks.instance().getModForChannel(packet.field_44005_a);
ModContainer mod = FMLCommonHandler.instance().getModForChannel(packet.field_44005_a);
if (mod != null)
{
@@ -253,18 +249,18 @@ public class FMLHandler
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)
if (FMLCommonHandler.instance().getModForChannel(channel) == null)
{
continue;
}
if ("REGISTER".equals(packet.field_44005_a))
{
FMLHooks.instance().activateChannel(player, channel);
FMLCommonHandler.instance().activateChannel(player, channel);
}
else
{
FMLHooks.instance().deactivateChannel(player, channel);
FMLCommonHandler.instance().deactivateChannel(player, channel);
}
}
}
@@ -286,8 +282,20 @@ public class FMLHandler
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.field_44005_a = "REGISTER";
packet.field_44004_c = FMLHooks.instance().getPacketRegistry();
packet.field_44004_c = FMLCommonHandler.instance().getPacketRegistry();
packet.field_44003_b = packet.field_44004_c.length;
networkManager.func_745_a(packet);
}
@Override
public boolean isServer()
{
return true;
}
@Override
public boolean isClient()
{
return false;
}
}
@@ -26,7 +26,7 @@ import java.util.StringTokenizer;
import net.minecraft.src.BaseMod;
import net.minecraft.src.MLProp;
import cpw.mods.fml.common.FMLHooks;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ICraftingHandler;
import cpw.mods.fml.common.IDispenseHandler;
import cpw.mods.fml.common.INetworkHandler;
@@ -271,7 +271,7 @@ public class ModLoaderModContainer implements ModContainer
{
if (isTicking)
{
isTicking = mod.onTickInGame(FMLHandler.instance().getServer());
isTicking = mod.onTickInGame(FMLServerHandler.instance().getServer());
}
}
@Override
@@ -498,6 +498,6 @@ public class ModLoaderModContainer implements ModContainer
@Override
public boolean ownsNetworkChannel(String channel)
{
return FMLHooks.instance().getChannelListFor(this).contains(channel);
return FMLCommonHandler.instance().getChannelListFor(this).contains(channel);
}
}
+21 -21
View File
@@ -16,10 +16,10 @@ import java.util.List;
import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
import cpw.mods.fml.common.FMLHooks;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ReflectionHelper;
import cpw.mods.fml.server.FMLHandler;
import cpw.mods.fml.server.FMLServerHandler;
import cpw.mods.fml.server.ModLoaderModContainer;
public class ModLoader
@@ -38,7 +38,7 @@ public class ModLoader
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
*
* {@link FMLHandler#fuelLookup(int, int)}
* {@link FMLServerHandler#fuelLookup(int, int)}
* @param id
* @param metadata
* @return
@@ -176,7 +176,7 @@ public class ModLoader
*/
public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList)
{
CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes());
}
/**
@@ -203,7 +203,7 @@ public class ModLoader
*/
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList)
{
CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes());
}
/**
@@ -222,7 +222,7 @@ public class ModLoader
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLHandler#tryDispensingEntity(World, double, double, double, byte, byte, ItemStack)}
* {@link FMLServerHandler#tryDispensingEntity(World, double, double, double, byte, byte, ItemStack)}
* @param world
* @param x
* @param y
@@ -307,12 +307,12 @@ public class ModLoader
/**
* Get a logger instance
* {@link FMLHandler#getFMLLogger()}
* {@link FMLServerHandler#getFMLLogger()}
* @return
*/
public static Logger getLogger()
{
return FMLHandler.getFMLLogger();
return FMLCommonHandler.instance().getFMLLogger();
}
/**
@@ -364,7 +364,7 @@ public class ModLoader
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLHandler#handlePacket250(Packet250CustomPayload, EntityPlayer)}
* {@link FMLServerHandler#handlePacket250(Packet250CustomPayload, EntityPlayer)}
* @param packet
*/
@Deprecated
@@ -418,13 +418,13 @@ public class ModLoader
/**
* 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)}
* {@link FMLCommonHandler#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);
FMLCommonHandler.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod), channel);
}
/**
@@ -454,7 +454,7 @@ public class ModLoader
*/
public static void removeSpawn(Class <? extends EntityLiving > entityClass, EnumCreatureType spawnList)
{
CommonRegistry.removeSpawn(entityClass, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
CommonRegistry.removeSpawn(entityClass, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes());
}
/**
@@ -475,7 +475,7 @@ public class ModLoader
*/
public static void removeSpawn(String entityName, EnumCreatureType spawnList)
{
CommonRegistry.removeSpawn(entityName, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
CommonRegistry.removeSpawn(entityName, spawnList, FMLServerHandler.instance().getDefaultOverworldBiomes());
}
/**
@@ -500,7 +500,7 @@ public class ModLoader
/**
* This method is unimplemented on the server: it is meant for clients to send chat to the server
* {@link FMLHandler#handleChatPacket(Packet3Chat, EntityPlayer)}
* {@link FMLServerHandler#handleChatPacket(Packet3Chat, EntityPlayer)}
* @param text
*/
@Deprecated
@@ -552,7 +552,7 @@ public class ModLoader
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLHandler#onItemCrafted(EntityPlayer, ItemStack, IInventory)}
* {@link FMLServerHandler#onItemCrafted(EntityPlayer, ItemStack, IInventory)}
* @param player
* @param item
* @param matrix
@@ -564,7 +564,7 @@ public class ModLoader
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLHandler#onItemSmelted(EntityPlayer, ItemStack)}
* {@link FMLServerHandler#onItemSmelted(EntityPlayer, ItemStack)}
* @param player
* @param item
*/
@@ -575,23 +575,23 @@ public class ModLoader
/**
* Throw the offered exception. Likely will stop the game.
* {@link FMLHandler#raiseException(Throwable, String, boolean)}
* {@link FMLServerHandler#raiseException(Throwable, String, boolean)}
* @param message
* @param e
*/
public static void throwException(String message, Throwable e)
{
FMLHandler.instance().raiseException(e, message, true);
FMLServerHandler.instance().raiseException(e, message, true);
}
/**
* Get the minecraft server instance
* {@link FMLHandler#getServer()}
* {@link FMLServerHandler#getServer()}
* @return
*/
public static MinecraftServer getMinecraftServerInstance()
{
return FMLHandler.instance().getServer();
return FMLServerHandler.instance().getServer();
}
/**
@@ -604,6 +604,6 @@ public class ModLoader
*/
public static boolean isChannelActive(EntityPlayer player, String channel)
{
return FMLHooks.instance().isChannelActive(channel, player);
return FMLCommonHandler.instance().isChannelActive(channel, player);
}
}