Clear stale sign data when signs break

This commit is contained in:
Tanner
2026-11-07 23:21:41 +00:00
parent 11add13779
commit 930f4f3868
3 changed files with 67 additions and 1 deletions
+14 -1
View File
@@ -283,11 +283,21 @@ class WorldState:
return chunk.get_block_at(floor(x), floor(y), floor(z))
def set_block_entity(self, position, entity_type, data):
self.block_entities[tuple(position)] = {
position = tuple(position)
if data is None:
self.block_entities.pop(position, None)
return
self.block_entities[position] = {
'type': entity_type,
'data': nbt_plain(data),
}
@staticmethod
def _is_sign_state(block_state_id):
from mosfet.info import blocks
name = blocks.BLOCKS.get(block_state_id)
return name is not None and name.endswith('_sign')
def set_block_at(self, x, y, z, block_state_id):
x, y, z = floor(x), floor(y), floor(z)
chunk = self.get_chunk(floor(x / 16), floor(z / 16))
@@ -297,6 +307,9 @@ class WorldState:
pos = (x, y, z)
if previous in self.indexed_ids:
self.index.get(previous, set()).discard(pos)
if (self._is_sign_state(previous) and
not self._is_sign_state(block_state_id)):
self.block_entities.pop(pos, None)
if block_state_id in self.indexed_ids:
self.index.setdefault(block_state_id, set()).add(pos)
return True