Fix legacy tag parser prefering untyped doubles to ints

This fixes an incompatibility caused by https://github.com/SkyblockerMod/Skyblocker/issues/462
This commit is contained in:
Linnea Gräf
2023-12-29 19:14:55 +01:00
parent 7456887738
commit bd0712adb0

View File

@@ -208,10 +208,6 @@ class LegacyTagParser private constructor(string: String) {
if (textForm.isEmpty()) { if (textForm.isEmpty()) {
racer.error("Expected numeric tag (starting with either -, +, . or a digit") racer.error("Expected numeric tag (starting with either -, +, . or a digit")
} }
val doubleMatch = Patterns.DOUBLE.matchEntire(textForm) ?: Patterns.DOUBLE_UNTYPED.matchEntire(textForm)
if (doubleMatch != null) {
return NbtDouble.of(doubleMatch.groups[1]!!.value.toDouble())
}
val floatMatch = Patterns.FLOAT.matchEntire(textForm) val floatMatch = Patterns.FLOAT.matchEntire(textForm)
if (floatMatch != null) { if (floatMatch != null) {
return NbtFloat.of(floatMatch.groups[1]!!.value.toFloat()) return NbtFloat.of(floatMatch.groups[1]!!.value.toFloat())
@@ -232,6 +228,10 @@ class LegacyTagParser private constructor(string: String) {
if (integerMatch != null) { if (integerMatch != null) {
return NbtInt.of(integerMatch.groups[1]!!.value.toInt()) return NbtInt.of(integerMatch.groups[1]!!.value.toInt())
} }
val doubleMatch = Patterns.DOUBLE.matchEntire(textForm) ?: Patterns.DOUBLE_UNTYPED.matchEntire(textForm)
if (doubleMatch != null) {
return NbtDouble.of(doubleMatch.groups[1]!!.value.toDouble())
}
throw IllegalStateException("Could not properly parse numeric tag '$textForm', despite passing rough verification. This is a bug in the LegacyTagParser") throw IllegalStateException("Could not properly parse numeric tag '$textForm', despite passing rough verification. This is a bug in the LegacyTagParser")
} }