Initial blind port of the mod error screens

This commit is contained in:
mezz committed 2018-09-09 12:46:56 -07:00
1 parent dde7dccef1
commit f851b37aa0
19 files changed
+633 -154

No files matched your search

@@ -24,15 +24,16 @@ import java.util.Map.Entry;
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<ModContainer,File> dupes;
public SetMultimap<ModContainer, File> dupes;
public DuplicateModsFoundException(SetMultimap<ModContainer, File> dupes) {
this.dupes = dupes;
@@ -50,7 +51,7 @@ public class DuplicateModsFoundException extends LoaderException implements IDis
}
@Override
@SideOnly(Side.CLIENT)
@OnlyIn(Dist.CLIENT)
public GuiScreen createGui()
{
return new GuiDupesFound(this);
@@ -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<MissingModInfo> 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<ArtifactVersion> 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<MissingModInfo> 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;
}
}
}
@@ -22,23 +22,21 @@ package net.minecraftforge.fml.common;
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<WrongMinecraftVersionException> wrongMinecraftExceptions;
public final List<MissingModsException> missingModsExceptions;
public MultipleModsErrored(List<WrongMinecraftVersionException> wrongMinecraftExceptions, List<MissingModsException> missingModsExceptions)
public MultipleModsErrored(List<MissingModsException> 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 class MultipleModsErrored extends EnhancedRuntimeException implements IDi
@Override
protected void printStackTrace(WrappedPrintStream stream)
{
for (WrongMinecraftVersionException wrongMinecraftVersionException : this.wrongMinecraftExceptions)
{
wrongMinecraftVersionException.printStackTrace(stream);
}
for (MissingModsException missingModsException : this.missingModsExceptions)
{
missingModsException.printStackTrace(stream);
@@ -31,4 +31,6 @@ public interface ArtifactVersion
boolean containsVersion(ArtifactVersion source);
String getRangeString();
String getLabel();
}
@@ -24,6 +24,10 @@ package net.minecraftforge.fml.common.versioning;
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 class Restriction
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 @@ public class Restriction
{
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 @@ public class Restriction
{
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());
}
}
}
*/
}
@@ -28,6 +28,9 @@ import java.util.Iterator;
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 class VersionRange
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<String> friendlyRestrictions = new ArrayList<String>(restrictions.size());
for (Restriction restriction : restrictions)
{
friendlyRestrictions.add(restriction.toStringFriendly());
}
return Joiner.on(", ").join(friendlyRestrictions);
}
}
}