#include "Common.h" #include "Types.h" #include "World.h" #include "nbt/NBT.h" #include "RegionFile.h" #include #include #include #include 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))) { if (dir) Log::Error("Cannot find folder \"{}\"", path.string().c_str()); else Log::Error("Cannot find file \"{}\"", path.string().c_str()); 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; Log::Info("Loading world \"{}\"", name.c_str()); NBT::CompoundTag levelDat = NBT::CompoundTag(levelDatPath.string().c_str()); //std::cout << levelDat << "\n"; m_levelData.spawnX = levelDat.Get("SpawnX"); m_levelData.spawnY = levelDat.Get("SpawnY"); m_levelData.spawnZ = levelDat.Get("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"; }*/ } };