ForgePatch/src/main/java/net/minecraftforge/common/ForgeMod.java

175 lines
7.6 KiB
Java
Raw Normal View History

2018-06-21 19:37:32 +00:00
/*
* Minecraft Forge
* 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;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.*;
import net.minecraftforge.fml.config.ModConfig;
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;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.server.command.ConfigCommand;
import net.minecraftforge.server.command.EnumArgument;
2018-09-05 00:23:45 +00:00
import net.minecraftforge.server.command.ForgeCommand;
import net.minecraftforge.server.command.ModIdArgument;
import net.minecraftforge.versions.forge.ForgeVersion;
import net.minecraftforge.versions.mcp.MCPVersion;
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;
import net.minecraft.command.arguments.ArgumentSerializer;
import net.minecraft.command.arguments.ArgumentTypes;
import net.minecraft.data.DataGenerator;
2019-05-23 23:02:15 +00:00
import net.minecraft.nbt.CompoundNBT;
2018-06-21 19:37:32 +00:00
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.data.ForgeBlockTagsProvider;
import net.minecraftforge.common.data.ForgeItemTagsProvider;
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;
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;
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
@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 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()
{
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;
MinecraftForge.initialize();
WorldPersistenceHooks.addHook(this);
WorldPersistenceHooks.addHook(new FMLWorldPersistenceHook());
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::preInit);
modEventBus.addListener(this::gatherData);
2018-06-22 04:43:25 +00:00
MinecraftForge.EVENT_BUS.addListener(this::serverStarting);
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ForgeConfig.serverSpec);
modEventBus.register(ForgeConfig.class);
// Forge does not display problems when the remote is not matching.
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, ()-> Pair.of(()->"ANY", (remote, isServer)-> true));
StartupMessageManager.addModMessage("Forge version "+ForgeVersion.getVersion());
2018-06-21 19:37:32 +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();
}
//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());
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();
DimensionManager.writeRegistry(dims);
if (!dims.isEmpty())
forgeData.put("dims", dims);
// 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
{
if (tag.contains("dims", 10))
DimensionManager.readRegistry(tag.getCompound("dims"));
// 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;
}
public void gatherData(GatherDataEvent event)
{
DataGenerator gen = event.getGenerator();
if (event.includeServer())
{
gen.addProvider(new ForgeBlockTagsProvider(gen));
gen.addProvider(new ForgeItemTagsProvider(gen));
gen.addProvider(new ForgeRecipeProvider(gen));
}
}
2018-06-21 19:37:32 +00:00
}