diff --git a/amulet/level/formats/anvil_world/format.py b/amulet/level/formats/anvil_world/format.py index b760640d2..dafabf064 100644 --- a/amulet/level/formats/anvil_world/format.py +++ b/amulet/level/formats/anvil_world/format.py @@ -495,12 +495,12 @@ def pre_save_operation( except StopIteration as e: height_changed = e.value - # light = self._calculate_light(level, changed_chunks) - # try: - # while True: - # yield next(light) / 2 - # except StopIteration as e: - # light_changed = e.value + light = self._calculate_light(level, changed_chunks) + try: + while True: + yield next(light) / 2 + except StopIteration as e: + light_changed = e.value return height_changed # or light_changed @@ -539,11 +539,24 @@ def _calculate_light( changed = False if level.level_wrapper.version < 1934: # the version may be less than 1934 but is at least 1924 - # calculate the light values + # TODO need to calculate the light values for 1,12 > 1.13. + # for i, (dimension, cx, cz) in enumerate(chunks): + # try: + # chunk = level.get_chunk(cx, cz, dimension) + # except ChunkLoadError: + # pass + # else: + # changed_ = False + # changed_ |= chunk.misc.pop("block_light", None) is not None Needs better + # changed_ |= chunk.misc.pop("sky_light", None) is not None + # if changed_: + # changed = True + # chunk.changed = True + # yield i / chunk_count pass - # TODO else: # the game will recalculate the light levels + # applies to versions (19w08b) 1934 to 3949 (1.21.Pre2) for i, (dimension, cx, cz) in enumerate(chunks): try: chunk = level.get_chunk(cx, cz, dimension) @@ -551,8 +564,7 @@ def _calculate_light( pass else: changed_ = False - changed_ |= chunk.misc.pop("block_light", None) is not None - changed_ |= chunk.misc.pop("sky_light", None) is not None + changed_ |= chunk.misc.pop("isLightOn", None) is not None if changed_: changed = True chunk.changed = True diff --git a/amulet/level/interfaces/chunk/anvil/anvil_1934.py b/amulet/level/interfaces/chunk/anvil/anvil_1934.py index bb13f74d7..b19bd0b68 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_1934.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_1934.py @@ -1,17 +1,51 @@ from __future__ import annotations +from typing import List, Tuple, TYPE_CHECKING + +if TYPE_CHECKING: + from amulet.api.chunk import Chunk + +from amulet_nbt import CompoundTag, ByteTag + +from .base_anvil_interface import ChunkDataType, ChunkPathType + from .anvil_1912 import Anvil1912Interface as ParentInterface class Anvil1934Interface(ParentInterface): + isLightOn: ChunkPathType = ( + "region", + [("Level", CompoundTag), ("isLightOn", ByteTag)], + ByteTag, + ) """ Made lighting optional + Made game recalculate lighting """ def __init__(self): super().__init__() self._set_feature("light_optional", "true") + self._register_decoder(self._decode_islighton) + self._register_encoder(self._encode_islighton) + + def _decode_islighton( + self, chunk: Chunk, data: ChunkDataType, floor_cy: int, height_cy: int + ): + chunk.misc["isLightOn"] = self.get_layer_obj( + data, self.isLightOn, pop_last=True + ) + + def _encode_islighton( + self, chunk: Chunk, data: ChunkDataType, floor_cy: int, height_cy: int + ): + self.set_layer_obj( + data, + self.isLightOn, + chunk.misc.get("isLightOn", None), + ) + @staticmethod def minor_is_valid(key: int): return 1934 <= key < 2203 diff --git a/amulet/level/interfaces/chunk/anvil/anvil_2844.py b/amulet/level/interfaces/chunk/anvil/anvil_2844.py index 6c21c0018..24991e7a9 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_2844.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_2844.py @@ -57,7 +57,7 @@ class Anvil2844Interface(ParentInterface): OldLevel: ChunkPathType = ("region", [("Level", CompoundTag)], CompoundTag) Level: ChunkPathType = ("region", [], CompoundTag) Sections: ChunkPathType = ("region", [("sections", ListTag)], ListTag) - + isLightOn: ChunkPathType = ("region", [("isLightOn", ByteTag)], ByteTag) Entities: ChunkPathType = ("region", [("entities", ListTag)], ListTag) BlockEntities: ChunkPathType = ("region", [("block_entities", ListTag)], ListTag) BlockTicks: ChunkPathType = ("region", [("block_ticks", ListTag)], ListTag)