Querz / NBT

A java implementation of the NBT protocol, including a way to implement custom tags.
MIT License
182 stars 48 forks source link

Deserialize crashes on empty sections #31

Closed prydin closed 5 years ago

prydin commented 5 years ago

With Minecraft 1.14, there are sometimes empty sections in the chunks. They look something like this:

image

Not sure why they appear, but they should be handled gracefully.

The code in Chunk.deserialize() tries to create a new Section here: https://github.com/Querz/NBT/blob/8cedf1e24d65f2e857f42e88453c7161ab53db38/src/main/java/net/querz/nbt/mca/Chunk.java#L76

...but fails on a NullPointerException in the Section constructor since there's no Palette member here: https://github.com/Querz/NBT/blob/8cedf1e24d65f2e857f42e88453c7161ab53db38/src/main/java/net/querz/nbt/mca/Section.java#L21

Querz commented 5 years ago

Ah yes, I faced this problem already some time ago in the MCASelector but didn't think this would be a problem here. I'll fix that this weekend.

Querz commented 5 years ago

I added an extra check for sections that have a Y index outside of 0-15 and a check for palette content. Empty sections like those added by Minecraft will be treated as non-existent.

The changes are currently available with the latest commit on the master branch, if everything works fine i'll make a release.

prydin commented 5 years ago

I uncovered another issue. Sometimes you have a valid index, but the section is still empty (or at least missing the Palette). Here's how I addressed that:

https://github.com/prydin/NBT/blob/18761711dc4b88ecb3a68dd8e53b746693ffbbb9/src/main/java/net/querz/nbt/mca/Chunk.java#L75

Querz commented 5 years ago

Yes, I also addressed this issue, see https://github.com/Querz/NBT/blob/master/src/main/java/net/querz/nbt/mca/Section.java#L21 If a Section is missing the Palette, it will be "empty" and won't be added to the chunk: https://github.com/Querz/NBT/blob/master/src/main/java/net/querz/nbt/mca/Chunk.java#L75