{"record":{"id":"b6ef21a575ccb5b1","repo":"Anuken/Mindustry","slug":"overwriting-existing-sectors-is-not-allowed","errorCode":null,"errorMessage":"Overwriting existing sectors is not allowed.","messagePattern":"Overwriting existing sectors is not allowed\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/ContentParser.java","lineNumber":778,"sourceCode":"\n            currentContent = preset;\n            read(() -> {\n                Planet planet = preset.planet == null ? Planets.serpulo : preset.planet;\n                if(value.has(\"planet\")){\n                    planet = locate(ContentType.planet, value.getString(\"planet\", \"serpulo\"));\n\n                    if(planet == null) throw new RuntimeException(\"Planet '\" + value.getString(\"planet\") + \"' not found.\");\n                }\n\n                if(value.has(\"sector\")){\n                    //clear old value\n                    Sector prev = preset.sector;\n                    if(prev != null && prev.preset == preset){\n                        prev.preset = null;\n                    }\n                    int sector = value.getInt(\"sector\", 0) % planet.sectors.size;\n                    if(!allowPatching && sector > 0 && planet.sectors.get(sector).preset != null){\n                        throw new RuntimeException(\"Overwriting existing sectors is not allowed.\");\n                    }\n                    preset.initialize(planet, sector, true);\n                }\n\n                value.remove(\"sector\");\n                value.remove(\"planet\");\n\n                if(value.has(\"rules\")){\n                    JsonValue r = value.remove(\"rules\");\n                    if(!r.isObject()) throw new RuntimeException(\"Rules must be an object!\");\n                    preset.rules = rules -> {\n                        try{\n                            //Use standard JSON, this is not content-parser relevant\n                            JsonIO.json.readFields(rules, r);\n                        }catch(Throwable e){ //Try not to crash here, as that would be catastrophic and confusing\n                            Log.err(e);\n                        }\n                    };","sourceCodeStart":760,"sourceCodeEnd":796,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/ContentParser.java#L760-L796","documentation":"When NOT patching (allowPatching false or preset not located) and the chosen sector index is > 0, the parser checks whether planet.sectors.get(sector).preset is already set. If another preset already claims that sector, throwing prevents silently overwriting an existing sector preset. Sector 0 is exempt.","triggerScenarios":"Two sector preset JSONs target the same non-zero sector number on the same planet, and the second is not a patch. The first preset occupies the slot; the second trips the guard.","commonSituations":"Duplicate sector numbers across mod files; overriding a vanilla sector preset without enabling patch mode.","solutions":["Assign each preset a distinct, unused sector number.","If you intend to replace a preset, enable patching and reference the existing preset by name.","Audit the planet's sector list to find a free slot."],"exampleFix":"// before (two files both use sector 4)\n\"sector\": 4\n// after\n\"sector\": 7  // an unoccupied slot","handlingStrategy":"validation","validationCode":"// Detect sector collisions before parse (non-patch mode).\nif(!allowPatching && value.has(\"sector\")){\n    int s = value.getInt(\"sector\", 0);\n    if(s > 0){\n        Planet p = /* resolved planet */;\n        if(p.sectors.get(s).preset != null) throw new IllegalStateException(\"Sector \" + s + \" already claimed\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit planet sector occupancy when assigning preset numbers.","Use patch mode to intentionally replace presets."],"tags":["mindustry","modding","json","content-parser","sector-preset","conflict"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}