summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/minecraft')
-rw-r--r--api/logic/minecraft/MinecraftProfile.cpp33
-rw-r--r--api/logic/minecraft/MinecraftProfile.h4
-rw-r--r--api/logic/minecraft/VersionFile.cpp1
-rw-r--r--api/logic/minecraft/VersionFile.h3
-rw-r--r--api/logic/minecraft/onesix/OneSixVersionFormat.cpp31
-rw-r--r--api/logic/minecraft/onesix/OneSixVersionFormat.h4
6 files changed, 72 insertions, 4 deletions
diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp
index a82d892f..5f1a9f26 100644
--- a/api/logic/minecraft/MinecraftProfile.cpp
+++ b/api/logic/minecraft/MinecraftProfile.cpp
@@ -457,12 +457,12 @@ void MinecraftProfile::applyJarMods(const QList<LibraryPtr>& jarMods)
this->m_jarMods.append(jarMods);
}
-static int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &needle)
+static int findLibraryByName(QList<LibraryPtr> *haystack, const GradleSpecifier &needle)
{
int retval = -1;
- for (int i = 0; i < haystack.size(); ++i)
+ for (int i = 0; i < haystack->size(); ++i)
{
- if (haystack.at(i)->rawName().matchName(needle))
+ if (haystack->at(i)->rawName().matchName(needle))
{
// only one is allowed.
if (retval != -1)
@@ -473,6 +473,31 @@ static int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &
return retval;
}
+void MinecraftProfile::applyMods(const QList<LibraryPtr>& mods)
+{
+ QList<LibraryPtr> * list = &m_mods;
+ for(auto & mod: mods)
+ {
+ auto modCopy = Library::limitedCopy(mod);
+
+ // find the mod by name.
+ const int index = findLibraryByName(list, mod->rawName());
+ // mod not found? just add it.
+ if (index < 0)
+ {
+ list->append(modCopy);
+ return;
+ }
+
+ auto existingLibrary = list->at(index);
+ // if we are higher it means we should update
+ if (Version(mod->version()) > Version(existingLibrary->version()))
+ {
+ list->replace(index, modCopy);
+ }
+ }
+}
+
void MinecraftProfile::applyLibrary(LibraryPtr library)
{
if(!library->isActive())
@@ -489,7 +514,7 @@ void MinecraftProfile::applyLibrary(LibraryPtr library)
auto libraryCopy = Library::limitedCopy(library);
// find the library by name.
- const int index = findLibraryByName(*list, library->rawName());
+ const int index = findLibraryByName(list, library->rawName());
// library not found? just add it.
if (index < 0)
{
diff --git a/api/logic/minecraft/MinecraftProfile.h b/api/logic/minecraft/MinecraftProfile.h
index 6e72afa1..8cb5331f 100644
--- a/api/logic/minecraft/MinecraftProfile.h
+++ b/api/logic/minecraft/MinecraftProfile.h
@@ -99,6 +99,7 @@ public: /* application of profile variables from patches */
void applyTraits(const QSet<QString> &traits);
void applyTweakers(const QStringList &tweakers);
void applyJarMods(const QList<LibraryPtr> &jarMods);
+ void applyMods(const QList<LibraryPtr> &jarMods);
void applyLibrary(LibraryPtr library);
void applyMainJar(LibraryPtr jar);
void applyProblemSeverity(ProblemSeverity severity);
@@ -179,6 +180,9 @@ private: /* data */
/// A list of jar mods. version files can add those.
QList<LibraryPtr> m_jarMods;
+ /// the list of mods
+ QList<LibraryPtr> m_mods;
+
ProblemSeverity m_problemSeverity = ProblemSeverity::None;
/*
diff --git a/api/logic/minecraft/VersionFile.cpp b/api/logic/minecraft/VersionFile.cpp
index b6e2ab37..37df06a1 100644
--- a/api/logic/minecraft/VersionFile.cpp
+++ b/api/logic/minecraft/VersionFile.cpp
@@ -35,6 +35,7 @@ void VersionFile::applyTo(MinecraftProfile *profile)
profile->applyMinecraftArguments(minecraftArguments);
profile->applyTweakers(addTweakers);
profile->applyJarMods(jarMods);
+ profile->applyMods(mods);
profile->applyTraits(traits);
for (auto library : libraries)
diff --git a/api/logic/minecraft/VersionFile.h b/api/logic/minecraft/VersionFile.h
index b673811c..e3fb46ed 100644
--- a/api/logic/minecraft/VersionFile.h
+++ b/api/logic/minecraft/VersionFile.h
@@ -85,6 +85,9 @@ public: /* data */
/// MultiMC: list of jar mods added to this version
QList<LibraryPtr> jarMods;
+ /// MultiMC: list of mods added to this version
+ QList<LibraryPtr> mods;
+
public:
// Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more.
QMap <QString, std::shared_ptr<MojangDownloadInfo>> mojangDownloads;
diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp
index da55d91b..e27389b6 100644
--- a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp
+++ b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp
@@ -126,6 +126,18 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
}
}
+ if (root.contains("mods"))
+ {
+ for (auto libVal : requireArray(root.value("mods")))
+ {
+ QJsonObject libObj = requireObject(libVal);
+ // parse the jarmod
+ auto lib = OneSixVersionFormat::modFromJson(libObj, filename);
+ // and add to jar mods
+ out->mods.append(lib);
+ }
+ }
+
auto readLibs = [&](const char * which)
{
for (auto libVal : requireArray(root.value(which)))
@@ -246,6 +258,15 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
}
root.insert("jarMods", array);
}
+ if (!patch->mods.isEmpty())
+ {
+ QJsonArray array;
+ for (auto value: patch->jarMods)
+ {
+ array.append(OneSixVersionFormat::modtoJson(value.get()));
+ }
+ root.insert("mods", array);
+ }
// write the contents to a json document.
{
QJsonDocument out;
@@ -306,3 +327,13 @@ QJsonObject OneSixVersionFormat::jarModtoJson(Library *jarmod)
}
return out;
}
+
+LibraryPtr OneSixVersionFormat::modFromJson(const QJsonObject& libObj, const QString& filename)
+{
+ return libraryFromJson(libObj, filename);
+}
+
+QJsonObject OneSixVersionFormat::modtoJson(Library *jarmod)
+{
+ return libraryToJson(jarmod);
+}
diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.h b/api/logic/minecraft/onesix/OneSixVersionFormat.h
index 0a29a202..64f18da8 100644
--- a/api/logic/minecraft/onesix/OneSixVersionFormat.h
+++ b/api/logic/minecraft/onesix/OneSixVersionFormat.h
@@ -22,4 +22,8 @@ public:
// new jar mods derived from libraries
static LibraryPtr jarModFromJson(const QJsonObject &libObj, const QString &filename);
static QJsonObject jarModtoJson(Library * jarmod);
+
+ // mods, also derived from libraries
+ static LibraryPtr modFromJson(const QJsonObject &libObj, const QString &filename);
+ static QJsonObject modtoJson(Library * jarmod);
};