From f851b37aa0ba2801362c60c74e60ef98b09ed580 Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 9 Sep 2018 12:46:56 -0700 Subject: [PATCH] Initial blind port of the mod error screens --- .gitignore | 2 + .../common/ForgeModContainer.java | 2 +- .../common/config/ConfigManager.java | 5 +- .../common/config/Configuration.java | 3 +- .../gui/GuiCustomModLoadingErrorScreen.java | 7 + .../fml/client/gui/GuiDupesFound.java | 18 +- .../fml/client/gui/GuiErrorBase.java | 14 +- .../fml/client/gui/GuiModsMissing.java | 16 +- .../client/gui/GuiModsMissingForServer.java | 1 + .../client/gui/GuiMultipleModsErrored.java | 84 ++-- .../fml/client/gui/GuiScrollingList.java | 378 ++++++++++++++++++ .../fml/client/gui/GuiWrongMinecraft.java | 50 --- .../common/DuplicateModsFoundException.java | 11 +- .../fml/common/MissingModsException.java | 129 ++++++ .../fml/common/MultipleModsErrored.java | 16 +- .../common/versioning/ArtifactVersion.java | 2 + .../fml/common/versioning/Restriction.java | 26 +- .../fml/common/versioning/VersionRange.java | 21 + ...odlauncher.serviceapi.ILaunchPluginService | 2 +- 19 files changed, 633 insertions(+), 154 deletions(-) create mode 100644 src/main/java/net/minecraftforge/fml/client/gui/GuiScrollingList.java delete mode 100644 src/main/java/net/minecraftforge/fml/client/gui/GuiWrongMinecraft.java create mode 100644 src/main/java/net/minecraftforge/fml/common/MissingModsException.java diff --git a/.gitignore b/.gitignore index 35c0642163..8f4afe08e0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ changelog.txt *.py *.7z /logs/ + +/.project diff --git a/src/main/java/net/minecraftforge/common/ForgeModContainer.java b/src/main/java/net/minecraftforge/common/ForgeModContainer.java index f10269e8e2..05cba89529 100644 --- a/src/main/java/net/minecraftforge/common/ForgeModContainer.java +++ b/src/main/java/net/minecraftforge/common/ForgeModContainer.java @@ -81,7 +81,7 @@ public ForgeModContainer() } catch (MalformedURLException e) {} config = null; - File cfgFile = new File(Loader.instance().getConfigDir(), "forge.cfg"); + File cfgFile = new File(FMLPaths.FMLCONFIG.get().toFile(), "forge.cfg"); config = new Configuration(cfgFile); syncConfig(true); diff --git a/src/main/java/net/minecraftforge/common/config/ConfigManager.java b/src/main/java/net/minecraftforge/common/config/ConfigManager.java index 8bfe7a3d58..b6726699ab 100644 --- a/src/main/java/net/minecraftforge/common/config/ConfigManager.java +++ b/src/main/java/net/minecraftforge/common/config/ConfigManager.java @@ -37,6 +37,7 @@ import net.minecraftforge.common.config.Config.LangKey; import net.minecraftforge.common.config.Config.Name; import net.minecraftforge.fml.common.FMLLog; +import net.minecraftforge.fml.common.FMLPaths; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.LoaderException; import net.minecraftforge.fml.loading.moddiscovery.ModAnnotation.EnumHolder; @@ -144,7 +145,7 @@ public static void sync(String modid, Config.Type type) { FMLLog.log.debug("Attempting to inject @Config classes into {} for type {}", modid, type); ClassLoader mcl = Loader.instance().getModClassLoader(); - File configDir = Loader.instance().getConfigDir(); + File configDir = FMLPaths.FMLCONFIG.get().toFile(); Multimap map = asm_data.get(modid); if (map == null) @@ -207,7 +208,7 @@ public static boolean hasConfigForMod(String modid) static Configuration getConfiguration(String modid, String name) { if (Strings.isNullOrEmpty(name)) name = modid; - File configDir = Loader.instance().getConfigDir(); + File configDir = FMLPaths.FMLCONFIG.get().toFile(); File configFile = new File(configDir, name + ".cfg"); return CONFIGS.get(configFile.getAbsolutePath()); } diff --git a/src/main/java/net/minecraftforge/common/config/Configuration.java b/src/main/java/net/minecraftforge/common/config/Configuration.java index 667af6c38f..0921fb4717 100644 --- a/src/main/java/net/minecraftforge/common/config/Configuration.java +++ b/src/main/java/net/minecraftforge/common/config/Configuration.java @@ -56,6 +56,7 @@ import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry; import net.minecraftforge.fml.client.config.IConfigElement; import net.minecraftforge.fml.common.FMLLog; +import net.minecraftforge.fml.common.FMLPaths; import net.minecraftforge.fml.common.Loader; import org.apache.commons.io.IOUtils; @@ -1287,7 +1288,7 @@ private void setChild(String name, Configuration child) public static void enableGlobalConfig() { - PARENT = new Configuration(new File(Loader.instance().getConfigDir(), "global.cfg")); + PARENT = new Configuration(new File(FMLPaths.FMLCONFIG.get().toFile(), "global.cfg")); PARENT.load(); } diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiCustomModLoadingErrorScreen.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiCustomModLoadingErrorScreen.java index 1cabab0f9d..974874b382 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiCustomModLoadingErrorScreen.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiCustomModLoadingErrorScreen.java @@ -19,19 +19,26 @@ package net.minecraftforge.fml.client.gui; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) public class GuiCustomModLoadingErrorScreen extends GuiErrorBase { private CustomModLoadingErrorDisplayException customException; + public GuiCustomModLoadingErrorScreen(CustomModLoadingErrorDisplayException customException) { this.customException = customException; } + @Override public void initGui() { super.initGui(); this.customException.initGui(this, fontRenderer); } + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiDupesFound.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiDupesFound.java index 9370b84569..ec2840835a 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiDupesFound.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiDupesFound.java @@ -19,15 +19,17 @@ package net.minecraftforge.fml.client.gui; -import net.minecraftforge.fml.common.DuplicateModsFoundException; -import net.minecraftforge.fml.ModContainer; - import java.io.File; import java.util.Map.Entry; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.ModContainer; +import net.minecraftforge.fml.common.DuplicateModsFoundException; + +@OnlyIn(Dist.CLIENT) public class GuiDupesFound extends GuiErrorBase { - private DuplicateModsFoundException dupes; public GuiDupesFound(DuplicateModsFoundException dupes) @@ -41,14 +43,14 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) this.drawDefaultBackground(); int offset = Math.max(85 - dupes.dupes.size() * 10, 10); this.drawCenteredString(this.fontRenderer, "Forge Mod Loader has found a problem with your minecraft installation", this.width / 2, offset, 0xFFFFFF); - offset+=10; + offset += 10; this.drawCenteredString(this.fontRenderer, "You have mod sources that are duplicate within your system", this.width / 2, offset, 0xFFFFFF); - offset+=10; + offset += 10; this.drawCenteredString(this.fontRenderer, "Mod Id : File name", this.width / 2, offset, 0xFFFFFF); - offset+=5; + offset += 5; for (Entry mc : dupes.dupes.entries()) { - offset+=10; + offset += 10; this.drawCenteredString(this.fontRenderer, String.format("%s : %s", mc.getKey().getModId(), mc.getValue().getName()), this.width / 2, offset, 0xEEEEEE); } super.drawScreen(mouseX, mouseY, partialTicks); diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiErrorBase.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiErrorBase.java index 8f8fe32b16..9ede95b283 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiErrorBase.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiErrorBase.java @@ -19,21 +19,25 @@ package net.minecraftforge.fml.client.gui; +import java.awt.Desktop; +import java.io.File; + import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiErrorScreen; import net.minecraft.client.resources.I18n; - -import java.awt.*; -import java.io.File; - +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.common.FMLPaths; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +@OnlyIn(Dist.CLIENT) public class GuiErrorBase extends GuiErrorScreen { private static final Logger LOGGER = LogManager.getLogger(); - static final File minecraftDir = new File(Loader.instance().getConfigDir().getParent()); + static final File minecraftDir = new File(FMLPaths.FMLCONFIG.get().toFile().getParent()); static final File logFile = new File(minecraftDir, "logs/latest.log"); + public GuiErrorBase() { super(null, null); diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissing.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissing.java index d8f7864e73..83cb02605c 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissing.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissing.java @@ -20,15 +20,19 @@ package net.minecraftforge.fml.client.gui; import java.util.List; +import java.util.Optional; import net.minecraft.client.resources.I18n; import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.ModContainer; +import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.MissingModsException; -import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion; +@OnlyIn(Dist.CLIENT) public class GuiModsMissing extends GuiErrorBase { private MissingModsException modsMissing; @@ -46,7 +50,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) int offset = Math.max(85 - missingModsVersions.size() * 10, 10); String modMissingDependenciesText = I18n.format("fml.messages.mod.missing.dependencies.compatibility", TextFormatting.BOLD + modsMissing.getModName() + TextFormatting.RESET); this.drawCenteredString(this.fontRenderer, modMissingDependenciesText, this.width / 2, offset, 0xFFFFFF); - offset+=5; + offset += 5; for (MissingModsException.MissingModInfo versionInfo : missingModsVersions) { ArtifactVersion acceptedVersion = versionInfo.getAcceptedVersion(); @@ -64,14 +68,14 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) String acceptedModVersionString = acceptedVersion.getRangeString(); if (acceptedVersion instanceof DefaultArtifactVersion) { - DefaultArtifactVersion dav = (DefaultArtifactVersion)acceptedVersion; + DefaultArtifactVersion dav = (DefaultArtifactVersion) acceptedVersion; if (dav.getRange() != null) { acceptedModVersionString = dav.getRange().toStringFriendly(); } } - ModContainer acceptedMod = Loader.instance().getIndexedModList().get(acceptedModId); - String acceptedModName = acceptedMod != null ? acceptedMod.getName() : acceptedModId; + Optional acceptedMod = ModList.get().getModContainerById(acceptedModId); + String acceptedModName = acceptedMod.map((mod) -> mod.getModInfo().getDisplayName()).orElse(acceptedModId); String versionInfoText = String.format(TextFormatting.BOLD + "%s " + TextFormatting.RESET + "%s (%s)", acceptedModName, acceptedModVersionString, missingReason); String message; if (versionInfo.isRequired()) diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissingForServer.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissingForServer.java index ecec5952c0..9ce3da7ed2 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissingForServer.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiModsMissingForServer.java @@ -24,6 +24,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; +import net.minecraftforge.fml.common.MissingModsException; import net.minecraftforge.fml.common.versioning.ArtifactVersion; public class GuiModsMissingForServer extends GuiScreen diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiMultipleModsErrored.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiMultipleModsErrored.java index 794924a7a4..9d2aabd2b3 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiMultipleModsErrored.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiMultipleModsErrored.java @@ -19,32 +19,30 @@ package net.minecraftforge.fml.client.gui; +import java.util.List; +import java.util.Optional; + import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.resources.I18n; import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.ModContainer; +import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.MissingModsException; -import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.MultipleModsErrored; -import net.minecraftforge.fml.common.WrongMinecraftVersionException; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion; -import org.lwjgl.input.Mouse; - -import java.io.IOException; -import java.util.List; +@OnlyIn(Dist.CLIENT) public class GuiMultipleModsErrored extends GuiErrorBase { - private final List wrongMinecraftExceptions; private final List missingModsExceptions; private GuiList list; public GuiMultipleModsErrored(MultipleModsErrored exception) { - wrongMinecraftExceptions = exception.wrongMinecraftExceptions; missingModsExceptions = exception.missingModsExceptions; } @@ -52,12 +50,12 @@ public GuiMultipleModsErrored(MultipleModsErrored exception) public void initGui() { super.initGui(); - int additionalSize = missingModsExceptions.isEmpty() || wrongMinecraftExceptions.isEmpty() ? 20 : 55; + int additionalSize = missingModsExceptions.isEmpty() ? 20 : 55; for (MissingModsException exception : missingModsExceptions) { additionalSize += exception.getMissingModInfos().size() * 10; } - list = new GuiList(wrongMinecraftExceptions.size() * 10 + missingModsExceptions.size() * 15 + additionalSize); + list = new GuiList(missingModsExceptions.size() * 15 + additionalSize); } @Override @@ -65,24 +63,15 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); this.list.drawScreen(mouseX, mouseY, partialTicks); - this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.missing.multiple", missingModsExceptions.size() + wrongMinecraftExceptions.size()), this.width/2, 10, 0xFFFFFF); + String missingMultipleModsText = I18n.format("fml.messages.mod.missing.multiple", missingModsExceptions.size()); + this.drawCenteredString(this.fontRenderer, missingMultipleModsText, this.width / 2, 10, 0xFFFFFF); super.drawScreen(mouseX, mouseY, partialTicks); } @Override - public void actionPerformed(GuiButton button) - { - this.list.actionPerformed(button); - super.actionPerformed(button); - } - - @Override - public void handleMouseInput() throws IOException + public boolean mouseScrolled(double scroll) { - super.handleMouseInput(); - int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth; - int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - this.list.handleMouseInput(mouseX, mouseY); + return this.list.mouseScrolled(scroll); } private class GuiList extends GuiScrollingList @@ -90,13 +79,13 @@ private class GuiList extends GuiScrollingList public GuiList(int entryHeight) { super(GuiMultipleModsErrored.this.mc, - GuiMultipleModsErrored.this.width-20, - GuiMultipleModsErrored.this.height -30, - 30, GuiMultipleModsErrored.this.height-50, - 10, - entryHeight, - GuiMultipleModsErrored.this.width, - GuiMultipleModsErrored.this.height); + GuiMultipleModsErrored.this.width - 20, + GuiMultipleModsErrored.this.height - 30, + 30, GuiMultipleModsErrored.this.height - 50, + 10, + entryHeight, + GuiMultipleModsErrored.this.width, + GuiMultipleModsErrored.this.height); } @Override @@ -106,7 +95,9 @@ protected int getSize() } @Override - protected void elementClicked(int index, boolean doubleClick) {} + protected void elementClicked(int index, boolean doubleClick) + { + } @Override protected boolean isSelected(int index) @@ -125,26 +116,13 @@ protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer { int offset = slotTop; FontRenderer renderer = GuiMultipleModsErrored.this.fontRenderer; - if (!wrongMinecraftExceptions.isEmpty()) - { - renderer.drawString(TextFormatting.UNDERLINE + I18n.format("fml.messages.mod.wrongminecraft", Loader.instance().getMinecraftModContainer().getVersion()), this.left, offset, 0xFFFFFF); - offset+=15; - for(WrongMinecraftVersionException exception : wrongMinecraftExceptions) - { - renderer.drawString(I18n.format("fml.messages.mod.wrongminecraft.requirement", TextFormatting.BOLD + exception.mod.getName() + TextFormatting.RESET, exception.mod.getModId(), exception.mod.acceptableMinecraftVersionRange().toStringFriendly()), this.left, offset, 0xFFFFFF); - offset += 10; - } - offset+=5; - renderer.drawString(I18n.format("fml.messages.mod.wrongminecraft.fix.multiple"), this.left, offset, 0xFFFFFF); - offset+=20; - } if (!missingModsExceptions.isEmpty()) { - renderer.drawString(I18n.format("fml.messages.mod.missing.dependencies.multiple.issues"), this.left, offset, 0xFFFFFF); - offset+=15; + renderer.func_211126_b(I18n.format("fml.messages.mod.missing.dependencies.multiple.issues"), this.left, offset, 0xFFFFFF); + offset += 15; for (MissingModsException exception : missingModsExceptions) { - renderer.drawString(exception.getModName() + ":", this.left, offset, 0xFFFFFF); + renderer.func_211126_b(exception.getModName() + ":", this.left, offset, 0xFFFFFF); for (MissingModsException.MissingModInfo versionInfo : exception.getMissingModInfos()) { ArtifactVersion acceptedVersion = versionInfo.getAcceptedVersion(); @@ -162,14 +140,14 @@ protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer String acceptedModVersionString = acceptedVersion.getRangeString(); if (acceptedVersion instanceof DefaultArtifactVersion) { - DefaultArtifactVersion dav = (DefaultArtifactVersion)acceptedVersion; + DefaultArtifactVersion dav = (DefaultArtifactVersion) acceptedVersion; if (dav.getRange() != null) { acceptedModVersionString = dav.getRange().toStringFriendly(); } } - ModContainer acceptedMod = Loader.instance().getIndexedModList().get(acceptedModId); - String acceptedModName = acceptedMod != null ? acceptedMod.getName() : acceptedModId; + Optional acceptedMod = ModList.get().getModContainerById(acceptedModId); + String acceptedModName = acceptedMod.map((mod) -> mod.getModInfo().getDisplayName()).orElse(acceptedModId); String versionInfoText = String.format(TextFormatting.BOLD + "%s " + TextFormatting.RESET + "%s (%s)", acceptedModName, acceptedModVersionString, missingReason); String message; if (versionInfo.isRequired()) @@ -181,7 +159,7 @@ protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer message = I18n.format("fml.messages.mod.missing.dependencies.compatible.with", versionInfoText); } offset += 10; - renderer.drawString(message, this.left, offset, 0xEEEEEE); + renderer.func_211126_b(message, this.left, offset, 0xEEEEEE); } offset += 15; diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiScrollingList.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiScrollingList.java new file mode 100644 index 0000000000..aed652d844 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiScrollingList.java @@ -0,0 +1,378 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2018. + * + * 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.gui; + +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.client.config.GuiUtils; +import org.lwjgl.opengl.GL11; + +@OnlyIn(Dist.CLIENT) +public abstract class GuiScrollingList +{ + private final Minecraft client; + protected final int listWidth; + protected final int listHeight; + protected final int screenWidth; + protected final int screenHeight; + protected final int top; + protected final int bottom; + protected final int right; + protected final int left; + protected final int slotHeight; + protected int mouseX; + protected int mouseY; + private float initialMouseClickY = -2.0F; + private float scrollFactor; + private float scrollDistance; + protected int selectedIndex = -1; + private long lastClickTime = 0L; + private boolean highlightSelected = true; + private boolean hasHeader; + private int headerHeight; + + @Deprecated // We need to know screen size. + public GuiScrollingList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight) + { + this(client, width, height, top, bottom, left, entryHeight, width, height); + } + + public GuiScrollingList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight, int screenWidth, int screenHeight) + { + this.client = client; + this.listWidth = width; + this.listHeight = height; + this.top = top; + this.bottom = bottom; + this.slotHeight = entryHeight; + this.left = left; + this.right = width + this.left; + this.screenWidth = screenWidth; + this.screenHeight = screenHeight; + } + + protected void setHeaderInfo(boolean hasHeader, int headerHeight) + { + this.hasHeader = hasHeader; + this.headerHeight = headerHeight; + if (!hasHeader) this.headerHeight = 0; + } + + protected void setHighlightSelected(boolean highlightSelected) + { + this.highlightSelected = highlightSelected; + } + + protected abstract int getSize(); + + protected abstract void elementClicked(int index, boolean doubleClick); + + protected abstract boolean isSelected(int index); + + protected int getContentHeight() + { + return this.getSize() * this.slotHeight + this.headerHeight; + } + + protected abstract void drawBackground(); + + /** + * Draw anything special on the screen. GL_SCISSOR is enabled for anything that + * is rendered outside of the view box. Do not mess with SCISSOR unless you support this. + */ + protected abstract void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer, Tessellator tess); + + /** + * Draw anything special on the screen. GL_SCISSOR is enabled for anything that + * is rendered outside of the view box. Do not mess with SCISSOR unless you support this. + */ + protected void drawHeader(int entryRight, int relativeY, Tessellator tess) + { + } + + protected void clickHeader(int x, int y) + { + } + + /** + * Draw anything special on the screen. GL_SCISSOR is enabled for anything that + * is rendered outside of the view box. Do not mess with SCISSOR unless you support this. + */ + protected void drawScreen(int mouseX, int mouseY) + { + } + + private void applyScrollLimits() + { + int listHeight = this.getContentHeight() - (this.bottom - this.top - 4); + + if (listHeight < 0) + { + listHeight /= 2; + } + + if (this.scrollDistance < 0.0F) + { + this.scrollDistance = 0.0F; + } + + if (this.scrollDistance > (float) listHeight) + { + this.scrollDistance = (float) listHeight; + } + } + + /** + * Scroll up a fixed amount, used for button callbacks. + */ + public void scrollUp() + { + this.scrollDistance -= (float) (this.slotHeight * 2 / 3); + this.initialMouseClickY = -2.0F; + this.applyScrollLimits(); + } + + /** + * Scroll down a fixed amount, used for button callbacks. + */ + public void scrollDown() + { + this.scrollDistance += (float) (this.slotHeight * 2 / 3); + this.initialMouseClickY = -2.0F; + this.applyScrollLimits(); + } + + private boolean isHovering() + { + return mouseX >= this.left && mouseX <= this.left + this.listWidth && + mouseY >= this.top && mouseY <= this.bottom; + } + + public boolean mouseScrolled(double scroll) + { + if (this.isHovering() && scroll != 0) + { + this.scrollDistance += (float) ((-1 * scroll / 120.0F) * this.slotHeight / 2); + return true; + } + return false; + } + + public void drawScreen(int mouseX, int mouseY, float partialTicks) + { + this.mouseX = mouseX; + this.mouseY = mouseY; + this.drawBackground(); + + boolean isHovering = this.isHovering(); + int listLength = this.getSize(); + int scrollBarWidth = 6; + int scrollBarRight = this.left + this.listWidth; + int scrollBarLeft = scrollBarRight - scrollBarWidth; + int entryLeft = this.left; + int entryRight = scrollBarLeft - 1; + int viewHeight = this.bottom - this.top; + int border = 4; + + Minecraft minecraft = Minecraft.getMinecraft(); + if (minecraft.mouseHelper.func_198030_b()) + { + if (this.initialMouseClickY == -1.0F) + { + if (isHovering) + { + int mouseListY = mouseY - this.top - this.headerHeight + (int) this.scrollDistance - border; + int slotIndex = mouseListY / this.slotHeight; + + if (mouseX >= entryLeft && mouseX <= entryRight && slotIndex >= 0 && mouseListY >= 0 && slotIndex < listLength) + { + this.elementClicked(slotIndex, slotIndex == this.selectedIndex && System.currentTimeMillis() - this.lastClickTime < 250L); + this.selectedIndex = slotIndex; + this.lastClickTime = System.currentTimeMillis(); + } + else if (mouseX >= entryLeft && mouseX <= entryRight && mouseListY < 0) + { + this.clickHeader(mouseX - entryLeft, mouseY - this.top + (int) this.scrollDistance - border); + } + + if (mouseX >= scrollBarLeft && mouseX <= scrollBarRight) + { + this.scrollFactor = -1.0F; + int scrollHeight = this.getContentHeight() - viewHeight - border; + if (scrollHeight < 1) scrollHeight = 1; + + int var13 = (int) ((float) (viewHeight * viewHeight) / (float) this.getContentHeight()); + + if (var13 < 32) var13 = 32; + if (var13 > viewHeight - border * 2) + var13 = viewHeight - border * 2; + + this.scrollFactor /= (float) (viewHeight - var13) / (float) scrollHeight; + } + else + { + this.scrollFactor = 1.0F; + } + + this.initialMouseClickY = mouseY; + } + else + { + this.initialMouseClickY = -2.0F; + } + } + else if (this.initialMouseClickY >= 0.0F) + { + this.scrollDistance -= ((float) mouseY - this.initialMouseClickY) * this.scrollFactor; + this.initialMouseClickY = (float) mouseY; + } + } + else + { + this.initialMouseClickY = -1.0F; + } + + this.applyScrollLimits(); + + Tessellator tess = Tessellator.getInstance(); + BufferBuilder worldr = tess.getBuffer(); + + MainWindow window = client.field_195558_d; + double scaleW = window.func_198107_o(); + double scaleH = window.func_198087_p(); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GL11.glScissor((int) (left * scaleW), (int) (window.func_198107_o() - (bottom * scaleH)), + (int) (listWidth * scaleW), (int) (viewHeight * scaleH)); + + if (this.client.world != null) + { + this.drawGradientRect(this.left, this.top, this.right, this.bottom, 0xC0101010, 0xD0101010); + } + else // Draw dark dirt background + { + GlStateManager.disableLighting(); + GlStateManager.disableFog(); + this.client.renderEngine.bindTexture(Gui.OPTIONS_BACKGROUND); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + final float scale = 32.0F; + worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldr.pos(this.left, this.bottom, 0.0D).tex(this.left / scale, (this.bottom + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex(); + worldr.pos(this.right, this.bottom, 0.0D).tex(this.right / scale, (this.bottom + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex(); + worldr.pos(this.right, this.top, 0.0D).tex(this.right / scale, (this.top + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex(); + worldr.pos(this.left, this.top, 0.0D).tex(this.left / scale, (this.top + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex(); + tess.draw(); + } + + int baseY = this.top + border - (int) this.scrollDistance; + + if (this.hasHeader) + { + this.drawHeader(entryRight, baseY, tess); + } + + for (int slotIdx = 0; slotIdx < listLength; ++slotIdx) + { + int slotTop = baseY + slotIdx * this.slotHeight + this.headerHeight; + int slotBuffer = this.slotHeight - border; + + if (slotTop <= this.bottom && slotTop + slotBuffer >= this.top) + { + if (this.highlightSelected && this.isSelected(slotIdx)) + { + int min = this.left; + int max = entryRight; + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.disableTexture2D(); + worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldr.pos(min, slotTop + slotBuffer + 2, 0).tex(0, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(max, slotTop + slotBuffer + 2, 0).tex(1, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(max, slotTop - 2, 0).tex(1, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(min, slotTop - 2, 0).tex(0, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(min + 1, slotTop + slotBuffer + 1, 0).tex(0, 1).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + worldr.pos(max - 1, slotTop + slotBuffer + 1, 0).tex(1, 1).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + worldr.pos(max - 1, slotTop - 1, 0).tex(1, 0).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + worldr.pos(min + 1, slotTop - 1, 0).tex(0, 0).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + tess.draw(); + GlStateManager.enableTexture2D(); + } + + this.drawSlot(slotIdx, entryRight, slotTop, slotBuffer, tess); + } + } + + GlStateManager.disableDepth(); + + int extraHeight = (this.getContentHeight() + border) - viewHeight; + if (extraHeight > 0) + { + int height = (viewHeight * viewHeight) / this.getContentHeight(); + + if (height < 32) height = 32; + + if (height > viewHeight - border * 2) + height = viewHeight - border * 2; + + int barTop = (int) this.scrollDistance * (viewHeight - height) / extraHeight + this.top; + if (barTop < this.top) + { + barTop = this.top; + } + + GlStateManager.disableTexture2D(); + worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldr.pos(scrollBarLeft, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + worldr.pos(scrollBarRight, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + worldr.pos(scrollBarRight, this.top, 0.0D).tex(1.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + worldr.pos(scrollBarLeft, this.top, 0.0D).tex(0.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex(); + tess.draw(); + worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldr.pos(scrollBarLeft, barTop + height, 0.0D).tex(0.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(scrollBarRight, barTop + height, 0.0D).tex(1.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(scrollBarRight, barTop, 0.0D).tex(1.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex(); + tess.draw(); + worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + worldr.pos(scrollBarLeft, barTop + height - 1, 0.0D).tex(0.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex(); + worldr.pos(scrollBarRight - 1, barTop + height - 1, 0.0D).tex(1.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex(); + worldr.pos(scrollBarRight - 1, barTop, 0.0D).tex(1.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex(); + worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex(); + tess.draw(); + } + + this.drawScreen(mouseX, mouseY); + GlStateManager.enableTexture2D(); + GlStateManager.shadeModel(GL11.GL_FLAT); + GlStateManager.enableAlpha(); + GlStateManager.disableBlend(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } + + protected void drawGradientRect(int left, int top, int right, int bottom, int color1, int color2) + { + GuiUtils.drawGradientRect(0, left, top, right, bottom, color1, color2); + } +} diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiWrongMinecraft.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiWrongMinecraft.java deleted file mode 100644 index 4ebf849b0d..0000000000 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiWrongMinecraft.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Minecraft Forge - * Copyright (c) 2016-2018. - * - * 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.gui; - -import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.WrongMinecraftVersionException; - -public class GuiWrongMinecraft extends GuiErrorBase -{ - private WrongMinecraftVersionException wrongMC; - - public GuiWrongMinecraft(WrongMinecraftVersionException wrongMC) - { - this.wrongMC = wrongMC; - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) - { - this.drawDefaultBackground(); - int offset = 75; - this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.wrongminecraft", Loader.instance().getMinecraftModContainer().getVersion()), this.width / 2, offset, 0xFFFFFF); - offset+=15; - this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.wrongminecraft.requirement", TextFormatting.BOLD + wrongMC.mod.getName() + TextFormatting.RESET, wrongMC.mod.getModId(), wrongMC.mod.acceptableMinecraftVersionRange().toStringFriendly()), this.width / 2, offset, 0xEEEEEE); - offset+=15; - this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.wrongminecraft.fix", wrongMC.mod.getName()),this.width/2, offset, 0xFFFFFF); - offset+=20; - this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.missing.dependencies.see.log", GuiErrorBase.logFile.getName()), this.width / 2, offset, 0xFFFFFF); - super.drawScreen(mouseX, mouseY, partialTicks); - } -} diff --git a/src/main/java/net/minecraftforge/fml/common/DuplicateModsFoundException.java b/src/main/java/net/minecraftforge/fml/common/DuplicateModsFoundException.java index 8d96e31fdf..c708ae10a8 100644 --- a/src/main/java/net/minecraftforge/fml/common/DuplicateModsFoundException.java +++ b/src/main/java/net/minecraftforge/fml/common/DuplicateModsFoundException.java @@ -24,15 +24,16 @@ import com.google.common.collect.SetMultimap; import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.fml.client.GuiDupesFound; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.ModContainer; import net.minecraftforge.fml.client.IDisplayableError; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.fml.client.gui.GuiDupesFound; public class DuplicateModsFoundException extends LoaderException implements IDisplayableError { private static final long serialVersionUID = 1L; - public SetMultimap dupes; + public SetMultimap dupes; public DuplicateModsFoundException(SetMultimap dupes) { this.dupes = dupes; @@ -50,7 +51,7 @@ protected void printStackTrace(WrappedPrintStream stream) } @Override - @SideOnly(Side.CLIENT) + @OnlyIn(Dist.CLIENT) public GuiScreen createGui() { return new GuiDupesFound(this); diff --git a/src/main/java/net/minecraftforge/fml/common/MissingModsException.java b/src/main/java/net/minecraftforge/fml/common/MissingModsException.java new file mode 100644 index 0000000000..8680955da9 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/MissingModsException.java @@ -0,0 +1,129 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2018. + * + * 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.common; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.base.Preconditions; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.client.gui.GuiModsMissing; +import net.minecraftforge.fml.client.IDisplayableError; +import net.minecraftforge.fml.common.versioning.ArtifactVersion; + +public class MissingModsException extends EnhancedRuntimeException implements IDisplayableError +{ + private static final long serialVersionUID = 1L; + private final String id; + private final String name; + private final List missingModsInfos; + private final String modName; + + public MissingModsException(String id, String name) + { + this.id = id; + this.name = name; + this.missingModsInfos = new ArrayList<>(); + this.modName = name; + } + + @Override + public String getMessage() + { + Set missingMods = missingModsInfos.stream().map(MissingModInfo::getAcceptedVersion).collect(Collectors.toSet()); + return String.format("Mod %s (%s) requires %s", id, name, missingMods); + } + + public void addMissingMod(ArtifactVersion acceptedVersion, @Nullable ArtifactVersion currentVersion, boolean required) + { + MissingModInfo missingModInfo = new MissingModInfo(acceptedVersion, currentVersion, required); + this.missingModsInfos.add(missingModInfo); + } + + public String getModName() + { + return modName; + } + + public List getMissingModInfos() + { + return Collections.unmodifiableList(this.missingModsInfos); + } + + @Override + protected void printStackTrace(WrappedPrintStream stream) + { + stream.println("Missing Mods:"); + for (MissingModInfo info : this.missingModsInfos) + { + ArtifactVersion acceptedVersion = info.getAcceptedVersion(); + ArtifactVersion currentVersion = info.getCurrentVersion(); + String currentString = currentVersion != null ? currentVersion.getVersionString() : "missing"; + stream.println(String.format("\t%s : need %s: have %s", acceptedVersion.getVersionString(), acceptedVersion.getRangeString(), currentString)); + } + stream.println(""); + } + + @Override + @OnlyIn(Dist.CLIENT) + public GuiScreen createGui() + { + return new GuiModsMissing(this); + } + + public static class MissingModInfo + { + private final ArtifactVersion acceptedVersion; + @Nullable + private final ArtifactVersion currentVersion; + private final boolean required; + + private MissingModInfo(ArtifactVersion acceptedVersion, @Nullable ArtifactVersion currentVersion, boolean required) + { + Preconditions.checkNotNull(acceptedVersion, "acceptedVersion"); + this.acceptedVersion = acceptedVersion; + this.currentVersion = currentVersion; + this.required = required; + } + + @Nullable + public ArtifactVersion getCurrentVersion() + { + return currentVersion; + } + + public ArtifactVersion getAcceptedVersion() + { + return acceptedVersion; + } + + public boolean isRequired() + { + return required; + } + } + +} diff --git a/src/main/java/net/minecraftforge/fml/common/MultipleModsErrored.java b/src/main/java/net/minecraftforge/fml/common/MultipleModsErrored.java index 0d5c7b6acf..6811ac16d5 100644 --- a/src/main/java/net/minecraftforge/fml/common/MultipleModsErrored.java +++ b/src/main/java/net/minecraftforge/fml/common/MultipleModsErrored.java @@ -22,23 +22,21 @@ import java.util.List; import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.fml.client.GuiMultipleModsErrored; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.client.IDisplayableError; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.fml.client.gui.GuiMultipleModsErrored; public class MultipleModsErrored extends EnhancedRuntimeException implements IDisplayableError { - public final List wrongMinecraftExceptions; public final List missingModsExceptions; - public MultipleModsErrored(List wrongMinecraftExceptions, List missingModsExceptions) + public MultipleModsErrored(List missingModsExceptions) { - this.wrongMinecraftExceptions = wrongMinecraftExceptions; this.missingModsExceptions = missingModsExceptions; } @Override - @SideOnly(Side.CLIENT) + @OnlyIn(Dist.CLIENT) public GuiScreen createGui() { return new GuiMultipleModsErrored(this); @@ -47,10 +45,6 @@ public GuiScreen createGui() @Override protected void printStackTrace(WrappedPrintStream stream) { - for (WrongMinecraftVersionException wrongMinecraftVersionException : this.wrongMinecraftExceptions) - { - wrongMinecraftVersionException.printStackTrace(stream); - } for (MissingModsException missingModsException : this.missingModsExceptions) { missingModsException.printStackTrace(stream); diff --git a/src/main/java/net/minecraftforge/fml/common/versioning/ArtifactVersion.java b/src/main/java/net/minecraftforge/fml/common/versioning/ArtifactVersion.java index 15517e0ffd..9b525e9214 100644 --- a/src/main/java/net/minecraftforge/fml/common/versioning/ArtifactVersion.java +++ b/src/main/java/net/minecraftforge/fml/common/versioning/ArtifactVersion.java @@ -31,4 +31,6 @@ public interface ArtifactVersion boolean containsVersion(ArtifactVersion source); String getRangeString(); + + String getLabel(); } diff --git a/src/main/java/net/minecraftforge/fml/common/versioning/Restriction.java b/src/main/java/net/minecraftforge/fml/common/versioning/Restriction.java index 438559a865..c345a81d99 100644 --- a/src/main/java/net/minecraftforge/fml/common/versioning/Restriction.java +++ b/src/main/java/net/minecraftforge/fml/common/versioning/Restriction.java @@ -24,6 +24,10 @@ import javax.annotation.Nullable; +import net.minecraft.client.resources.I18n; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + /** * Describes a restriction in versioning. * @@ -205,13 +209,14 @@ public String toString() return buf.toString(); } - /* + //Forge: Added toStringFriendly, uses Minecraft's localization engine to create user friendly localized message. + @OnlyIn(Dist.CLIENT) public String toStringFriendly() { if ( getLowerBound() == null && getUpperBound() == null ) { - return I18n.translateToLocal("fml.messages.version.restriction.any"); + return I18n.format("fml.messages.version.restriction.any"); } else if ( getLowerBound() != null && getUpperBound() != null ) { @@ -223,19 +228,19 @@ else if ( getLowerBound() != null && getUpperBound() != null ) { if (isLowerBoundInclusive() && isUpperBoundInclusive()) { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.bounded.inclusive", getLowerBound(), getUpperBound()); + return I18n.format("fml.messages.version.restriction.bounded.inclusive", getLowerBound(), getUpperBound()); } else if (isLowerBoundInclusive()) { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.bounded.upperexclusive", getLowerBound(), getUpperBound()); + return I18n.format("fml.messages.version.restriction.bounded.upperexclusive", getLowerBound(), getUpperBound()); } else if (isUpperBoundInclusive()) { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.bounded.lowerexclusive", getLowerBound(), getUpperBound()); + return I18n.format("fml.messages.version.restriction.bounded.lowerexclusive", getLowerBound(), getUpperBound()); } else { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.bounded.exclusive", getLowerBound(), getUpperBound()); + return I18n.format("fml.messages.version.restriction.bounded.exclusive", getLowerBound(), getUpperBound()); } } } @@ -243,24 +248,23 @@ else if ( getLowerBound() != null ) { if ( isLowerBoundInclusive() ) { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.lower.inclusive", getLowerBound()); + return I18n.format("fml.messages.version.restriction.lower.inclusive", getLowerBound()); } else { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.lower.exclusive", getLowerBound()); + return I18n.format("fml.messages.version.restriction.lower.exclusive", getLowerBound()); } } else { if ( isUpperBoundInclusive() ) { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.upper.inclusive", getUpperBound()); + return I18n.format("fml.messages.version.restriction.upper.inclusive", getUpperBound()); } else { - return I18n.translateToLocalFormatted("fml.messages.version.restriction.upper.exclusive", getUpperBound()); + return I18n.format("fml.messages.version.restriction.upper.exclusive", getUpperBound()); } } } - */ } diff --git a/src/main/java/net/minecraftforge/fml/common/versioning/VersionRange.java b/src/main/java/net/minecraftforge/fml/common/versioning/VersionRange.java index 989c6598b2..3100bebcf0 100644 --- a/src/main/java/net/minecraftforge/fml/common/versioning/VersionRange.java +++ b/src/main/java/net/minecraftforge/fml/common/versioning/VersionRange.java @@ -28,6 +28,9 @@ import java.util.List; import com.google.common.base.Joiner; //Forge: Add Imports +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + import javax.annotation.Nullable; /** @@ -584,4 +587,22 @@ public String getLowerBoundString() return restrictions.size() == 1 ? restrictions.get(0).getLowerBound().getVersionString() : ""; } + //Forge: Added friendly {localized} toString + @OnlyIn(Dist.CLIENT) + public String toStringFriendly() + { + if ( recommendedVersion != null ) + { + return recommendedVersion.getVersionString(); + } + else + { + List friendlyRestrictions = new ArrayList(restrictions.size()); + for (Restriction restriction : restrictions) + { + friendlyRestrictions.add(restriction.toStringFriendly()); + } + return Joiner.on(", ").join(friendlyRestrictions); + } + } } diff --git a/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService b/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService index 824a7b6c15..502278a9a3 100644 --- a/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService +++ b/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService @@ -1,4 +1,4 @@ net.minecraftforge.fml.loading.RuntimeDistCleaner -net.minecraftforge.common.asm.RuntimeEnumExtener +net.minecraftforge.common.asm.RuntimeEnumExtender net.minecraftforge.common.asm.ObjectHolderDefinalize net.minecraftforge.common.asm.CapabilityInjectDefinalize