Improve labeled chest caching interactions

This commit is contained in:
Tanner
2026-11-07 18:23:55 +00:00
parent 34d902c46d
commit 688297e968
7 changed files with 240 additions and 25 deletions
+20 -5
View File
@@ -365,6 +365,7 @@ class ChestOpenManager:
self.g.chest_viewers = self.g.get('chest_viewers') or {}
self.g.chest_open_events = self.g.get('chest_open_events') or []
self.g.last_chest_opened_by_other = None
self._own_open_suppressions = {}
self.g.connection.register_packet_listener(
self.handle_block_event, BlockEventPacket)
@@ -396,17 +397,31 @@ class ChestOpenManager:
else:
self.g.chest_viewers.pop(position, None)
now = time.monotonic()
self._own_open_suppressions = {
pos: expires for pos, expires in self._own_open_suppressions.items()
if expires > now
}
pending = self.g.get('pending_chest_open')
pending_age = (time.monotonic() - pending.get('requested_at', 0)
pending_age = (now - pending.get('requested_at', 0)
if pending is not None else None)
pending_is_fresh = (pending_age is not None and
0 <= pending_age <= self.OWN_OPEN_TIMEOUT)
is_bot_opening = (
pending_is_fresh and
tuple(pending.get('position', ())) == position
pending_positions = (
pending.get('positions') or (pending.get('position', ()),)
if pending is not None else ()
)
if pending is not None and (is_bot_opening or not pending_is_fresh):
pending_positions = {tuple(pos) for pos in pending_positions}
is_bot_opening = (
pending_is_fresh and position in pending_positions
)
if pending is not None and not pending_is_fresh:
self.g.pending_chest_open = None
if is_bot_opening:
for own_position in pending_positions:
self._own_open_suppressions[own_position] = now + 0.5
is_bot_opening = (is_bot_opening or
position in self._own_open_suppressions)
if (viewers <= previous_viewers or
(is_bot_opening and
+10 -1
View File
@@ -4,7 +4,9 @@ import time
from contextlib import nullcontext
from minecraft.networking.packets import Packet
from minecraft.networking.types import Float, Long, VarInt, VarLong
from minecraft.networking.types import (
Float, Long, UnsignedByte, VarInt, VarLong,
)
from minecraft.networking.modern import (
ChatCommand, ClientboundPlayerChatPacket, ServerboundChatPacket, SystemChat,
)
@@ -29,6 +31,13 @@ class UpdateTimePacket(Packet):
})
class PlayerInputPacket(Packet):
"""Serverbound key state, including sneak for container-safe placement."""
id = 0x2B
packet_name = 'player input'
definition = [{'flags': UnsignedByte}]
class PlayerCommandPacket(Packet):
"""Client player-command packet; action 0 stops sleeping (protocol 777)."""
id = 0x2A