summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft/World.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-12-11 23:53:14 +0100
committerPetr Mrázek <peterix@gmail.com>2018-12-11 23:53:14 +0100
commit13b293dd6518f8e3c80afd6fe40629e3caee69dc (patch)
tree1af24d9e9e0ea426138f18d24c7bfbeab7803d9b /api/logic/minecraft/World.cpp
parentde568b32b85b24fb24fdec2bc90066bf00b2f013 (diff)
downloadMultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar
MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar.gz
MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar.lz
MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar.xz
MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.zip
GH-2374 fix missing alternating backgrounds in worlds, add gametype column
Diffstat (limited to 'api/logic/minecraft/World.cpp')
-rw-r--r--api/logic/minecraft/World.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/api/logic/minecraft/World.cpp b/api/logic/minecraft/World.cpp
index b39f940e..5da562aa 100644
--- a/api/logic/minecraft/World.cpp
+++ b/api/logic/minecraft/World.cpp
@@ -30,6 +30,26 @@
#include <quazipfile.h>
#include <quazipdir.h>
+#include <QCoreApplication>
+
+QString gameTypeToString(GameType type)
+{
+ switch (type)
+ {
+ case GameType::Survival:
+ return QCoreApplication::translate("GameType", "Survival");
+ case GameType::Creative:
+ return QCoreApplication::translate("GameType", "Creative");
+ case GameType::Adventure:
+ return QCoreApplication::translate("GameType", "Adventure");
+ case GameType::Spectator:
+ return QCoreApplication::translate("GameType", "Spectator");
+ default:
+ break;
+ }
+ return QObject::tr("Unknown");
+}
+
std::unique_ptr <nbt::tag_compound> parseLevelDat(QByteArray data)
{
QByteArray output;
@@ -303,6 +323,32 @@ static int64_t read_long (nbt::value& parent, const char * name, const int64_t &
}
}
+static int read_int (nbt::value& parent, const char * name, const int & fallback = 0)
+{
+ try
+ {
+ auto &namedValue = parent.at(name);
+ if(namedValue.get_type() != nbt::tag_type::Int)
+ {
+ return fallback;
+ }
+ auto & tag_str = namedValue.as<nbt::tag_int>();
+ return tag_str.get();
+ }
+ catch (const std::out_of_range &e)
+ {
+ // fallback for old world formats
+ qWarning() << "Int NBT tag" << name << "could not be found. Defaulting to" << fallback;
+ return fallback;
+ }
+ catch (const std::bad_cast &e)
+ {
+ // type mismatch
+ qWarning() << "NBT tag" << name << "could not be converted to int. Defaulting to" << fallback;
+ return fallback;
+ }
+}
+
void World::loadFromLevelDat(QByteArray data)
{
try
@@ -332,11 +378,14 @@ void World::loadFromLevelDat(QByteArray data)
m_lastPlayed = QDateTime::fromMSecsSinceEpoch(temp);
}
+ m_gameType = (GameType) read_int(val, "GameType", 0);
+
m_randomSeed = read_long(val, "RandomSeed", 0);
qDebug() << "World Name:" << m_actualName;
qDebug() << "Last Played:" << m_lastPlayed.toString();
qDebug() << "Seed:" << m_randomSeed;
+ qDebug() << "GameMode:" << m_randomSeed;
}
catch (const nbt::io::input_error &e)
{