2018-06-21 19:37:32 +00:00
/ *
* Minecraft Forge
2018-09-21 09:15:03 +00:00
* Copyright ( c ) 2016 - 2018 .
2018-06-21 19:37:32 +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
* /
package net.minecraftforge.common ;
2018-12-22 00:07:39 +00:00
import net.minecraftforge.fml.FMLWorldPersistenceHook ;
2018-06-21 19:37:32 +00:00
import net.minecraftforge.fml.VersionChecker ;
import net.minecraftforge.fml.WorldPersistenceHooks ;
2019-01-15 03:32:43 +00:00
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent ;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent ;
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent ;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent ;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent ;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent ;
2018-08-27 17:10:07 +00:00
import net.minecraftforge.fml.javafmlmod.FMLModLoadingContext ;
2019-02-05 02:23:58 +00:00
import net.minecraftforge.fml.loading.FMLPaths ;
2018-09-05 00:23:45 +00:00
import net.minecraftforge.server.command.ForgeCommand ;
2018-10-04 23:28:45 +00:00
import net.minecraftforge.versions.forge.ForgeVersion ;
2019-01-02 02:35:23 +00:00
import net.minecraftforge.versions.mcp.MCPVersion ;
2019-02-05 02:23:58 +00:00
import java.nio.file.Path ;
2018-06-21 19:37:32 +00:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
import net.minecraft.nbt.NBTTagCompound ;
import net.minecraft.world.storage.SaveHandler ;
import net.minecraft.world.storage.WorldInfo ;
import net.minecraftforge.common.model.animation.CapabilityAnimation ;
import net.minecraftforge.energy.CapabilityEnergy ;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler ;
import net.minecraftforge.items.CapabilityItemHandler ;
import net.minecraftforge.fluids.UniversalBucket ;
2018-12-22 00:07:39 +00:00
import net.minecraftforge.fml.common.Mod ;
2018-06-21 19:37:32 +00:00
import net.minecraftforge.fml.common.gameevent.PlayerEvent ;
2018-06-22 04:43:25 +00:00
import org.apache.logging.log4j.Marker ;
import org.apache.logging.log4j.MarkerManager ;
2018-06-21 19:37:32 +00:00
2019-02-05 02:23:58 +00:00
import com.electronwill.nightconfig.core.file.CommentedFileConfig ;
import com.electronwill.nightconfig.core.io.WritingMode ;
2018-12-22 00:07:39 +00:00
@Mod ( " forge " )
2018-06-21 19:37:32 +00:00
public class ForgeMod implements WorldPersistenceHooks . WorldPersistenceHook
{
public static final String VERSION_CHECK_CAT = " version_checking " ;
2018-08-27 17:10:07 +00:00
private static final Logger LOGGER = LogManager . getLogger ( ) ;
2018-06-22 04:43:25 +00:00
private static final Marker FORGEMOD = MarkerManager . getMarker ( " FORGEMOD " ) ;
2018-06-21 19:37:32 +00:00
public static int [ ] blendRanges = { 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34 } ;
public static boolean disableVersionCheck = false ;
public static boolean forgeLightPipelineEnabled = true ;
public static boolean zoomInMissingModelTextInGui = false ;
public static boolean disableStairSlabCulling = false ; // Also known as the "DontCullStairsBecauseIUseACrappyTexturePackThatBreaksBasicBlockShapesSoICantTrustBasicBlockCulling" flag
public static boolean alwaysSetupTerrainOffThread = false ; // In RenderGlobal.setupTerrain, always force the chunk render updates to be queued to the thread
public static boolean logCascadingWorldGeneration = true ; // see Chunk#logCascadingWorldGeneration()
public static boolean fixVanillaCascading = false ; // There are various places in vanilla that cause cascading worldgen. Enabling this WILL change where blocks are placed to prevent this.
// DO NOT contact Forge about worldgen not 'matching' vanilla if this flag is set.
private static ForgeMod INSTANCE ;
public static ForgeMod getInstance ( )
{
return INSTANCE ;
}
public UniversalBucket universalBucket ;
public ForgeMod ( )
{
2019-01-27 05:06:57 +00:00
LOGGER . info ( FORGEMOD , " Forge mod loading, version {}, for MC {} with MCP {} " , ForgeVersion . getVersion ( ) , MCPVersion . getMCVersion ( ) , MCPVersion . getMCPVersion ( ) ) ;
2018-06-21 19:37:32 +00:00
INSTANCE = this ;
2018-12-22 00:07:39 +00:00
WorldPersistenceHooks . addHook ( this ) ;
WorldPersistenceHooks . addHook ( new FMLWorldPersistenceHook ( ) ) ;
2018-08-27 17:10:07 +00:00
FMLModLoadingContext . get ( ) . getModEventBus ( ) . addListener ( this : : preInit ) ;
FMLModLoadingContext . get ( ) . getModEventBus ( ) . addListener ( this : : postInit ) ;
FMLModLoadingContext . get ( ) . getModEventBus ( ) . addListener ( this : : onAvailable ) ;
2018-06-22 04:43:25 +00:00
MinecraftForge . EVENT_BUS . addListener ( this : : serverStarting ) ;
MinecraftForge . EVENT_BUS . addListener ( this : : playerLogin ) ;
MinecraftForge . EVENT_BUS . addListener ( this : : serverStopping ) ;
2019-02-05 02:23:58 +00:00
/ *
2019-01-29 03:42:37 +00:00
FMLModLoadingContext . get ( ) . registerConfig ( ModConfig . Type . CLIENT , ForgeConfig . spec ) ;
FMLModLoadingContext . get ( ) . registerConfig ( ModConfig . Type . SERVER , ForgeConfig . chunk_spec ) ;
FMLModLoadingContext . get ( ) . getModEventBus ( ) . register ( ForgeConfig . class ) ;
2019-02-05 02:23:58 +00:00
* /
//Temporary, until I can talk to CPW about how certian types of config setups
loadConfig ( ForgeConfig . spec , FMLPaths . CONFIGDIR . get ( ) . resolve ( " forge.toml " ) ) ;
loadConfig ( ForgeConfig . chunk_spec , FMLPaths . CONFIGDIR . get ( ) . resolve ( " forge_chunk.toml " ) ) ;
}
private void loadConfig ( ForgeConfigSpec spec , Path path ) {
LOGGER . debug ( FORGEMOD , " Loading config file {} " , path ) ;
final CommentedFileConfig configData = CommentedFileConfig . builder ( path )
. sync ( )
. autosave ( )
. writingMode ( WritingMode . REPLACE )
. build ( ) ;
LOGGER . debug ( FORGEMOD , " Built TOML config for {} " , path . toString ( ) ) ;
configData . load ( ) ;
LOGGER . debug ( FORGEMOD , " Loaded TOML config file {} " , path . toString ( ) ) ;
spec . setConfig ( configData ) ;
2018-06-21 19:37:32 +00:00
}
2018-08-30 01:30:15 +00:00
/ *
2018-06-21 19:37:32 +00:00
public void missingMapping ( RegistryEvent . MissingMappings < Item > event )
{
for ( MissingMappings . Mapping < Item > entry : event . getAllMappings ( ) )
{
if ( entry . key . toString ( ) . equals ( " minecraft:totem " ) ) //This item changed from 1.11 -> 1.11.2
{
ResourceLocation newTotem = new ResourceLocation ( " minecraft:totem_of_undying " ) ;
entry . remap ( ForgeRegistries . ITEMS . getValue ( newTotem ) ) ;
}
}
}
2018-08-30 01:30:15 +00:00
* /
2018-06-21 19:37:32 +00:00
public void playerLogin ( PlayerEvent . PlayerLoggedInEvent event )
{
2018-08-30 01:30:15 +00:00
UsernameCache . setUsername ( event . player . getUniqueID ( ) , event . player . getGameProfile ( ) . getName ( ) ) ;
2018-06-21 19:37:32 +00:00
}
2019-01-15 03:32:43 +00:00
public void preInit ( FMLCommonSetupEvent evt )
2018-06-21 19:37:32 +00:00
{
CapabilityItemHandler . register ( ) ;
CapabilityFluidHandler . register ( ) ;
CapabilityAnimation . register ( ) ;
CapabilityEnergy . register ( ) ;
MinecraftForge . EVENT_BUS . register ( MinecraftForge . INTERNAL_HANDLER ) ;
MinecraftForge . EVENT_BUS . register ( this ) ;
if ( ! ForgeMod . disableVersionCheck )
{
VersionChecker . startVersionCheck ( ) ;
}
}
2018-08-30 01:30:15 +00:00
/ *
2018-06-21 19:37:32 +00:00
public void registrItems ( RegistryEvent . Register < Item > event )
{
// Add and register the forge universal bucket, if it's enabled
if ( FluidRegistry . isUniversalBucketEnabled ( ) )
{
universalBucket = new UniversalBucket ( ) ;
universalBucket . setUnlocalizedName ( " forge.bucketFilled " ) ;
2019-01-29 00:25:49 +00:00
event . getRegistry ( ) . register ( universalBucket . setRegistryName ( ForgeVersion . MOD_ID , " bucket_filled " ) ) ;
2018-06-21 19:37:32 +00:00
MinecraftForge . EVENT_BUS . register ( universalBucket ) ;
}
}
2018-08-30 01:30:15 +00:00
* /
2018-06-21 19:37:32 +00:00
2019-01-15 03:32:43 +00:00
public void postInit ( InterModProcessEvent evt )
2018-06-21 19:37:32 +00:00
{
registerAllBiomesAndGenerateEvents ( ) ;
//ForgeChunkManager.loadConfiguration();
}
private static void registerAllBiomesAndGenerateEvents ( )
{
2018-08-30 01:30:15 +00:00
/ *
2018-06-21 19:37:32 +00:00
for ( Biome biome : ForgeRegistries . BIOMES . getValuesCollection ( ) )
{
if ( biome . decorator instanceof DeferredBiomeDecorator )
{
DeferredBiomeDecorator decorator = ( DeferredBiomeDecorator ) biome . decorator ;
decorator . fireCreateEventAndReplace ( biome ) ;
}
BiomeDictionary . ensureHasTypes ( biome ) ;
}
2018-08-30 01:30:15 +00:00
* /
2018-06-21 19:37:32 +00:00
}
public void onAvailable ( FMLLoadCompleteEvent evt )
{
2018-08-30 01:30:15 +00:00
// FluidRegistry.validateFluidRegistry();
2018-06-21 19:37:32 +00:00
}
public void serverStarting ( FMLServerStartingEvent evt )
{
2018-09-05 00:23:45 +00:00
new ForgeCommand ( evt . getCommandDispatcher ( ) ) ;
2018-06-21 19:37:32 +00:00
}
public void serverStopping ( FMLServerStoppingEvent evt )
{
WorldWorkerManager . clear ( ) ;
}
@Override
public NBTTagCompound getDataForWriting ( SaveHandler handler , WorldInfo info )
{
NBTTagCompound forgeData = new NBTTagCompound ( ) ;
NBTTagCompound dimData = DimensionManager . saveDimensionDataMap ( ) ;
forgeData . setTag ( " DimensionData " , dimData ) ;
2018-09-18 04:04:02 +00:00
// TODO fluids FluidRegistry.writeDefaultFluidList(forgeData);
2018-06-21 19:37:32 +00:00
return forgeData ;
}
@Override
2018-08-30 01:30:15 +00:00
public void readData ( SaveHandler handler , WorldInfo info , NBTTagCompound tag )
2018-06-21 19:37:32 +00:00
{
2018-09-22 10:40:22 +00:00
DimensionManager . loadDimensionDataMap ( tag . hasKey ( " DimensionData " ) ? tag . getCompound ( " DimensionData " ) : null ) ;
2018-09-18 04:04:02 +00:00
// TODO fluids FluidRegistry.loadFluidDefaults(tag);
2018-06-21 19:37:32 +00:00
}
public void mappingChanged ( FMLModIdMappingEvent evt )
{
}
@Override
public String getModId ( )
{
return ForgeVersion . MOD_ID ;
}
}