mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Basic error display GUI.
This commit is contained in:
1 parent
dec65732ce
commit
bb9eca96a8
26 files changed
+451
-83
No files matched your search
@@ -29,11 +29,13 @@ import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraft.resources.data.IMetadataSectionSerializer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.LoadingFailedException;
|
||||
import net.minecraftforge.fml.LogicalSidedProvider;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.SidedProvider;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.client.gui.GuiNotification;
|
||||
import net.minecraftforge.fml.client.gui.LoadingErrorScreen;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -44,6 +46,7 @@ public class ClientModLoader
|
||||
{
|
||||
private static boolean loading;
|
||||
private static Minecraft mc;
|
||||
private static LoadingFailedException error;
|
||||
|
||||
public static void begin(final Minecraft minecraft, final ResourcePackList<ResourcePackInfoClient> defaultResourcePacks, final IReloadableResourceManager mcResourceManager, DownloadingPackFinder metadataSerializer)
|
||||
{
|
||||
@@ -51,13 +54,21 @@ public class ClientModLoader
|
||||
ClientModLoader.mc = minecraft;
|
||||
SidedProvider.setClient(()->minecraft);
|
||||
LogicalSidedProvider.setClient(()->minecraft);
|
||||
ModLoader.get().loadMods();
|
||||
try {
|
||||
ModLoader.get().loadMods();
|
||||
} catch (LoadingFailedException e) {
|
||||
error = e;
|
||||
}
|
||||
ResourcePackLoader.loadResourcePacks(defaultResourcePacks);
|
||||
}
|
||||
|
||||
public static void end()
|
||||
{
|
||||
ModLoader.get().finishMods();
|
||||
try {
|
||||
ModLoader.get().finishMods();
|
||||
} catch (LoadingFailedException e) {
|
||||
if (error == null) error = e;
|
||||
}
|
||||
loading = false;
|
||||
mc.gameSettings.loadOptions();
|
||||
}
|
||||
@@ -71,11 +82,9 @@ public class ClientModLoader
|
||||
{
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
public static boolean isErrored()
|
||||
{
|
||||
return false;
|
||||
if (error != null) {
|
||||
mc.displayGuiScreen(new LoadingErrorScreen(error));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLoading()
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.resources.ResourcePackInfoClient;
|
||||
import net.minecraft.resources.AbstractResourcePack;
|
||||
import net.minecraft.resources.FilePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IPackFinder;
|
||||
import net.minecraft.resources.IReloadableResourceManager;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
@@ -33,7 +30,6 @@ import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraftforge.fml.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import java.util.function.DoubleBinaryOperator;
|
||||
|
||||
public class GuiButtonClickConsumer extends GuiButton {
|
||||
private final DoubleBinaryOperator onClickAction;
|
||||
|
||||
public GuiButtonClickConsumer(final int buttonId, final int x, final int y, final int widthIn, final int heightIn, final String buttonText, DoubleBinaryOperator onClick) {
|
||||
super(buttonId, x, y, widthIn, heightIn, buttonText);
|
||||
this.onClickAction = onClick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final double mouseX, final double mouseY) {
|
||||
onClickAction.applyAsDouble(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.common.FMLPaths;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package net.minecraftforge.fml.client.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraftforge.fml.ForgeI18n;
|
||||
import net.minecraftforge.fml.LoadingFailedException;
|
||||
import net.minecraftforge.fml.ModLoadingException;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.util.StringUtils.stripControlCodes;
|
||||
|
||||
public class LoadingErrorScreen extends GuiErrorScreen {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private final Path modsDir;
|
||||
private final Path logFile;
|
||||
private final LoadingFailedException loadingFailedException;
|
||||
private LoadingErrorList errorList;
|
||||
public LoadingErrorScreen(LoadingFailedException loadingException)
|
||||
{
|
||||
super(null, null);
|
||||
this.loadingFailedException = loadingException;
|
||||
this.modsDir = FMLPaths.MODSDIR.get();
|
||||
this.logFile = FMLPaths.GAMEDIR.get().resolve(Paths.get("logs","latest.log"));
|
||||
}
|
||||
|
||||
private double openModsDir(double mouseX, double mouseY)
|
||||
{
|
||||
try
|
||||
{
|
||||
Desktop.getDesktop().open(modsDir.toFile());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Problem opening mods folder", e);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
private double openLogFile(double mouseX, double mouseY)
|
||||
{
|
||||
try
|
||||
{
|
||||
Desktop.getDesktop().open(logFile.toFile());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Problem opening log file {}", logFile, e);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttons.clear();
|
||||
this.children.clear();
|
||||
this.addButton(new GuiButtonClickConsumer(10, 50, this.height - 38, this.width / 2 - 55, 20,
|
||||
ForgeI18n.parseMessage("fml.button.open.mods.folder"), this::openModsDir));
|
||||
this.addButton(new GuiButtonClickConsumer(11, this.width / 2 + 5, this.height - 38, this.width / 2 - 55, 20,
|
||||
ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName()), this::openLogFile));
|
||||
this.errorList = new LoadingErrorList(this, this.loadingFailedException.getErrors());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.errorList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
drawMultiLineCenteredString(fontRenderer, ForgeI18n.parseMessage("fml.loadingerrorscreen.header", this.loadingFailedException.getErrors().size()), this.width / 2, 10);
|
||||
this.buttons.forEach(button -> button.render(mouseX, mouseY, partialTicks));
|
||||
}
|
||||
|
||||
private void drawMultiLineCenteredString(FontRenderer fr, String str, int x, int y) {
|
||||
for (String s : fr.listFormattedStringToWidth(str, this.width)) {
|
||||
fr.drawStringWithShadow(s, (float) (x - fr.getStringWidth(s) / 2.0), y, 0xFFFFFF);
|
||||
y+=fr.FONT_HEIGHT;
|
||||
}
|
||||
}
|
||||
public static class LoadingErrorList extends GuiListExtended<LoadingErrorList.ErrorEntry> {
|
||||
LoadingErrorList(final LoadingErrorScreen parent, final List<ModLoadingException> errors) {
|
||||
super(parent.mc,parent.width,parent.height,35,parent.height - 50, 2 * parent.mc.fontRenderer.FONT_HEIGHT + 8);
|
||||
errors.forEach(e->addEntry(new ErrorEntry(e)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return this.right - 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getListWidth()
|
||||
{
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public class ErrorEntry extends GuiListExtended.IGuiListEntry<ErrorEntry> {
|
||||
private final ModLoadingException error;
|
||||
|
||||
ErrorEntry(final ModLoadingException e) {
|
||||
this.error = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(final int entryWidth, final int entryHeight, final int mouseX, final int mouseY, final boolean p_194999_5_, final float partialTicks) {
|
||||
int top = this.getY();
|
||||
int left = this.getX();
|
||||
FontRenderer font = Minecraft.getInstance().fontRenderer;
|
||||
final List<String> strings = font.listFormattedStringToWidth(error.formatToString(), LoadingErrorList.this.width);
|
||||
float f = (float)top + 2;
|
||||
for (int i = 0; i < Math.min(strings.size(), 2); i++) {
|
||||
font.drawString(strings.get(i), left + 5, f, 0xFFFFFFFF);
|
||||
f += font.FONT_HEIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user