From 6cf6e25ca5472cbc07cb6b5d71b00455eb2e7cdd Mon Sep 17 00:00:00 2001 From: PREMIEREHELL <88470674+PREMIEREHELL@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:30:09 -0700 Subject: [PATCH 1/6] Java lighting --- .../interfaces/chunk/anvil/anvil_1934.py | 32 +++++++++++++++++++ .../interfaces/chunk/anvil/anvil_2844.py | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/amulet/level/interfaces/chunk/anvil/anvil_1934.py b/amulet/level/interfaces/chunk/anvil/anvil_1934.py index bb13f74d7..6e0010528 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_1934.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_1934.py @@ -1,20 +1,52 @@ 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): """ Made lighting optional + Made game recalculate lighting """ + isLightOn: ChunkPathType = ( + "region", + [("Level", CompoundTag), ("isLightOn", ByteTag)], + ByteTag, + ) + def __init__(self): super().__init__() self._set_feature("light_optional", "true") + self._register_encoder(self._encode_islighton) + self._register_decoder(self._decode_islighton) @staticmethod def minor_is_valid(key: int): return 1934 <= key < 2203 + 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 + ): + + if chunk.misc.pop("isLightOn", None): + self.set_layer_obj(data, self.isLightOn, ByteTag(0)) + export = Anvil1934Interface 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) From 4f6382396c9d23432f20dc38bf498f85ce3c48a5 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 12 Jun 2024 09:18:46 +0100 Subject: [PATCH 2/6] Renamed methods --- amulet/level/interfaces/chunk/anvil/anvil_1934.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/amulet/level/interfaces/chunk/anvil/anvil_1934.py b/amulet/level/interfaces/chunk/anvil/anvil_1934.py index 6e0010528..1581c2b83 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_1934.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_1934.py @@ -27,21 +27,21 @@ class Anvil1934Interface(ParentInterface): def __init__(self): super().__init__() self._set_feature("light_optional", "true") - self._register_encoder(self._encode_islighton) - self._register_decoder(self._decode_islighton) + self._register_encoder(self._encode_is_light_on) + self._register_decoder(self._decode_is_light_on) @staticmethod def minor_is_valid(key: int): return 1934 <= key < 2203 - def _decode_islighton( + def _decode_is_light_on( 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( + def _encode_is_light_on( self, chunk: Chunk, data: ChunkDataType, floor_cy: int, height_cy: int ): From f7b3785eebd7dd3f854015b5d21a4a3d68ee8f29 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 12 Jun 2024 09:18:59 +0100 Subject: [PATCH 3/6] Removed unused imports --- amulet/level/interfaces/chunk/anvil/anvil_1934.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amulet/level/interfaces/chunk/anvil/anvil_1934.py b/amulet/level/interfaces/chunk/anvil/anvil_1934.py index 1581c2b83..7feb0c802 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_1934.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_1934.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import List, Tuple, TYPE_CHECKING +from typing import TYPE_CHECKING if TYPE_CHECKING: from amulet.api.chunk import Chunk From e4cb361bca3eae6bc6b8a8788a432ed44b843dce Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 12 Jun 2024 09:19:08 +0100 Subject: [PATCH 4/6] Remove docstring --- amulet/level/interfaces/chunk/anvil/anvil_1934.py | 1 - 1 file changed, 1 deletion(-) diff --git a/amulet/level/interfaces/chunk/anvil/anvil_1934.py b/amulet/level/interfaces/chunk/anvil/anvil_1934.py index 7feb0c802..d6176b34b 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_1934.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_1934.py @@ -15,7 +15,6 @@ class Anvil1934Interface(ParentInterface): """ Made lighting optional - Made game recalculate lighting """ isLightOn: ChunkPathType = ( From b4951fd4c487b90bbae304e1543643831dc75db7 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 12 Jun 2024 09:19:27 +0100 Subject: [PATCH 5/6] Fix setting isLightOn --- amulet/level/interfaces/chunk/anvil/anvil_1934.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/amulet/level/interfaces/chunk/anvil/anvil_1934.py b/amulet/level/interfaces/chunk/anvil/anvil_1934.py index d6176b34b..cd7d2d4de 100644 --- a/amulet/level/interfaces/chunk/anvil/anvil_1934.py +++ b/amulet/level/interfaces/chunk/anvil/anvil_1934.py @@ -43,9 +43,8 @@ def _decode_is_light_on( def _encode_is_light_on( self, chunk: Chunk, data: ChunkDataType, floor_cy: int, height_cy: int ): - - if chunk.misc.pop("isLightOn", None): - self.set_layer_obj(data, self.isLightOn, ByteTag(0)) + is_light_on = bool(chunk.misc.pop("isLightOn", None)) + self.set_layer_obj(data, self.isLightOn, ByteTag(is_light_on)) export = Anvil1934Interface From b1ef23b1bf10c8c7427e12d8b95b2e2b548d9acb Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 12 Jun 2024 09:20:02 +0100 Subject: [PATCH 6/6] Re-enable calculate light --- amulet/level/formats/anvil_world/format.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/amulet/level/formats/anvil_world/format.py b/amulet/level/formats/anvil_world/format.py index b760640d2..c3bdb0b52 100644 --- a/amulet/level/formats/anvil_world/format.py +++ b/amulet/level/formats/anvil_world/format.py @@ -495,14 +495,14 @@ 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 + return height_changed or light_changed @staticmethod def _calculate_height( @@ -553,6 +553,7 @@ def _calculate_light( 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) if changed_: changed = True chunk.changed = True