2018-06-06 15:37:56 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2019-02-10 22:57:03 +00:00
|
|
|
* Copyright (c) 2016-2019.
|
2018-06-06 15:37:56 +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.fml.client;
|
|
|
|
|
2019-10-04 21:16:36 +00:00
|
|
|
import static net.minecraftforge.fml.Logging.CORE;
|
|
|
|
import static net.minecraftforge.fml.loading.LogMarkers.LOADING;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2019-12-11 02:27:07 +00:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2019-10-04 21:16:36 +00:00
|
|
|
|
2018-06-06 15:37:56 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
2019-05-23 23:02:15 +00:00
|
|
|
import net.minecraft.client.resources.ClientResourcePackInfo;
|
2019-10-04 21:16:36 +00:00
|
|
|
import net.minecraft.client.resources.DownloadingPackFinder;
|
2019-06-22 02:42:16 +00:00
|
|
|
import net.minecraft.profiler.IProfiler;
|
2019-08-05 00:16:01 +00:00
|
|
|
import net.minecraft.resources.IFutureReloadListener;
|
|
|
|
import net.minecraft.resources.IReloadableResourceManager;
|
|
|
|
import net.minecraft.resources.IResourceManager;
|
2019-10-04 19:24:15 +00:00
|
|
|
import net.minecraft.resources.ResourcePackInfo;
|
2019-08-05 00:16:01 +00:00
|
|
|
import net.minecraft.resources.ResourcePackList;
|
2019-10-04 21:16:36 +00:00
|
|
|
import net.minecraft.resources.data.PackMetadataSection;
|
|
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
2018-06-21 19:37:32 +00:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2019-06-23 20:01:20 +00:00
|
|
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
2019-07-21 01:04:00 +00:00
|
|
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
2019-03-11 22:32:37 +00:00
|
|
|
import net.minecraftforge.common.ForgeConfig;
|
2019-05-12 17:07:17 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2019-06-23 20:01:20 +00:00
|
|
|
import net.minecraftforge.eventbus.api.Event;
|
2019-08-05 00:16:01 +00:00
|
|
|
import net.minecraftforge.fml.BrandingControl;
|
|
|
|
import net.minecraftforge.fml.LoadingFailedException;
|
|
|
|
import net.minecraftforge.fml.LogicalSidedProvider;
|
|
|
|
import net.minecraftforge.fml.ModLoader;
|
2019-10-04 19:24:15 +00:00
|
|
|
import net.minecraftforge.fml.ModLoadingStage;
|
2019-08-05 00:16:01 +00:00
|
|
|
import net.minecraftforge.fml.ModLoadingWarning;
|
|
|
|
import net.minecraftforge.fml.SidedProvider;
|
|
|
|
import net.minecraftforge.fml.VersionChecker;
|
2020-01-22 21:09:58 +00:00
|
|
|
import net.minecraftforge.fml.client.gui.screen.LoadingErrorScreen;
|
2019-06-23 20:01:20 +00:00
|
|
|
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
2019-10-04 19:24:15 +00:00
|
|
|
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
2019-10-04 21:16:36 +00:00
|
|
|
import net.minecraftforge.fml.packs.DelegatableResourcePack;
|
|
|
|
import net.minecraftforge.fml.packs.DelegatingResourcePack;
|
2019-10-04 19:24:15 +00:00
|
|
|
import net.minecraftforge.fml.packs.ModFileResourcePack;
|
2018-10-06 01:42:15 +00:00
|
|
|
import net.minecraftforge.fml.packs.ResourcePackLoader;
|
2019-08-05 00:16:01 +00:00
|
|
|
import net.minecraftforge.fml.server.LanguageHook;
|
2019-10-04 19:24:15 +00:00
|
|
|
import net.minecraftforge.forgespi.language.IModInfo;
|
2018-06-06 15:37:56 +00:00
|
|
|
|
2018-06-21 19:37:32 +00:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-06-06 15:37:56 +00:00
|
|
|
public class ClientModLoader
|
|
|
|
{
|
2019-03-11 22:32:37 +00:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
2018-06-19 18:04:05 +00:00
|
|
|
private static boolean loading;
|
|
|
|
private static Minecraft mc;
|
2018-09-29 01:07:46 +00:00
|
|
|
private static LoadingFailedException error;
|
2019-06-23 03:39:00 +00:00
|
|
|
private static EarlyLoaderGUI earlyLoaderGUI;
|
2018-06-19 18:04:05 +00:00
|
|
|
|
2019-05-23 23:02:15 +00:00
|
|
|
public static void begin(final Minecraft minecraft, final ResourcePackList<ClientResourcePackInfo> defaultResourcePacks, final IReloadableResourceManager mcResourceManager, DownloadingPackFinder metadataSerializer)
|
2018-06-06 15:37:56 +00:00
|
|
|
{
|
2019-10-26 20:55:15 +00:00
|
|
|
// force log4j to shutdown logging in a shutdown hook. This is because we disable default shutdown hook so the server properly logs it's shutdown
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(LogManager::shutdown));
|
2018-06-19 18:04:05 +00:00
|
|
|
loading = true;
|
|
|
|
ClientModLoader.mc = minecraft;
|
2018-06-11 01:12:46 +00:00
|
|
|
SidedProvider.setClient(()->minecraft);
|
2018-06-23 02:45:01 +00:00
|
|
|
LogicalSidedProvider.setClient(()->minecraft);
|
2019-08-05 00:16:01 +00:00
|
|
|
LanguageHook.loadForgeAndMCLangs();
|
2020-02-26 03:45:14 +00:00
|
|
|
earlyLoaderGUI = new EarlyLoaderGUI(minecraft.getMainWindow());
|
2019-07-01 03:48:54 +00:00
|
|
|
createRunnableWithCatch(() -> ModLoader.get().gatherAndInitializeMods(earlyLoaderGUI::renderTick)).run();
|
2019-10-04 19:24:15 +00:00
|
|
|
ResourcePackLoader.loadResourcePacks(defaultResourcePacks, ClientModLoader::buildPackFinder);
|
2019-06-22 02:42:16 +00:00
|
|
|
mcResourceManager.addReloadListener(ClientModLoader::onreload);
|
|
|
|
mcResourceManager.addReloadListener(BrandingControl.resourceManagerReloadListener());
|
2019-07-21 01:04:00 +00:00
|
|
|
ModelLoaderRegistry.init();
|
2018-06-06 15:37:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 02:42:16 +00:00
|
|
|
private static CompletableFuture<Void> onreload(final IFutureReloadListener.IStage stage, final IResourceManager resourceManager, final IProfiler prepareProfiler, final IProfiler executeProfiler, final Executor asyncExecutor, final Executor syncExecutor) {
|
2019-06-23 16:26:25 +00:00
|
|
|
return CompletableFuture.runAsync(createRunnableWithCatch(() -> startModLoading(syncExecutor)), asyncExecutor).
|
2019-06-22 16:52:22 +00:00
|
|
|
thenCompose(stage::markCompleteAwaitingOthers).
|
2019-06-23 16:26:25 +00:00
|
|
|
thenRunAsync(() -> finishModLoading(syncExecutor), asyncExecutor);
|
2019-06-22 02:42:16 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 23:08:49 +00:00
|
|
|
private static Runnable createRunnableWithCatch(Runnable r) {
|
2019-06-22 02:42:16 +00:00
|
|
|
return ()-> {
|
|
|
|
try {
|
|
|
|
r.run();
|
|
|
|
} catch (LoadingFailedException e) {
|
|
|
|
MinecraftForge.EVENT_BUS.shutdown();
|
2019-06-22 16:52:22 +00:00
|
|
|
if (error == null) error = e;
|
2019-06-22 02:42:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-06-22 16:52:22 +00:00
|
|
|
|
2019-06-23 16:26:25 +00:00
|
|
|
private static void startModLoading(Executor executor) {
|
2019-06-23 03:39:00 +00:00
|
|
|
earlyLoaderGUI.handleElsewhere();
|
2019-06-23 20:01:20 +00:00
|
|
|
createRunnableWithCatch(() -> ModLoader.get().loadMods(executor, ClientModLoader::preSidedRunnable, ClientModLoader::postSidedRunnable)).run();
|
2019-06-23 03:39:00 +00:00
|
|
|
}
|
2019-06-23 20:01:20 +00:00
|
|
|
|
|
|
|
private static void postSidedRunnable(Consumer<Supplier<Event>> perModContainerEventProcessor) {
|
|
|
|
RenderingRegistry.loadEntityRenderers(mc.getRenderManager());
|
2020-01-23 21:41:32 +00:00
|
|
|
ModelLoaderRegistry.initComplete();
|
2019-06-23 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void preSidedRunnable(Consumer<Supplier<Event>> perModContainerEventProcessor) {
|
|
|
|
perModContainerEventProcessor.accept(ModelRegistryEvent::new);
|
|
|
|
}
|
|
|
|
|
2019-06-23 16:26:25 +00:00
|
|
|
private static void finishModLoading(Executor executor)
|
2018-06-06 15:37:56 +00:00
|
|
|
{
|
2019-06-23 16:26:25 +00:00
|
|
|
createRunnableWithCatch(() -> ModLoader.get().finishMods(executor)).run();
|
2018-06-19 18:04:05 +00:00
|
|
|
loading = false;
|
2019-06-23 16:26:25 +00:00
|
|
|
// reload game settings on main thread
|
|
|
|
executor.execute(()->mc.gameSettings.loadOptions());
|
2018-06-06 15:37:56 +00:00
|
|
|
}
|
|
|
|
|
2018-06-11 01:12:46 +00:00
|
|
|
public static VersionChecker.Status checkForUpdates()
|
2018-06-06 15:37:56 +00:00
|
|
|
{
|
2018-06-11 01:12:46 +00:00
|
|
|
return VersionChecker.Status.UP_TO_DATE;
|
2018-06-06 15:37:56 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 21:59:41 +00:00
|
|
|
public static boolean completeModLoading()
|
2018-06-06 15:37:56 +00:00
|
|
|
{
|
2019-12-11 02:27:07 +00:00
|
|
|
RenderSystem.disableTexture();
|
|
|
|
RenderSystem.enableTexture();
|
2019-03-11 22:32:37 +00:00
|
|
|
List<ModLoadingWarning> warnings = ModLoader.get().getWarnings();
|
2019-03-23 00:58:10 +00:00
|
|
|
boolean showWarnings = true;
|
|
|
|
try {
|
|
|
|
showWarnings = ForgeConfig.CLIENT.showLoadWarnings.get();
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
// We're in an early error state, config is not available. Assume true.
|
|
|
|
}
|
|
|
|
if (!showWarnings) {
|
2019-03-11 22:32:37 +00:00
|
|
|
//User disabled warning screen, as least log them
|
|
|
|
if (!warnings.isEmpty()) {
|
|
|
|
LOGGER.warn(LOADING, "Mods loaded with {} warning(s)", warnings.size());
|
|
|
|
warnings.forEach(warning -> LOGGER.warn(LOADING, warning.formatToString()));
|
|
|
|
}
|
|
|
|
warnings = Collections.emptyList(); //Clear warnings, as the user does not want to see them
|
|
|
|
}
|
2019-10-15 21:59:41 +00:00
|
|
|
if (error == null) {
|
|
|
|
// We can finally start the forge eventbus up
|
|
|
|
MinecraftForge.EVENT_BUS.start();
|
|
|
|
}
|
2019-03-11 22:32:37 +00:00
|
|
|
if (error != null || !warnings.isEmpty()) {
|
|
|
|
mc.displayGuiScreen(new LoadingErrorScreen(error, warnings));
|
2019-10-15 21:59:41 +00:00
|
|
|
return true;
|
2018-12-21 22:45:35 +00:00
|
|
|
} else {
|
|
|
|
ClientHooks.logMissingTextureErrors();
|
2019-10-15 21:59:41 +00:00
|
|
|
return false;
|
2019-06-22 16:31:27 +00:00
|
|
|
}
|
2018-06-11 01:12:46 +00:00
|
|
|
}
|
2018-06-19 18:04:05 +00:00
|
|
|
|
2019-06-23 03:39:00 +00:00
|
|
|
public static void renderProgressText() {
|
|
|
|
earlyLoaderGUI.renderFromGUI();
|
|
|
|
}
|
2018-06-19 18:04:05 +00:00
|
|
|
public static boolean isLoading()
|
|
|
|
{
|
|
|
|
return loading;
|
|
|
|
}
|
2019-10-04 19:24:15 +00:00
|
|
|
|
2019-10-04 21:16:36 +00:00
|
|
|
private static <T extends ResourcePackInfo> ResourcePackLoader.IPackInfoFinder<T> buildPackFinder(Map<ModFile, ? extends ModFileResourcePack> modResourcePacks, BiConsumer<? super ModFileResourcePack, ? super T> packSetter) {
|
2019-10-04 19:24:15 +00:00
|
|
|
return (packList, factory) -> clientPackFinder(modResourcePacks, packSetter, packList, factory);
|
|
|
|
}
|
|
|
|
|
2019-10-04 21:16:36 +00:00
|
|
|
private static <T extends ResourcePackInfo> void clientPackFinder(Map<ModFile, ? extends ModFileResourcePack> modResourcePacks, BiConsumer<? super ModFileResourcePack, ? super T> packSetter, Map<String, T> packList, ResourcePackInfo.IFactory<? extends T> factory) {
|
|
|
|
List<DelegatableResourcePack> hiddenPacks = new ArrayList<>();
|
|
|
|
for (Entry<ModFile, ? extends ModFileResourcePack> e : modResourcePacks.entrySet())
|
2019-10-04 19:24:15 +00:00
|
|
|
{
|
|
|
|
IModInfo mod = e.getKey().getModInfos().get(0);
|
|
|
|
if (Objects.equals(mod.getModId(), "minecraft")) continue; // skip the minecraft "mod"
|
|
|
|
final String name = "mod:" + mod.getModId();
|
2019-10-04 21:16:36 +00:00
|
|
|
final T packInfo = ResourcePackInfo.createResourcePack(name, false, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM);
|
2019-10-04 19:24:15 +00:00
|
|
|
if (packInfo == null) {
|
|
|
|
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
|
|
|
|
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
packSetter.accept(e.getValue(), packInfo);
|
|
|
|
LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
|
2019-10-04 21:16:36 +00:00
|
|
|
if (mod.getOwningFile().showAsResourcePack()) {
|
|
|
|
packList.put(name, packInfo);
|
|
|
|
} else {
|
|
|
|
hiddenPacks.add(e.getValue());
|
|
|
|
}
|
2019-10-04 19:24:15 +00:00
|
|
|
}
|
2019-12-11 02:27:07 +00:00
|
|
|
final T packInfo = ResourcePackInfo.createResourcePack("mod_resources", true, () -> new DelegatingResourcePack("mod_resources", "Mod Resources",
|
2020-01-29 19:31:31 +00:00
|
|
|
new PackMetadataSection(new TranslationTextComponent("fml.resources.modresources", hiddenPacks.size()), 5),
|
2019-10-04 21:16:36 +00:00
|
|
|
hiddenPacks), factory, ResourcePackInfo.Priority.BOTTOM);
|
|
|
|
packList.put("mod_resources", packInfo);
|
2019-10-04 19:24:15 +00:00
|
|
|
}
|
2018-06-06 15:37:56 +00:00
|
|
|
}
|