2012-03-30 14:11:13 +00:00
/ *
2016-06-23 03:49:47 +00:00
* Minecraft Forge
2018-07-01 21:17:28 +00:00
* Copyright ( c ) 2016 - 2018 .
2013-03-30 16:12:54 +00:00
*
2016-06-23 03:49:47 +00: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 version 2 . 1
* of the License .
*
* 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
2012-03-30 14:11:13 +00:00
* /
2013-03-08 00:25:48 +00:00
2014-09-23 05:01:24 +00:00
package net.minecraftforge.fml.common ;
2012-04-02 22:09:06 +00:00
2014-04-04 23:47:19 +00:00
import java.io.File ;
import java.lang.ref.WeakReference ;
2018-01-22 00:07:54 +00:00
import java.util.Collection ;
2017-07-13 04:50:28 +00:00
import java.util.Collections ;
2012-05-07 05:39:55 +00:00
import java.util.List ;
2012-10-03 01:54:47 +00:00
import java.util.Map ;
import java.util.Set ;
2014-04-09 20:18:44 +00:00
import java.util.concurrent.CountDownLatch ;
2014-12-14 01:45:38 +00:00
import java.util.concurrent.ExecutionException ;
import java.util.concurrent.FutureTask ;
2014-04-09 20:18:44 +00:00
import java.util.concurrent.TimeUnit ;
2014-04-01 12:30:47 +00:00
2013-12-17 16:24:57 +00:00
import net.minecraft.entity.item.EntityItem ;
2012-12-09 04:21:03 +00:00
import net.minecraft.entity.player.EntityPlayer ;
2013-12-17 16:24:57 +00:00
import net.minecraft.inventory.IInventory ;
import net.minecraft.item.ItemStack ;
2012-12-09 04:21:03 +00:00
import net.minecraft.nbt.NBTBase ;
import net.minecraft.nbt.NBTTagCompound ;
2014-09-23 02:29:40 +00:00
import net.minecraft.network.EnumConnectionState ;
2013-12-31 14:45:26 +00:00
import net.minecraft.network.INetHandler ;
2013-12-06 16:17:40 +00:00
import net.minecraft.network.NetworkManager ;
2014-09-23 02:29:40 +00:00
import net.minecraft.network.handshake.client.C00Handshake ;
2016-03-03 07:23:40 +00:00
import net.minecraft.network.login.server.SPacketDisconnect ;
2013-02-02 15:54:48 +00:00
import net.minecraft.server.MinecraftServer ;
2014-12-14 01:45:38 +00:00
import net.minecraft.util.IThreadListener ;
2016-03-03 07:23:40 +00:00
import net.minecraft.util.text.TextComponentString ;
2012-12-09 04:21:03 +00:00
import net.minecraft.world.World ;
import net.minecraft.world.storage.SaveHandler ;
import net.minecraft.world.storage.WorldInfo ;
2016-01-25 14:39:43 +00:00
import net.minecraftforge.client.model.animation.Animation ;
2015-11-13 07:59:43 +00:00
import net.minecraftforge.common.ForgeVersion ;
import net.minecraftforge.common.MinecraftForge ;
2016-11-29 00:05:41 +00:00
import net.minecraftforge.common.util.CompoundDataFixer ;
2018-06-21 19:37:32 +00:00
import net.minecraftforge.fml.LogicalSide ;
import net.minecraftforge.fml.StartupQuery ;
import net.minecraftforge.fml.WorldPersistenceHooks ;
import net.minecraftforge.fml.BrandingControl ;
2017-06-23 05:33:11 +00:00
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent ;
2018-06-11 01:12:46 +00:00
import net.minecraftforge.eventbus.api.IEventBus ;
2014-09-23 05:01:24 +00:00
import net.minecraftforge.fml.common.gameevent.InputEvent ;
import net.minecraftforge.fml.common.gameevent.PlayerEvent ;
import net.minecraftforge.fml.common.gameevent.TickEvent ;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase ;
2018-08-16 20:03:32 +00:00
import net.minecraftforge.fml.common.network.FMLNetworkEvent ;
2014-09-23 05:01:24 +00:00
import net.minecraftforge.fml.common.network.NetworkRegistry ;
2017-04-07 22:35:58 +00:00
import net.minecraftforge.fml.common.thread.SidedThreadGroup ;
2018-06-15 19:03:35 +00:00
import net.minecraftforge.fml.ModContainer ;
2014-09-23 05:01:24 +00:00
import net.minecraftforge.fml.server.FMLServerHandler ;
2014-04-01 12:30:47 +00:00
2013-12-17 04:18:00 +00:00
import org.apache.logging.log4j.Logger ;
2014-04-01 12:30:47 +00:00
2013-03-30 16:12:54 +00:00
import com.google.common.base.Joiner ;
2012-07-24 01:20:37 +00:00
import com.google.common.collect.ImmutableList ;
import com.google.common.collect.Lists ;
2012-10-03 01:54:47 +00:00
import com.google.common.collect.MapMaker ;
import com.google.common.collect.Maps ;
2014-04-01 12:30:47 +00:00
2012-04-05 20:22:47 +00:00
/ * *
* The main class for non - obfuscated hook handling code
2012-06-26 20:24:50 +00:00
*
* Anything that doesn ' t require obfuscated or client / server specific code should
2012-04-05 20:22:47 +00:00
* go in this handler
2012-06-26 20:24:50 +00:00
*
2012-04-05 20:22:47 +00:00
* It also contains a reference to the sided handler instance that is valid
* allowing for common code to access specific properties from the obfuscated world
* without a direct dependency
2012-06-26 20:24:50 +00:00
*
2012-04-05 20:22:47 +00:00
* @author cpw
*
* /
2012-04-05 15:34:57 +00:00
public class FMLCommonHandler
2012-04-05 14:07:52 +00:00
{
2012-04-05 20:22:47 +00:00
/ * *
* The singleton
* /
2012-04-05 15:34:57 +00:00
private static final FMLCommonHandler INSTANCE = new FMLCommonHandler ( ) ;
2012-04-05 20:22:47 +00:00
/ * *
2012-06-26 20:24:50 +00:00
* The delegate for side specific data and functions
2012-04-05 20:22:47 +00:00
* /
2012-04-05 15:34:57 +00:00
private IFMLSidedHandler sidedDelegate ;
2012-06-26 20:24:50 +00:00
2012-08-21 22:48:12 +00:00
private boolean noForge ;
private List < String > brandings ;
2013-12-06 13:07:09 +00:00
private List < String > brandingsNoMC ;
2017-07-13 04:50:28 +00:00
private Set < SaveHandler > handlerSet = Collections . newSetFromMap ( new MapMaker ( ) . weakKeys ( ) . < SaveHandler , Boolean > makeMap ( ) ) ;
2014-04-04 23:47:19 +00:00
private WeakReference < SaveHandler > handlerToCheck ;
2018-06-11 01:12:46 +00:00
private IEventBus eventBus = MinecraftForge . EVENT_BUS ;
2014-04-09 20:18:44 +00:00
private volatile CountDownLatch exitLatch = null ;
2015-02-03 11:21:27 +00:00
private FMLCommonHandler ( )
{
}
2013-12-17 04:18:00 +00:00
/ * *
* The FML event bus . Subscribe here for FML related events
*
2015-11-24 20:39:18 +00:00
* @Deprecated Use { @link MinecraftForge # EVENT_BUS } they ' re the same thing now
2013-12-17 04:18:00 +00:00
* @return the event bus
* /
2015-11-24 20:39:18 +00:00
@Deprecated
2018-06-11 01:12:46 +00:00
public IEventBus bus ( )
2013-12-17 04:18:00 +00:00
{
return eventBus ;
}
2012-06-29 03:37:30 +00:00
2016-06-13 13:33:26 +00:00
public List < String > beginLoading ( IFMLSidedHandler handler )
2012-04-05 16:36:54 +00:00
{
sidedDelegate = handler ;
2015-11-13 07:59:43 +00:00
MinecraftForge . initialize ( ) ;
// MinecraftForge.registerCrashCallable();
2016-06-13 13:33:26 +00:00
return ImmutableList . < String > of ( ) ;
2012-04-05 15:34:57 +00:00
}
2012-04-05 16:36:54 +00:00
2012-04-05 14:07:52 +00:00
/ * *
* @return the instance
* /
2012-04-05 15:34:57 +00:00
public static FMLCommonHandler instance ( )
2012-04-05 14:07:52 +00:00
{
return INSTANCE ;
2012-03-30 14:11:13 +00:00
}
2012-06-26 20:24:50 +00:00
/ * *
* Find the container that associates with the supplied mod object
* @param mod
* /
public ModContainer findContainerFor ( Object mod )
{
2014-01-01 00:55:41 +00:00
if ( mod instanceof String )
{
return Loader . instance ( ) . getIndexedModList ( ) . get ( mod ) ;
}
else
{
return Loader . instance ( ) . getReversedModObjectList ( ) . get ( mod ) ;
}
2012-06-26 20:24:50 +00:00
}
2012-04-05 20:22:47 +00:00
/ * *
* Get the forge mod loader logging instance ( goes to the forgemodloader log file )
2012-10-25 20:18:42 +00:00
* @return The log instance for the FML log file
2017-06-23 05:33:11 +00:00
*
* @deprecated Not used in FML , Mods use your own logger , see { @link FMLPreInitializationEvent # getModLog ( ) }
2012-04-05 20:22:47 +00:00
* /
2017-06-23 05:33:11 +00:00
@Deprecated
2012-04-05 16:36:54 +00:00
public Logger getFMLLogger ( )
{
2017-06-23 05:33:11 +00:00
return FMLLog . log ;
2012-04-05 15:34:57 +00:00
}
2012-04-05 16:36:54 +00:00
2012-06-02 19:13:55 +00:00
public Side getSide ( )
2012-05-07 04:54:18 +00:00
{
2012-06-02 19:13:55 +00:00
return sidedDelegate . getSide ( ) ;
2012-05-07 04:54:18 +00:00
}
2012-06-26 20:24:50 +00:00
2012-08-21 23:15:07 +00:00
/ * *
* Return the effective side for the context in the game . This is dependent
2012-08-22 13:43:32 +00:00
* on thread analysis to try and determine whether the code is running in the
2012-08-21 23:15:07 +00:00
* server or not . Use at your own risk
* /
public Side getEffectiveSide ( )
{
2017-04-07 22:35:58 +00:00
final ThreadGroup group = Thread . currentThread ( ) . getThreadGroup ( ) ;
return group instanceof SidedThreadGroup ? ( ( SidedThreadGroup ) group ) . getSide ( ) : Side . CLIENT ;
2012-08-21 23:15:07 +00:00
}
2012-05-10 22:54:25 +00:00
/ * *
* Raise an exception
* /
public void raiseException ( Throwable exception , String message , boolean stopGame )
2012-05-07 05:39:55 +00:00
{
2017-06-23 05:33:11 +00:00
FMLLog . log . error ( " Something raised an exception. The message was '{}'. 'stopGame' is {} " , stopGame , exception ) ;
2012-07-04 02:39:35 +00:00
if ( stopGame )
{
getSidedDelegate ( ) . haltGame ( message , exception ) ;
}
2012-05-07 05:39:55 +00:00
}
2012-05-10 22:54:25 +00:00
2012-06-26 20:24:50 +00:00
2013-12-06 13:07:09 +00:00
public List < String > getBrandings ( boolean includeMC )
2012-07-24 01:20:37 +00:00
{
if ( brandings = = null )
{
2018-06-06 15:37:56 +00:00
BrandingControl . computeBranding ( ) ;
2012-05-11 05:45:36 +00:00
}
2013-12-06 13:07:09 +00:00
return includeMC ? ImmutableList . copyOf ( brandings ) : ImmutableList . copyOf ( brandingsNoMC ) ;
2012-05-11 05:45:36 +00:00
}
2012-06-01 02:09:45 +00:00
public IFMLSidedHandler getSidedDelegate ( )
{
return sidedDelegate ;
}
2012-07-06 14:29:17 +00:00
public void onPostServerTick ( )
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . ServerTickEvent ( Phase . END ) ) ;
2012-07-06 14:29:17 +00:00
}
/ * *
* Every tick just after world and other ticks occur
* /
2013-12-17 04:18:00 +00:00
public void onPostWorldTick ( World world )
2012-07-06 14:29:17 +00:00
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . WorldTickEvent ( Side . SERVER , Phase . END , world ) ) ;
2012-07-06 14:29:17 +00:00
}
public void onPreServerTick ( )
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . ServerTickEvent ( Phase . START ) ) ;
2012-07-06 14:29:17 +00:00
}
/ * *
* Every tick just before world and other ticks occur
* /
2013-12-17 04:18:00 +00:00
public void onPreWorldTick ( World world )
2012-07-06 14:29:17 +00:00
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . WorldTickEvent ( Side . SERVER , Phase . START , world ) ) ;
2012-07-06 02:31:46 +00:00
}
2012-08-06 13:52:42 +00:00
2013-01-22 14:11:44 +00:00
public boolean handleServerAboutToStart ( MinecraftServer server )
2012-08-02 04:38:30 +00:00
{
2013-01-22 14:11:44 +00:00
return Loader . instance ( ) . serverAboutToStart ( server ) ;
}
public boolean handleServerStarting ( MinecraftServer server )
{
return Loader . instance ( ) . serverStarting ( server ) ;
2012-08-02 04:38:30 +00:00
}
2012-08-06 13:52:42 +00:00
2012-08-02 04:38:30 +00:00
public void handleServerStarted ( )
{
Loader . instance ( ) . serverStarted ( ) ;
2014-07-31 12:47:11 +00:00
sidedDelegate . allowLogins ( ) ;
2012-08-02 04:38:30 +00:00
}
2012-08-06 13:52:42 +00:00
2012-08-02 04:38:30 +00:00
public void handleServerStopping ( )
{
Loader . instance ( ) . serverStopping ( ) ;
}
2012-08-02 19:20:30 +00:00
2014-04-04 23:47:19 +00:00
public File getSavesDirectory ( ) {
return sidedDelegate . getSavesDirectory ( ) ;
2014-04-01 19:56:53 +00:00
}
2012-08-02 19:20:30 +00:00
public MinecraftServer getMinecraftServerInstance ( )
{
2012-08-11 15:01:18 +00:00
return sidedDelegate . getServer ( ) ;
2012-08-02 19:20:30 +00:00
}
2012-08-08 04:31:24 +00:00
public void showGuiScreen ( Object clientGuiElement )
{
sidedDelegate . showGuiScreen ( clientGuiElement ) ;
}
2012-08-09 05:58:14 +00:00
2014-04-01 12:30:47 +00:00
public void queryUser ( StartupQuery query ) throws InterruptedException
{
sidedDelegate . queryUser ( query ) ;
}
2013-12-03 04:46:42 +00:00
public void onServerStart ( MinecraftServer dedicatedServer )
2012-08-09 13:21:16 +00:00
{
2012-08-17 13:16:08 +00:00
FMLServerHandler . instance ( ) ;
2012-08-09 13:21:16 +00:00
sidedDelegate . beginServerLoading ( dedicatedServer ) ;
}
2012-08-10 20:37:06 +00:00
2012-08-09 13:21:16 +00:00
public void onServerStarted ( )
{
sidedDelegate . finishServerLoading ( ) ;
}
2012-08-10 20:37:06 +00:00
public void onPreClientTick ( )
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . ClientTickEvent ( Phase . START ) ) ;
2012-08-10 20:37:06 +00:00
}
public void onPostClientTick ( )
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . ClientTickEvent ( Phase . END ) ) ;
2012-08-10 20:37:06 +00:00
}
public void onRenderTickStart ( float timer )
{
2016-01-25 14:39:43 +00:00
Animation . setClientPartialTickTime ( timer ) ;
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . RenderTickEvent ( Phase . START , timer ) ) ;
2012-08-10 20:37:06 +00:00
}
public void onRenderTickEnd ( float timer )
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . RenderTickEvent ( Phase . END , timer ) ) ;
2012-08-10 20:37:06 +00:00
}
2012-08-10 21:11:01 +00:00
public void onPlayerPreTick ( EntityPlayer player )
{
2013-12-17 04:18:00 +00:00
bus ( ) . post ( new TickEvent . PlayerTickEvent ( Phase . START , player ) ) ;
2012-08-10 21:11:01 +00:00
}
public void onPlayerPostTick ( EntityPlayer player )
{
2013-12-18 13:34:20 +00:00
bus ( ) . post ( new TickEvent . PlayerTickEvent ( Phase . END , player ) ) ;
2012-08-10 21:11:01 +00:00
}
2012-08-21 22:48:12 +00:00
2012-10-03 01:54:47 +00:00
public void handleWorldDataSave ( SaveHandler handler , WorldInfo worldInfo , NBTTagCompound tagCompound )
{
for ( ModContainer mc : Loader . instance ( ) . getModList ( ) )
{
if ( mc instanceof InjectedModContainer )
{
2018-06-21 19:37:32 +00:00
WorldPersistenceHooks . WorldPersistenceHook wac = ( ( InjectedModContainer ) mc ) . getWrappedWorldAccessContainer ( ) ;
2012-10-03 01:54:47 +00:00
if ( wac ! = null )
{
NBTTagCompound dataForWriting = wac . getDataForWriting ( handler , worldInfo ) ;
2014-03-19 07:15:53 +00:00
tagCompound . setTag ( mc . getModId ( ) , dataForWriting ) ;
2012-10-03 01:54:47 +00:00
}
}
}
}
public void handleWorldDataLoad ( SaveHandler handler , WorldInfo worldInfo , NBTTagCompound tagCompound )
{
2018-06-21 19:37:32 +00:00
if ( getEffectiveSide ( ) ! = LogicalSide . SERVER )
2012-10-03 01:54:47 +00:00
{
return ;
}
if ( handlerSet . contains ( handler ) )
{
return ;
}
handlerSet . add ( handler ) ;
2014-04-04 23:47:19 +00:00
handlerToCheck = new WeakReference < SaveHandler > ( handler ) ; // for confirmBackupLevelDatUse
2012-10-03 01:54:47 +00:00
Map < String , NBTBase > additionalProperties = Maps . newHashMap ( ) ;
2014-01-19 03:25:35 +00:00
worldInfo . setAdditionalProperties ( additionalProperties ) ;
2012-10-03 01:54:47 +00:00
for ( ModContainer mc : Loader . instance ( ) . getModList ( ) )
{
if ( mc instanceof InjectedModContainer )
{
2018-06-21 19:37:32 +00:00
WorldPersistenceHooks . WorldPersistenceHook wac = ( ( InjectedModContainer ) mc ) . getWrappedWorldAccessContainer ( ) ;
2012-10-03 01:54:47 +00:00
if ( wac ! = null )
{
2014-04-01 12:30:47 +00:00
wac . readData ( handler , worldInfo , additionalProperties , tagCompound . getCompoundTag ( mc . getModId ( ) ) ) ;
2012-10-03 01:54:47 +00:00
}
}
}
}
2012-12-07 06:52:16 +00:00
2014-04-04 23:47:19 +00:00
public void confirmBackupLevelDatUse ( SaveHandler handler )
2014-04-01 19:56:53 +00:00
{
2014-04-04 23:47:19 +00:00
if ( handlerToCheck = = null | | handlerToCheck . get ( ) ! = handler ) {
// only run if the save has been initially loaded
handlerToCheck = null ;
return ;
2014-04-01 19:56:53 +00:00
}
String text = " Forge Mod Loader detected that the backup level.dat is being used. \ n \ n " +
" This may happen due to a bug or corruption, continuing can damage \ n " +
" your world beyond repair or lose data / progress. \ n \ n " +
" It's recommended to create a world backup before continuing. " ;
boolean confirmed = StartupQuery . confirm ( text ) ;
if ( ! confirmed ) StartupQuery . abort ( ) ;
}
2017-05-02 00:14:55 +00:00
public boolean isDisplayCloseRequested ( )
{
return sidedDelegate ! = null & & sidedDelegate . isDisplayCloseRequested ( ) ;
}
2012-12-07 06:52:16 +00:00
public boolean shouldServerBeKilledQuietly ( )
{
2013-01-27 20:54:36 +00:00
if ( sidedDelegate = = null )
{
return false ;
}
2012-12-07 06:52:16 +00:00
return sidedDelegate . shouldServerShouldBeKilledQuietly ( ) ;
}
2014-04-09 20:18:44 +00:00
/ * *
* Make handleExit ( ) wait for handleServerStopped ( ) .
*
* For internal use only !
* /
public void expectServerStopped ( )
{
exitLatch = new CountDownLatch ( 1 ) ;
}
/ * *
* Delayed System . exit ( ) until the server is actually stopped / done saving .
*
* For internal use only !
*
* @param retVal Exit code for System . exit ( )
* /
public void handleExit ( int retVal )
{
CountDownLatch latch = exitLatch ;
if ( latch ! = null )
{
try
{
2017-06-23 05:33:11 +00:00
FMLLog . log . info ( " Waiting for the server to terminate/save. " ) ;
2014-04-09 20:18:44 +00:00
if ( ! latch . await ( 10 , TimeUnit . SECONDS ) )
{
2017-06-23 05:33:11 +00:00
FMLLog . log . warn ( " The server didn't stop within 10 seconds, exiting anyway. " ) ;
2014-04-09 20:18:44 +00:00
}
else
{
2017-06-23 05:33:11 +00:00
FMLLog . log . info ( " Server terminated. " ) ;
2014-04-09 20:18:44 +00:00
}
}
catch ( InterruptedException e )
{
2017-06-23 05:33:11 +00:00
FMLLog . log . warn ( " Interrupted wait, exiting. " ) ;
2014-04-09 20:18:44 +00:00
}
}
System . exit ( retVal ) ;
}
2012-12-31 04:52:38 +00:00
public void handleServerStopped ( )
{
2013-09-20 21:02:56 +00:00
sidedDelegate . serverStopped ( ) ;
2013-06-11 18:41:19 +00:00
MinecraftServer server = getMinecraftServerInstance ( ) ;
2012-12-31 04:52:38 +00:00
Loader . instance ( ) . serverStopped ( ) ;
2013-06-11 18:41:19 +00:00
// FORCE the internal server to stop: hello optifine workaround!
2013-09-20 21:02:56 +00:00
if ( server ! = null ) ObfuscationReflectionHelper . setPrivateValue ( MinecraftServer . class , server , false , " field_71316 " + " _v " , " u " , " serverStopped " ) ;
2014-04-09 20:18:44 +00:00
// allow any pending exit to continue, clear exitLatch
CountDownLatch latch = exitLatch ;
if ( latch ! = null )
{
latch . countDown ( ) ;
exitLatch = null ;
}
2012-12-31 04:52:38 +00:00
}
2013-03-30 16:12:54 +00:00
public String getModName ( )
{
List < String > modNames = Lists . newArrayListWithExpectedSize ( 3 ) ;
modNames . add ( " fml " ) ;
if ( ! noForge )
{
2016-12-17 21:23:39 +00:00
modNames . add ( ForgeVersion . MOD_ID ) ;
2013-03-30 16:12:54 +00:00
}
if ( Loader . instance ( ) . getFMLBrandingProperties ( ) . containsKey ( " snooperbranding " ) )
{
modNames . add ( Loader . instance ( ) . getFMLBrandingProperties ( ) . get ( " snooperbranding " ) ) ;
}
return Joiner . on ( ',' ) . join ( modNames ) ;
}
2013-07-02 05:39:40 +00:00
public void addModToResourcePack ( ModContainer container )
{
sidedDelegate . addModAsResource ( container ) ;
}
2013-07-10 04:42:40 +00:00
2013-09-14 00:04:25 +00:00
public String getCurrentLanguage ( )
{
2013-09-20 21:02:56 +00:00
2013-09-14 00:04:25 +00:00
return sidedDelegate . getCurrentLanguage ( ) ;
}
2013-12-03 04:46:42 +00:00
public void bootstrap ( )
{
}
2013-12-06 16:17:40 +00:00
public NetworkManager getClientToServerNetworkManager ( )
{
return sidedDelegate . getClientToServerNetworkManager ( ) ;
}
2013-12-17 04:18:00 +00:00
public void fireMouseInput ( )
{
bus ( ) . post ( new InputEvent . MouseInputEvent ( ) ) ;
}
public void fireKeyInput ( )
{
bus ( ) . post ( new InputEvent . KeyInputEvent ( ) ) ;
}
public void firePlayerChangedDimensionEvent ( EntityPlayer player , int fromDim , int toDim )
{
bus ( ) . post ( new PlayerEvent . PlayerChangedDimensionEvent ( player , fromDim , toDim ) ) ;
}
public void firePlayerLoggedIn ( EntityPlayer player )
{
bus ( ) . post ( new PlayerEvent . PlayerLoggedInEvent ( player ) ) ;
}
public void firePlayerLoggedOut ( EntityPlayer player )
{
bus ( ) . post ( new PlayerEvent . PlayerLoggedOutEvent ( player ) ) ;
}
2016-11-28 04:58:19 +00:00
public void firePlayerRespawnEvent ( EntityPlayer player , boolean endConquered )
2013-12-17 04:18:00 +00:00
{
2016-11-28 04:58:19 +00:00
bus ( ) . post ( new PlayerEvent . PlayerRespawnEvent ( player , endConquered ) ) ;
2013-12-17 04:18:00 +00:00
}
2013-12-17 16:24:57 +00:00
2017-12-01 05:46:54 +00:00
public void firePlayerItemPickupEvent ( EntityPlayer player , EntityItem item , ItemStack clone )
2013-12-17 16:24:57 +00:00
{
2017-12-01 05:46:54 +00:00
bus ( ) . post ( new PlayerEvent . ItemPickupEvent ( player , item , clone ) ) ;
2013-12-17 16:24:57 +00:00
}
public void firePlayerCraftingEvent ( EntityPlayer player , ItemStack crafted , IInventory craftMatrix )
{
bus ( ) . post ( new PlayerEvent . ItemCraftedEvent ( player , crafted , craftMatrix ) ) ;
}
public void firePlayerSmeltedEvent ( EntityPlayer player , ItemStack smelted )
{
bus ( ) . post ( new PlayerEvent . ItemSmeltedEvent ( player , smelted ) ) ;
}
2013-12-31 14:45:26 +00:00
public INetHandler getClientPlayHandler ( )
{
return sidedDelegate . getClientPlayHandler ( ) ;
}
2014-01-16 19:58:28 +00:00
2014-01-17 00:45:42 +00:00
public void fireNetRegistrationEvent ( NetworkManager manager , Set < String > channelSet , String channel , Side side )
{
sidedDelegate . fireNetRegistrationEvent ( bus ( ) , manager , channelSet , channel , side ) ;
}
2014-02-08 17:18:34 +00:00
2014-03-11 07:50:55 +00:00
public boolean shouldAllowPlayerLogins ( )
{
return sidedDelegate . shouldAllowPlayerLogins ( ) ;
}
2014-08-15 20:16:07 +00:00
2018-08-16 20:03:32 +00:00
public void fireServerConnectionEvent ( NetworkManager manager )
{
bus ( ) . post ( new FMLNetworkEvent . ServerConnectionFromClientEvent ( manager ) ) ;
}
2014-09-23 02:29:40 +00:00
/ * *
* Process initial Handshake packet , kicks players from the server if they are connecting while we are starting up .
* Also verifies the client has the FML marker .
*
* @param packet Handshake Packet
2018-06-23 02:45:01 +00:00
* @param manager NetworkDirection connection
2014-09-23 02:29:40 +00:00
* @return True to allow connection , otherwise False .
* /
public boolean handleServerHandshake ( C00Handshake packet , NetworkManager manager )
{
if ( ! shouldAllowPlayerLogins ( ) )
{
2016-03-01 12:58:03 +00:00
TextComponentString text = new TextComponentString ( " Server is still starting! Please wait before reconnecting. " ) ;
2018-06-21 19:37:32 +00:00
LOGGER . info ( " Disconnecting Player: {} " , text . getUnformattedText ( ) ) ;
2016-03-03 07:23:40 +00:00
manager . sendPacket ( new SPacketDisconnect ( text ) ) ;
2014-09-23 02:29:40 +00:00
manager . closeChannel ( text ) ;
return false ;
}
2014-09-30 09:20:56 +00:00
if ( packet . getRequestedState ( ) = = EnumConnectionState . LOGIN & & ( ! NetworkRegistry . INSTANCE . isVanillaAccepted ( Side . CLIENT ) & & ! packet . hasFMLMarker ( ) ) )
2014-09-23 02:29:40 +00:00
{
manager . setConnectionState ( EnumConnectionState . LOGIN ) ;
2018-01-22 00:07:54 +00:00
TextComponentString text = new TextComponentString ( " This server has mods that require FML/Forge to be installed on the client. Contact your server admin for more details. " ) ;
Collection < String > modNames = NetworkRegistry . INSTANCE . getRequiredMods ( Side . CLIENT ) ;
FMLLog . log . info ( " Disconnecting Player: This server has mods that require FML/Forge to be installed on the client: {} " , modNames ) ;
2016-03-03 07:23:40 +00:00
manager . sendPacket ( new SPacketDisconnect ( text ) ) ;
2014-09-23 02:29:40 +00:00
manager . closeChannel ( text ) ;
return false ;
}
2018-06-22 04:43:25 +00:00
manager . channel ( ) . attr ( net . minecraftforge . fml . network . NetworkRegistry . FML_MARKER ) . set ( packet . hasFMLMarker ( ) ) ;
2014-09-23 02:29:40 +00:00
return true ;
}
2015-04-21 01:42:59 +00:00
public void processWindowMessages ( )
{
2015-04-24 21:11:49 +00:00
if ( sidedDelegate = = null ) return ;
2015-04-21 01:42:59 +00:00
sidedDelegate . processWindowMessages ( ) ;
}
2014-08-15 20:16:07 +00:00
/ * *
* Used to exit from java , with system exit preventions in place . Will be tidy about it and just log a message ,
* unless debugging is enabled
*
* @param exitCode The exit code
2014-08-16 14:32:00 +00:00
* @param hardExit Perform a halt instead of an exit ( only use when the world is unsavable ) - read the warnings at { @link Runtime # halt ( int ) }
2014-08-15 20:16:07 +00:00
* /
public void exitJava ( int exitCode , boolean hardExit )
{
2018-04-01 07:25:38 +00:00
FMLLog . log . warn ( " Java has been asked to exit (code {}) " , exitCode ) ;
2014-08-15 20:16:07 +00:00
if ( hardExit )
{
2018-04-01 07:25:38 +00:00
FMLLog . log . warn ( " This is an abortive exit and could cause world corruption or other things " ) ;
2014-08-15 20:16:07 +00:00
}
2018-04-01 07:25:38 +00:00
StackTraceElement [ ] stack = Thread . currentThread ( ) . getStackTrace ( ) ;
FMLLog . log . warn ( " Exit trace: " ) ;
//The first 2 elements are Thread#getStackTrace and FMLCommonHandler#exitJava and aren't relevant
for ( int i = 2 ; i < stack . length ; i + + )
2014-08-15 20:16:07 +00:00
{
2018-04-01 07:25:38 +00:00
FMLLog . log . warn ( " \ t{} " , stack [ i ] ) ;
2014-08-15 20:16:07 +00:00
}
if ( hardExit )
{
Runtime . getRuntime ( ) . halt ( exitCode ) ;
}
else
{
2014-08-16 14:32:00 +00:00
Runtime . getRuntime ( ) . exit ( exitCode ) ;
2014-08-15 20:16:07 +00:00
}
}
2014-12-14 01:45:38 +00:00
public IThreadListener getWorldThread ( INetHandler net )
{
return sidedDelegate . getWorldThread ( net ) ;
}
2015-11-27 03:38:21 +00:00
public static void callFuture ( FutureTask < ? > task )
2014-12-14 01:45:38 +00:00
{
try
{
task . run ( ) ;
task . get ( ) ; // Forces the exception to be thrown if any
}
2017-06-28 05:56:54 +00:00
catch ( InterruptedException | ExecutionException e )
2014-12-14 01:45:38 +00:00
{
2017-06-23 05:33:11 +00:00
FMLLog . log . fatal ( " Exception caught executing FutureTask: {} " , e . toString ( ) , e ) ;
2014-12-14 01:45:38 +00:00
}
}
2015-02-05 01:23:41 +00:00
2015-05-17 14:11:41 +00:00
public String stripSpecialChars ( String message )
{
return sidedDelegate ! = null ? sidedDelegate . stripSpecialChars ( message ) : message ;
}
2016-07-30 17:31:46 +00:00
public void reloadRenderers ( ) {
sidedDelegate . reloadRenderers ( ) ;
}
2016-09-18 01:08:42 +00:00
public void fireSidedRegistryEvents ( )
{
sidedDelegate . fireSidedRegistryEvents ( ) ;
}
2016-11-29 00:05:41 +00:00
public CompoundDataFixer getDataFixer ( )
{
return ( CompoundDataFixer ) sidedDelegate . getDataFixer ( ) ;
}
2017-03-06 22:31:26 +00:00
public boolean isDisplayVSyncForced ( ) { return sidedDelegate . isDisplayVSyncForced ( ) ; }
2017-06-24 22:34:09 +00:00
public void resetClientRecipeBook ( ) {
this . sidedDelegate . resetClientRecipeBook ( ) ;
}
2017-06-27 23:28:08 +00:00
public void reloadSearchTrees ( ) {
this . sidedDelegate . reloadSearchTrees ( ) ;
}
2018-08-16 20:17:27 +00:00
public void reloadCreativeSettings ( )
{
this . sidedDelegate . reloadCreativeSettings ( ) ;
}
2012-03-30 14:11:13 +00:00
}