Skip to content

Commit

Permalink
Fix chunk deserialization (#362)
Browse files Browse the repository at this point in the history
Update Region.cs
  • Loading branch information
Tides committed May 30, 2023
1 parent d6171e4 commit f7bf0c6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Obsidian/WorldData/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,13 @@ private static Chunk DeserializeChunk(NbtCompound chunkCompound)

var section = chunk.Sections[secY + 4];

if (statesCompound.TryGetTag("data", out var dataArrayTag))
{
var data = dataArrayTag as NbtArray<long>;

section.BlockStateContainer.DataArray.storage = data!.GetArray();
}

var chunkSecPalette = section.BlockStateContainer.Palette;

if (statesCompound.TryGetTag("palette", out var palleteArrayTag))
if (statesCompound!.TryGetTag("palette", out var palleteArrayTag))
{
var blockStatesPalette = palleteArrayTag as NbtList;
foreach (NbtCompound entry in blockStatesPalette)
foreach (NbtCompound entry in blockStatesPalette!)
{
var name = entry.GetString("Name");
var id = entry.GetInt("Id");

chunkSecPalette.GetOrAddId(BlocksRegistry.Get(id));//TODO PROCESS ADDED PROPERTIES TO GET CORRECT BLOCK STATE
Expand All @@ -204,6 +196,14 @@ private static Chunk DeserializeChunk(NbtCompound chunkCompound)
section.BlockStateContainer.GrowDataArray();
}

//TODO find a way around this (We shouldn't be storing the states data array in nbt anyway.)
if (statesCompound.TryGetTag("data", out var dataArrayTag))
{
var data = dataArrayTag as NbtArray<long>;

section.BlockStateContainer.DataArray.storage = data!.GetArray();
}

var biomesCompound = sectionCompound["biomes"] as NbtCompound;
var biomesPalette = biomesCompound!["palette"] as NbtList;

Expand Down

0 comments on commit f7bf0c6

Please sign in to comment.