Read nearby 26.3 sign text

This commit is contained in:
Tanner
2026-11-05 23:47:05 +00:00
parent 09035793e2
commit c323ea8373
4 changed files with 179 additions and 2 deletions
+27 -2
View File
@@ -4,8 +4,9 @@ from munch import Munch
from minecraft.networking.packets import clientbound, serverbound
from minecraft.networking.modern import (
AddEntityPacket, ContainerOpenPacket, ContainerSetContentPacket,
ContainerSetSlotPacket, SetEntityDataPacket,
AddEntityPacket, BlockEntityDataPacket, ContainerOpenPacket,
ContainerSetContentPacket, ContainerSetSlotPacket, SetEntityDataPacket,
nbt_plain,
PaletteSection,
EntityPositionSyncPacket, MoveEntityPositionPacket,
MoveEntityPositionRotationPacket, MoveEntityRotationPacket,
@@ -218,6 +219,7 @@ class WorldState:
self.min_section = min_y // 16
self.chunks = {}
self.index = {}
self.block_entities = {}
from mosfet.info import blocks
self.indexed_ids = blocks.INDEXED_IDS
self.center = None
@@ -242,6 +244,10 @@ class WorldState:
chunk = ChunkColumn(packet.x, packet.z, packet.sections,
self.min_section)
self.chunks[(packet.x, packet.z)] = chunk
for entity in getattr(packet, 'block_entities', []):
pos = (entity['x'], entity['y'], entity['z'])
self.set_block_entity(
pos, entity['type'], entity.get('data'))
for section_y, section in chunk.sections.items():
palette = section['blocks']
if not self.indexed_ids.intersection(
@@ -275,6 +281,12 @@ class WorldState:
return None
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)] = {
'type': entity_type,
'data': nbt_plain(data),
}
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))
@@ -300,10 +312,16 @@ class WorldState:
}
if not self.index[state_id]:
del self.index[state_id]
self.block_entities = {
pos: entity for pos, entity in self.block_entities.items()
if not (x0 <= pos[0] < x0 + 16 and
z0 <= pos[2] < z0 + 16)
}
def unload_all_chunks(self):
self.chunks.clear()
self.index.clear()
self.block_entities.clear()
def get_loaded_area(self, ignore_empty=False):
if not self.chunks:
@@ -348,6 +366,7 @@ class EntityManager:
for packet_type, handler in (
(AddEntityPacket, self.handle_add_entity),
(SetEntityDataPacket, self.handle_entity_data),
(BlockEntityDataPacket, self.handle_block_entity_data),
(RemoveEntitiesPacket, self.handle_remove_entities),
(MoveEntityPositionPacket, self.handle_move),
(MoveEntityPositionRotationPacket, self.handle_move),
@@ -379,6 +398,12 @@ class EntityManager:
type=packet.entity_type_id, yaw=packet.yaw,
pitch=packet.pitch)
def handle_block_entity_data(self, packet):
location = packet.location
self.g.chunks.set_block_entity(
(location.x, location.y, location.z),
packet.block_entity_type, packet.data)
def handle_entity_data(self, packet):
obj = self.g.objects.get(packet.entity_id)
if obj is None or not packet.item_stacks: