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

Fixed loading Bedrock chunks with no palette #194

Merged
merged 2 commits into from
May 11, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from typing import Tuple, Dict, List, Union, Iterable, Optional, TYPE_CHECKING, Any

import struct
import logging

import numpy
import amulet_nbt

Expand Down Expand Up @@ -31,6 +32,8 @@
from amulet.api.chunk.blocks import Blocks
from amulet.api.wrapper import Translator

log = logging.getLogger(__name__)

# This is here to scale a 4x array to a 16x array. This can be removed when we natively support 16x array
_scale_grid = tuple(numpy.meshgrid(*[numpy.arange(16) // 4] * 3, indexing="ij"))

Expand Down Expand Up @@ -649,21 +652,35 @@ def _load_palette_blocks(
data: bytes,
) -> Tuple[numpy.ndarray, List[amulet_nbt.NBTFile], bytes]:
data, _, blocks = self._decode_packed_array(data)
if blocks is not None:
if blocks is None:
blocks = numpy.zeros((16, 16, 16), dtype=numpy.int16)
palette_len = 1
else:
palette_len, data = struct.unpack("<I", data[:4])[0], data[4:]

if palette_len:
palette, offset = amulet_nbt.load(
data,
compressed=False,
count=palette_len,
offset=True,
little_endian=True,
)
return blocks, palette, data[offset:]
data = data[offset:]
else:
palette, offset = amulet_nbt.load(
data, compressed=False, count=1, offset=True, little_endian=True
)
return numpy.zeros((16, 16, 16), dtype=numpy.int16), palette, data[offset:]
palette = [
amulet_nbt.NBTFile(
amulet_nbt.TAG_Compound(
{
"name": amulet_nbt.TAG_String("minecraft:air"),
"states": amulet_nbt.TAG_Compound(),
"version": amulet_nbt.TAG_Int(17694723),
}
)
)
]

return blocks, palette, data

@staticmethod
def _encode_packed_array(arr: numpy.ndarray, min_bit_size=1) -> bytes:
Expand Down