Offroaders123 / NBTify

A library to read and write NBT files on the web!
http://npm.im/nbtify
MIT License
42 stars 5 forks source link

Run-Time List Item Type Check #14

Closed Offroaders123 closed 1 year ago

Offroaders123 commented 1 year ago

At the NBT writing stage, add a check that ensures all list items are of the same type as the first item in the list. If they aren't, it will throw a writing error.

Offroaders123 commented 1 year ago

Added the check for this! Now if you try to serialize your NBT structure, and it has a ListTag with items of multiple types, it will throw an error when it finds the first item of a different type than the first item in the array.

To help prevent this from happening, it helps to define the item type for the ListTags in your NBT objects using type definitions, so then you can get pre-run time linting errors before the buffer writing errors happen, say if you were using TypeScript, or @ts-check or allowJS/checkJS with JavaScript.

Offroaders123 commented 1 year ago

I have to implement this behavior for the SNBT parser too, as that doesn't correctly handle this case yet.