2020-08-07 05:48:54 +01:00
|
|
|
#include "Common.h"
|
|
|
|
#include "Types.h"
|
|
|
|
#include "World.h"
|
|
|
|
#include "nbt/NBT.h"
|
|
|
|
#include "RegionFile.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
using std::string;
|
|
|
|
using std::stringstream;
|
|
|
|
|
|
|
|
namespace Feather
|
|
|
|
{
|
|
|
|
static bool CheckPath(fs::path path, bool dir = false)
|
|
|
|
{
|
|
|
|
if (!fs::exists(path) || (dir && !fs::is_directory(path)))
|
|
|
|
{
|
2020-08-07 06:25:10 +01:00
|
|
|
if (dir) Log::Error("Cannot find folder \"{}\"", path.string().c_str());
|
|
|
|
else Log::Error("Cannot find file \"{}\"", path.string().c_str());
|
2020-08-07 05:48:54 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
World::World(string name)
|
|
|
|
{
|
|
|
|
fs::path worldPath = fs::path(name);
|
|
|
|
if (!CheckPath(worldPath)) return;
|
|
|
|
|
|
|
|
fs::path regionsPath = worldPath/"region";
|
|
|
|
if (!CheckPath(regionsPath)) return;
|
|
|
|
|
|
|
|
fs::path levelDatPath = worldPath/"level.dat";
|
|
|
|
if (!CheckPath(levelDatPath)) return;
|
|
|
|
|
|
|
|
|
2020-08-07 06:25:10 +01:00
|
|
|
Log::Info("Loading world \"{}\"", name.c_str());
|
2020-08-07 05:48:54 +01:00
|
|
|
|
|
|
|
NBT::CompoundTag levelDat = NBT::CompoundTag(levelDatPath.string().c_str());
|
|
|
|
|
|
|
|
//std::cout << levelDat << "\n";
|
|
|
|
|
|
|
|
m_levelData.spawnX = levelDat.Get<int32_t>("SpawnX");
|
|
|
|
m_levelData.spawnY = levelDat.Get<int32_t>("SpawnY");
|
|
|
|
m_levelData.spawnZ = levelDat.Get<int32_t>("SpawnZ");
|
|
|
|
|
|
|
|
ChunkPos spawnChunk(BlockPos(m_levelData.spawnX, m_levelData.spawnY, m_levelData.spawnZ));
|
|
|
|
RegionPos regionPos(spawnChunk);
|
|
|
|
|
|
|
|
stringstream regionFile;
|
|
|
|
regionFile << "r." << regionPos.x << "." << regionPos.z << ".mca";
|
|
|
|
|
|
|
|
fs::path mcaFile = regionsPath / regionFile.str();
|
|
|
|
if (!CheckPath(mcaFile)) return;
|
|
|
|
//Log_Info("Spawn Chunk Region File: %s", mcaFile.string().c_str());
|
|
|
|
|
|
|
|
RegionFile region(mcaFile.string());
|
|
|
|
|
|
|
|
//std::cout << region << "\n";
|
|
|
|
|
|
|
|
/*for (auto& f : fs::directory_iterator(regionsPath))
|
|
|
|
{
|
|
|
|
std::cout << f.path() << "\n";
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
};
|