Fix negative number handling for snbt parsers

This commit is contained in:
zontreck 2025-01-22 03:12:53 -07:00
parent 18e98ca918
commit 900a5358a8
7 changed files with 32 additions and 7 deletions

View file

@ -1,3 +1,5 @@
import 'package:intl/intl.dart';
import '../Stream.dart';
import '../Tag.dart';
@ -41,13 +43,16 @@ class DoubleTag extends Tag {
@override
void prettyPrint(int indent, bool recurse) {
NumberFormat nf = NumberFormat("###.##", "en_US");
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: $value");
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${nf.format(value)}");
}
@override
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
builder.append("${isList ? "".padLeft(indent, '\t') : ""}${value}d");
NumberFormat nf = NumberFormat("###.##", "en_US");
builder.append(
"${isList ? "".padLeft(indent, '\t') : ""}${nf.format(value)}d");
}
@override

View file

@ -1,3 +1,5 @@
import 'package:intl/intl.dart';
import '../Stream.dart';
import '../Tag.dart';
@ -40,13 +42,16 @@ class FloatTag extends Tag {
@override
void prettyPrint(int indent, bool recurse) {
NumberFormat nf = NumberFormat("###.##", "en_US");
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: $value");
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${nf.format(value)}");
}
@override
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
builder.append("${isList ? "".padLeft(indent, '\t') : ""}${value}f");
NumberFormat nf = NumberFormat("###.##", "en_US");
builder.append(
"${isList ? "".padLeft(indent, '\t') : ""}${nf.format(value)}f");
}
@override