Handle schematics with an invalid DataVersion

This commit is contained in:
Octavia Togami 2020-07-13 12:19:26 -07:00
parent 98d97a7bfe
commit 38b9ac9b03
No known key found for this signature in database
GPG Key ID: CC364524D1983C99

View File

@ -101,6 +101,12 @@ public Clipboard read() throws IOException {
return readVersion1(schematicTag); return readVersion1(schematicTag);
} else if (schematicVersion == 2) { } else if (schematicVersion == 2) {
dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue(); dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
if (dataVersion < 0) {
log.warn("Schematic has an unknown data version ({}). Data may be incompatible.",
dataVersion);
// Do not DFU unknown data
dataVersion = liveDataVersion;
}
if (dataVersion > liveDataVersion) { if (dataVersion > liveDataVersion) {
log.warn("Schematic was made in a newer Minecraft version ({} > {}). Data may be incompatible.", log.warn("Schematic was made in a newer Minecraft version ({} > {}). Data may be incompatible.",
dataVersion, liveDataVersion); dataVersion, liveDataVersion);
@ -129,7 +135,11 @@ public OptionalInt getDataVersion() {
if (schematicVersion == 1) { if (schematicVersion == 1) {
return OptionalInt.of(Constants.DATA_VERSION_MC_1_13_2); return OptionalInt.of(Constants.DATA_VERSION_MC_1_13_2);
} else if (schematicVersion == 2) { } else if (schematicVersion == 2) {
return OptionalInt.of(requireTag(schematic, "DataVersion", IntTag.class).getValue()); int dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
if (dataVersion < 0) {
return OptionalInt.empty();
}
return OptionalInt.of(dataVersion);
} }
return OptionalInt.empty(); return OptionalInt.empty();
} catch (IOException e) { } catch (IOException e) {