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
+11
View File
@@ -25,6 +25,11 @@ class World:
def block_at(self, x, y, z):
return self.g.chunks.get_block_at(x, y, z)
@staticmethod
def _is_sign_state(state_id):
name = blocks.BLOCKS.get(state_id)
return name is not None and name.endswith('_sign')
@staticmethod
def _sign_component_text(value):
if value is None:
@@ -58,6 +63,12 @@ class World:
for position, entity in self.g.chunks.block_entities.items():
if utils.phyp(center, position) > distance:
continue
get_block_at = getattr(self.g.chunks, 'get_block_at', None)
if callable(get_block_at):
state_id = get_block_at(*position)
if (state_id is not None and
not self._is_sign_state(state_id)):
continue
data = entity.get('data') or {}
for side in ('front', 'back'):
text_data = data.get(side + '_text')