2012-04-02 18:09:06 -04:00
/*
* The FML Forge Mod Loader suite. Copyright (C) 2012 cpw
2012-04-05 10:07:52 -04:00
*
2012-04-02 18:09:06 -04:00
* 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.
2012-04-05 10:07:52 -04:00
*
2012-04-02 18:09:06 -04:00
* 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.
2012-04-05 10:07:52 -04:00
*
2012-04-02 18:09:06 -04:00
* 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.server ;
2012-06-01 23:07:32 -04:00
import java.util.List ;
2012-04-02 18:09:06 -04:00
import net.minecraft.server.MinecraftServer ;
2012-08-09 08:40:32 -04:00
import net.minecraft.src.Entity ;
2012-09-07 22:46:31 -04:00
import net.minecraft.src.NetClientHandler ;
2012-09-06 10:03:30 -04:00
import net.minecraft.src.NetHandler ;
2012-08-12 22:45:18 -04:00
import net.minecraft.src.Packet ;
2012-09-06 10:03:30 -04:00
import net.minecraft.src.Packet131MapData ;
2012-04-02 18:09:06 -04:00
import net.minecraft.src.World ;
2012-04-05 11:34:57 -04:00
import cpw.mods.fml.common.FMLCommonHandler ;
import cpw.mods.fml.common.IFMLSidedHandler ;
2012-04-03 17:04:26 -04:00
import cpw.mods.fml.common.Loader ;
2012-08-02 02:08:30 -02:30
import cpw.mods.fml.common.ObfuscationReflectionHelper ;
2012-06-02 15:13:55 -04:00
import cpw.mods.fml.common.Side ;
2012-08-09 08:40:32 -04:00
import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket ;
import cpw.mods.fml.common.network.EntitySpawnPacket ;
2012-08-26 22:13:43 -04:00
import cpw.mods.fml.common.network.ModMissingPacket ;
2012-08-22 23:46:16 -04:00
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration ;
2012-08-13 20:28:53 -04:00
import cpw.mods.fml.common.registry.LanguageRegistry ;
2012-04-02 18:09:06 -04:00
2012-04-05 16:22:47 -04:00
/**
* Handles primary communication from hooked code into the system
2012-07-03 22:39:35 -04:00
*
2012-04-19 22:40:59 -04:00
* The FML entry point is {@link #onPreLoad(MinecraftServer)} called from
* {@link MinecraftServer}
2012-07-03 22:39:35 -04:00
*
2012-04-19 22:40:59 -04:00
* Obfuscated code should focus on this class and other members of the "server"
* (or "client") code
2012-07-03 22:39:35 -04:00
*
2012-04-05 16:22:47 -04:00
* The actual mod loading is handled at arms length by {@link Loader}
2012-07-03 22:39:35 -04:00
*
2012-04-19 22:40:59 -04:00
* It is expected that a similar class will exist for each target environment:
* Bukkit and Client side.
2012-07-03 22:39:35 -04:00
*
2012-04-05 16:22:47 -04:00
* It should not be directly modified.
2012-07-03 22:39:35 -04:00
*
2012-04-05 16:22:47 -04:00
* @author cpw
2012-07-03 22:39:35 -04:00
*
2012-04-05 16:22:47 -04:00
*/
2012-04-05 11:34:57 -04:00
public class FMLServerHandler implements IFMLSidedHandler
2012-04-05 10:07:52 -04:00
{
2012-04-05 16:22:47 -04:00
/**
* The singleton
*/
2012-04-05 11:34:57 -04:00
private static final FMLServerHandler INSTANCE = new FMLServerHandler ();
2012-04-05 10:07:52 -04:00
2012-04-05 16:22:47 -04:00
/**
* A reference to the server itself
*/
2012-04-05 10:07:52 -04:00
private MinecraftServer server ;
2012-08-09 09:21:16 -04:00
private FMLServerHandler ()
{
FMLCommonHandler . instance (). beginLoading ( this );
}
2012-04-05 16:22:47 -04:00
/**
2012-04-19 22:40:59 -04:00
* Called to start the whole game off from
* {@link MinecraftServer#startServer}
2012-07-03 22:39:35 -04:00
*
2012-04-05 16:22:47 -04:00
* @param minecraftServer
*/
2012-08-02 02:08:30 -02:30
public void beginServerLoading ( MinecraftServer minecraftServer )
2012-04-05 10:07:52 -04:00
{
server = minecraftServer ;
2012-08-02 02:08:30 -02:30
ObfuscationReflectionHelper . detectObfuscation ( World . class );
2012-04-05 10:07:52 -04:00
Loader . instance (). loadMods ();
}
2012-04-05 16:22:47 -04:00
/**
* Called a bit later on during server initialization to finish loading mods
*/
2012-08-02 02:08:30 -02:30
public void finishServerLoading ()
2012-04-05 10:07:52 -04:00
{
Loader . instance (). initializeMods ();
2012-08-13 20:28:53 -04:00
LanguageRegistry . reloadLanguageTable ();
2012-04-05 10:07:52 -04:00
}
2012-07-03 22:39:35 -04:00
@Override
public void haltGame ( String message , Throwable exception )
{
throw new RuntimeException ( message , exception );
}
2012-04-05 16:22:47 -04:00
/**
* Get the server instance
2012-07-03 22:39:35 -04:00
*
2012-04-05 16:22:47 -04:00
* @return
*/
2012-04-05 10:07:52 -04:00
public MinecraftServer getServer ()
{
return server ;
}
/**
* @return the instance
*/
2012-04-05 11:34:57 -04:00
public static FMLServerHandler instance ()
2012-04-05 10:07:52 -04:00
{
return INSTANCE ;
}
2012-06-01 23:07:32 -04:00
/* (non-Javadoc)
* @see cpw.mods.fml.common.IFMLSidedHandler#getAdditionalBrandingInformation()
*/
@Override
public List < String > getAdditionalBrandingInformation ()
{
return null ;
}
2012-06-02 15:13:55 -04:00
/* (non-Javadoc)
* @see cpw.mods.fml.common.IFMLSidedHandler#getSide()
*/
@Override
public Side getSide ()
{
return Side . SERVER ;
}
2012-08-08 00:31:24 -04:00
@Override
public void showGuiScreen ( Object clientGuiElement )
{
2012-08-11 14:12:39 -04:00
2012-08-08 00:31:24 -04:00
}
2012-08-09 08:40:32 -04:00
@Override
2012-08-22 23:46:16 -04:00
public Entity spawnEntityIntoClientWorld ( EntityRegistration er , EntitySpawnPacket packet )
2012-08-09 08:40:32 -04:00
{
// NOOP
return null ;
}
@Override
public void adjustEntityLocationOnClient ( EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket )
{
// NOOP
}
2012-08-12 22:45:18 -04:00
@Override
public void sendPacket ( Packet packet )
{
throw new RuntimeException ( "You cannot send a bare packet without a target on the server!" );
}
2012-08-26 22:13:43 -04:00
@Override
public void displayMissingMods ( ModMissingPacket modMissingPacket )
{
// NOOP on server
}
2012-09-06 10:03:30 -04:00
@Override
public void handleTinyPacket ( NetHandler handler , Packet131MapData mapData )
{
// NOOP on server
}
2012-09-07 19:32:36 -04:00
@Override
2012-09-07 22:46:31 -04:00
public void setClientCompatibilityLevel ( byte compatibilityLevel )
2012-09-07 19:32:36 -04:00
{
// NOOP on server
}
2012-09-07 22:46:31 -04:00
@Override
public byte getClientCompatibilityLevel ()
{
System . out . printf ( "Server Compatibility %d\n" , 0 );
Thread . dumpStack ();
return 0 ;
}
2012-04-02 18:09:06 -04:00
}