2018-06-21 19:37:32 +00:00
/ *
* Minecraft Forge
2019-02-10 22:57:03 +00:00
* Copyright ( c ) 2016 - 2019 .
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 ;
2019-02-14 03:13:59 +00:00
import net.minecraftforge.eventbus.api.IEventBus ;
2019-08-03 17:25:41 +00:00
import net.minecraftforge.eventbus.api.SubscribeEvent ;
2019-07-01 03:48:54 +00:00
import net.minecraftforge.fml.* ;
2019-02-10 21:38:14 +00:00
import net.minecraftforge.fml.config.ModConfig ;
2019-01-15 03:32:43 +00:00
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent ;
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent ;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent ;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent ;
2019-02-14 03:13:59 +00:00
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext ;
2019-07-29 01:09:15 +00:00
import net.minecraftforge.server.command.ConfigCommand ;
2019-08-20 22:29:26 +00:00
import net.minecraftforge.server.command.EnumArgument ;
2018-09-05 00:23:45 +00:00
import net.minecraftforge.server.command.ForgeCommand ;
2019-08-20 22:29:26 +00:00
import net.minecraftforge.server.command.ModIdArgument ;
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
2019-03-31 20:36:49 +00:00
import org.apache.commons.lang3.tuple.Pair ;
2018-06-21 19:37:32 +00:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2019-08-20 22:29:26 +00:00
import net.minecraft.command.arguments.ArgumentSerializer ;
import net.minecraft.command.arguments.ArgumentTypes ;
2019-06-14 03:58:03 +00:00
import net.minecraft.data.DataGenerator ;
2019-08-03 17:25:41 +00:00
import net.minecraft.item.crafting.IRecipe ;
import net.minecraft.item.crafting.IRecipeSerializer ;
2019-05-23 23:02:15 +00:00
import net.minecraft.nbt.CompoundNBT ;
2019-08-03 17:25:41 +00:00
import net.minecraft.util.ResourceLocation ;
2018-06-21 19:37:32 +00:00
import net.minecraft.world.storage.SaveHandler ;
import net.minecraft.world.storage.WorldInfo ;
2019-08-03 17:25:41 +00:00
import net.minecraftforge.common.crafting.CompoundIngredient ;
import net.minecraftforge.common.crafting.ConditionalRecipe ;
import net.minecraftforge.common.crafting.CraftingHelper ;
import net.minecraftforge.common.crafting.IngredientNBT ;
import net.minecraftforge.common.crafting.VanillaIngredientSerializer ;
import net.minecraftforge.common.crafting.conditions.AndCondition ;
import net.minecraftforge.common.crafting.conditions.FalseCondition ;
import net.minecraftforge.common.crafting.conditions.ItemExistsCondition ;
import net.minecraftforge.common.crafting.conditions.ModLoadedCondition ;
import net.minecraftforge.common.crafting.conditions.NotCondition ;
import net.minecraftforge.common.crafting.conditions.OrCondition ;
import net.minecraftforge.common.crafting.conditions.TagEmptyCondition ;
import net.minecraftforge.common.crafting.conditions.TrueCondition ;
2019-06-14 03:58:03 +00:00
import net.minecraftforge.common.data.ForgeBlockTagsProvider ;
import net.minecraftforge.common.data.ForgeItemTagsProvider ;
2019-06-28 00:23:07 +00:00
import net.minecraftforge.common.data.ForgeRecipeProvider ;
2018-06-21 19:37:32 +00:00
import net.minecraftforge.common.model.animation.CapabilityAnimation ;
import net.minecraftforge.energy.CapabilityEnergy ;
2019-08-03 17:25:41 +00:00
import net.minecraftforge.event.RegistryEvent ;
import net.minecraftforge.event.entity.player.PlayerEvent ;
2019-06-16 01:24:45 +00:00
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent ;
2018-06-21 19:37:32 +00:00
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-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
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
2019-02-14 23:08:53 +00:00
public static boolean alwaysSetupTerrainOffThread = false ; // In WorldRenderer.setupTerrain, always force the chunk render updates to be queued to the thread
2018-06-21 19:37:32 +00:00
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 ;
2019-02-19 17:33:37 +00:00
MinecraftForge . initialize ( ) ;
2018-12-22 00:07:39 +00:00
WorldPersistenceHooks . addHook ( this ) ;
WorldPersistenceHooks . addHook ( new FMLWorldPersistenceHook ( ) ) ;
2019-02-14 03:13:59 +00:00
final IEventBus modEventBus = FMLJavaModLoadingContext . get ( ) . getModEventBus ( ) ;
modEventBus . addListener ( this : : preInit ) ;
2019-06-14 03:58:03 +00:00
modEventBus . addListener ( this : : gatherData ) ;
2019-08-03 17:25:41 +00:00
modEventBus . register ( this ) ;
2018-06-22 04:43:25 +00:00
MinecraftForge . EVENT_BUS . addListener ( this : : serverStarting ) ;
MinecraftForge . EVENT_BUS . addListener ( this : : serverStopping ) ;
2019-02-14 03:13:59 +00:00
ModLoadingContext . get ( ) . registerConfig ( ModConfig . Type . CLIENT , ForgeConfig . clientSpec ) ;
ModLoadingContext . get ( ) . registerConfig ( ModConfig . Type . SERVER , ForgeConfig . serverSpec ) ;
modEventBus . register ( ForgeConfig . class ) ;
2019-03-31 20:36:49 +00:00
// Forge does not display problems when the remote is not matching.
ModLoadingContext . get ( ) . registerExtensionPoint ( ExtensionPoint . DISPLAYTEST , ( ) - > Pair . of ( ( ) - > " ANY " , ( remote , isServer ) - > true ) ) ;
2019-07-01 03:48:54 +00:00
StartupMessageManager . addModMessage ( " Forge version " + ForgeVersion . getVersion ( ) ) ;
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 ( ) ;
}
2019-08-20 22:29:26 +00:00
//ArgumentTypes.register("forge:enum", EnumArgument.class, new EnumArgument.Serialzier()); //This can't register, it breaks vanilla clients. As the packet serailzier doesn't discard unknown data
ArgumentTypes . register ( " forge:modid " , ModIdArgument . class , new ArgumentSerializer < > ( ModIdArgument : : modIdArgument ) ) ;
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 ( ) ) ;
2019-07-29 01:09:15 +00:00
ConfigCommand . register ( evt . getCommandDispatcher ( ) ) ;
2018-06-21 19:37:32 +00:00
}
public void serverStopping ( FMLServerStoppingEvent evt )
{
WorldWorkerManager . clear ( ) ;
}
@Override
2019-05-23 23:02:15 +00:00
public CompoundNBT getDataForWriting ( SaveHandler handler , WorldInfo info )
2018-06-21 19:37:32 +00:00
{
2019-05-23 23:02:15 +00:00
CompoundNBT forgeData = new CompoundNBT ( ) ;
CompoundNBT dims = new CompoundNBT ( ) ;
2019-02-14 23:08:53 +00:00
DimensionManager . writeRegistry ( dims ) ;
if ( ! dims . isEmpty ( ) )
2019-06-08 14:45:28 +00:00
forgeData . put ( " dims " , dims ) ;
2018-09-18 04:04:02 +00:00
// TODO fluids FluidRegistry.writeDefaultFluidList(forgeData);
2018-06-21 19:37:32 +00:00
return forgeData ;
}
@Override
2019-05-23 23:02:15 +00:00
public void readData ( SaveHandler handler , WorldInfo info , CompoundNBT tag )
2018-06-21 19:37:32 +00:00
{
2019-02-14 23:08:53 +00:00
if ( tag . contains ( " dims " , 10 ) )
DimensionManager . readRegistry ( tag . getCompound ( " dims " ) ) ;
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 ;
}
2019-06-14 03:58:03 +00:00
public void gatherData ( GatherDataEvent event )
{
DataGenerator gen = event . getGenerator ( ) ;
if ( event . includeServer ( ) )
{
gen . addProvider ( new ForgeBlockTagsProvider ( gen ) ) ;
gen . addProvider ( new ForgeItemTagsProvider ( gen ) ) ;
2019-06-28 00:23:07 +00:00
gen . addProvider ( new ForgeRecipeProvider ( gen ) ) ;
2019-06-14 03:58:03 +00:00
}
}
2019-08-03 17:25:41 +00:00
@SubscribeEvent //ModBus, can't use addListener due to nested genetics.
public void registerRecipeSerialziers ( RegistryEvent . Register < IRecipeSerializer < ? > > event )
{
CraftingHelper . register ( AndCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( FalseCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( ItemExistsCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( ModLoadedCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( NotCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( OrCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( TrueCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( TagEmptyCondition . Serializer . INSTANCE ) ;
CraftingHelper . register ( new ResourceLocation ( " forge " , " compound " ) , CompoundIngredient . Serializer . INSTANCE ) ;
CraftingHelper . register ( new ResourceLocation ( " forge " , " nbt " ) , IngredientNBT . Serializer . INSTANCE ) ;
CraftingHelper . register ( new ResourceLocation ( " minecraft " , " item " ) , VanillaIngredientSerializer . INSTANCE ) ;
event . getRegistry ( ) . register ( new ConditionalRecipe . Serializer < IRecipe < ? > > ( ) . setRegistryName ( new ResourceLocation ( " forge " , " conditional " ) ) ) ;
}
2018-06-21 19:37:32 +00:00
}