{"record":{"id":"abe1b9d61cb99ff3","repo":"HMCL-dev/HMCL","slug":"level-dat-missing-levelname","errorCode":null,"errorMessage":"level.dat missing LevelName","messagePattern":"level\\.dat missing LevelName","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java","lineNumber":250,"sourceCode":"        return getGameVersion() != null && getGameVersion().isAtLeast(\"1.20\", \"23w14a\");\n    }\n\n    public static boolean supportQuickPlay(GameVersionNumber gameVersionNumber) {\n        return gameVersionNumber != null && gameVersionNumber.isAtLeast(\"1.20\", \"23w14a\");\n    }\n\n    private void loadAndCheckWorldData() throws IOException {\n        loadAndCheckLevelData(levelDataPath);\n        loadOtherData();\n    }\n\n    private void loadAndCheckLevelData(Path levelDat) throws IOException {\n        this.levelData = NBTCodec.of().readTag(levelDat, TagType.COMPOUND);\n        if (!(levelData.get(\"Data\") instanceof CompoundTag data))\n            throw new IOException(\"level.dat missing Data\");\n\n        if (!(data.get(\"LevelName\") instanceof StringTag))\n            throw new IOException(\"level.dat missing LevelName\");\n\n        if (!(data.get(\"LastPlayed\") instanceof LongTag))\n            throw new IOException(\"level.dat missing LastPlayed\");\n        this.dataTag = data;\n    }\n\n    private void loadOtherData() throws IOException {\n        if (!(levelData.get(\"Data\") instanceof CompoundTag data)) return;\n\n        Path worldGenSettingsDatPath = file.resolve(\"data/minecraft/world_gen_settings.dat\");\n        if (data.get(\"WorldGenSettings\") instanceof CompoundTag worldGenSettingsTag) {\n            setWorldGenSettingsData(null, worldGenSettingsTag, worldGenSettingsTag);\n        } else if (Files.isRegularFile(worldGenSettingsDatPath)) {\n            CompoundTag raw = NBTCodec.of().readTag(worldGenSettingsDatPath, TagType.COMPOUND);\n            if (raw.get(\"data\") instanceof CompoundTag compoundTag) {\n                setWorldGenSettingsData(worldGenSettingsDatPath, raw, compoundTag);\n            } else {\n                setWorldGenSettingsData(null, null, null);","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java#L232-L268","documentation":"Thrown by loadAndCheckLevelData when level.dat contains the Data compound but its 'LevelName' entry is missing or not a StringTag. HMCL uses LevelName as the display name of the world, so it treats its absence as an invalid world.","triggerScenarios":"new World(worldDir) on a level.dat whose Data compound lacks LevelName or stores it as a non-string tag type.","commonSituations":"level.dat edited incorrectly with an NBT editor deleting LevelName, worlds exported by third-party tools that strip metadata, partially corrupted Data compounds, or custom test fixtures that omit the field.","solutions":["Add or repair Data.LevelName as a string tag using an NBT editor (e.g. NBTExplorer)","Restore level.dat from a backup","Re-export/re-copy the world from the original Minecraft instance","If writing test worlds, include Data.LevelName as a StringTag"],"exampleFix":"// before (NBT fixture)\ncompound.put(\"Data\", dataTag); // dataTag has no LevelName\n// after\ndataTag.putString(\"LevelName\", \"My World\");\ncompound.put(\"Data\", dataTag);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    World world = new World(worldDir);\n} catch (IOException e) {\n    if (String.valueOf(e.getMessage()).equals(\"level.dat missing LevelName\")) {\n        // fix via NBT editor or fall back to using the folder name as display name\n    }\n}","preventionTips":["Never delete fields when editing level.dat with NBT editors","Include LevelName when generating test world fixtures: dataTag.putString(\"LevelName\", ...)","Prefer in-game rename over manual NBT edits","Validate third-party-exported worlds before importing"],"tags":["minecraft","nbt","world","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}