Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNBT Float Types Formatting #36

Open
Offroaders123 opened this issue Nov 6, 2023 · 1 comment
Open

SNBT Float Types Formatting #36

Offroaders123 opened this issue Nov 6, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Offroaders123
Copy link
Owner

SNBT decimal point demo

@Offroaders123 Offroaders123 added the bug Something isn't working label Nov 6, 2023
@Offroaders123 Offroaders123 self-assigned this Nov 6, 2023
Offroaders123 added a commit that referenced this issue Nov 6, 2023
Discovered a bug with my SNBT output! Realized that it's actually 'mandatory' (I think?) for Float and Double tags to have a decimal point. I thought it was a bug in Tnze's SNBT extension for VSCode, but it was my misunderstanding as to what was required for those tags when displayed/viewed/edited in SNBT.

I also just realized I need to add support for the `true` and `false` boolean keyword types. Those don't appear to be working either.

https://github.com/Tnze/snbt-vscode
https://static.wikia.nocookie.net/minecraft_de_gamepedia/images/e/e2/SNBT_data-Befehl.png/revision/latest
https://minecraft.wiki/w/NBT_format#SNBT_format

#36
@Offroaders123
Copy link
Owner Author

I realized there's a bug in my SNBT writer, in that Float and Double types need to have a decimal point when in SNBT form, I don't think it's optional.
With Tnze's SNBT extension for VSCode, I noticed some of the syntax highlighting was off, and I thought it was a bug in the implementation for that, but it was actually because I missed that part of the SNBT syntax.

SNBT Float Types Formatting Issue Demo

Offroaders123 added a commit that referenced this issue Nov 7, 2023
This is the real implementation for this. It actually didn't take too much to get it working!

I'm not sure whether the SNBT parsing implementation should make it mandatory for Float and Double tags to have a decimal spot. Currently you don't need to have one for it to parse correctly. This change here now just ensures that the output SNBT will now always have decimal places for simple Float and Double values.

#36
#38
#39
Offroaders123/Dovetail#5

https://stackoverflow.com/questions/175739/how-can-i-check-if-a-string-is-a-valid-number
https://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places (I thought it was going to be this one, but turns out it rounds the value, and forces the value to be within that length, unlike how I thought it was additive.)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
https://stackoverflow.com/questions/9838809/check-if-number-string-contains-decimal (I was going to use this next also, but then I realized that `Number.isInteger()` also covers the same thing, but with one less primitive type conversion, and a variable reference)

https://www.youtube.com/watch?v=z1j3RI3ZpsQ (asmr :), sleepy programming made this commit message take longer to write than normal, was dozing off a little bit; man this time change is still hard, gaining an hour is hard too because when you want to go to bed/wake up, it's not time yet, so you have to wait another hour to get to your normal time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant