Add in a utility function that *might* tell you the context

you're running in on either client or server: FMLCommonHandler.getEffectiveSide
This commit is contained in:
Christian 2012-08-21 19:15:07 -04:00
parent ba16217fe2
commit d27e722903
1 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,8 @@ import net.minecraft.src.DedicatedServer;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.ServerListenThread;
import net.minecraft.src.ThreadServerApplication;
import net.minecraft.src.World;
import com.google.common.base.Strings;
@ -162,6 +164,23 @@ public class FMLCommonHandler
return sidedDelegate.getSide();
}
/**
* Return the effective side for the context in the game. This is dependent
* on thread analysis to try and determine whether the code is running in the
* server or not. Use at your own risk
*
* @return
*/
public Side getEffectiveSide()
{
Thread thr = Thread.currentThread();
if ((thr instanceof ThreadServerApplication) || (thr instanceof ServerListenThread))
{
return Side.SERVER;
}
return Side.CLIENT;
}
/**
* Raise an exception
*