Closed LeadAssimilator closed 2 years ago
Agree, the lack of boolean is an oversight on my part.
The most elegant solution is probably the addition of BoolTag
class that simply uses ByteTag
ID internally and for serialization purposes, etc. This should be trivial to implement and update soon.
As of https://github.com/ForeverZer0/SharpNBT/commit/f27bebf6c9057ab6e2ba9e3726d5911b176c1ab7, SNBT parsing also accepts values of true
and false
, which are are case-sensitive (by-design). They will be parsed into a newly added BoolTag
class to make them semantically different from a ByteTag
. The BoolTag
class will be properly serialized as ByteTag
when serializing to a binary format, but unfortunately cannot be deserialized from binary, as it does not exists natively, and is primarily a feature of SNBT and document building.
The TagBuilder
class also now includes a AddBool
methods.
There is also a release for this version, which will likely be updated on NuGet by the time this message is seen.
The SNBT parser lacks support for the Boolean type with values true or false. Internally this type is mapped to Byte when converting to NBT.
Although I think it is important to somehow preserve the original value came from a Boolean such that when rewriting snbt files, the Boolean fields remain as true or false and don't get rewritten as 1b or 0b. Rewriting to 1b or 0b would cause unnecessary changes to appear when diffing snbts. It also makes manual editing more error prone as one loses any indication that the field has only two valid values.
So perhaps an extra property could be added to ByteTag indicating it is really a Boolean, or a BooleanTag could be introduced that has conversions for ByteTag in order to prevent information loss.