Improve labeled chest caching interactions
This commit is contained in:
+29
-11
@@ -26,7 +26,8 @@ from mosfet.protocol.packets import (
|
||||
|
||||
from mosfet.protocol.types import Slot
|
||||
from mosfet.protocol.modern import (
|
||||
ClientCommandPacket, PlayerCommandPacket, UpdateTimePacket, UseItemPacket,
|
||||
ClientCommandPacket, PlayerCommandPacket, PlayerInputPacket,
|
||||
UpdateTimePacket, UseItemPacket,
|
||||
)
|
||||
|
||||
from mosfet import utils
|
||||
@@ -386,14 +387,18 @@ class LegacyGame:
|
||||
|
||||
def open_container(self, location):
|
||||
location = tuple(int(value) for value in location)
|
||||
bid = self.g.chunks.get_block_at(*location)
|
||||
block_name = blocks.BLOCKS.get(bid)
|
||||
if (block_name and block_name != 'ender_chest' and
|
||||
(block_name == 'chest' or block_name.endswith('_chest'))):
|
||||
self.g.pending_chest_open = {
|
||||
'position': location,
|
||||
'requested_at': time.monotonic(),
|
||||
}
|
||||
positions = {location}
|
||||
world = self.g.get('world')
|
||||
if world and hasattr(world, '_double_chest_positions'):
|
||||
positions.update(world._double_chest_positions(location))
|
||||
for offset in ((1, 0, 0), (-1, 0, 0), (0, 0, 1),
|
||||
(0, 0, -1), (0, 1, 0), (0, -1, 0)):
|
||||
positions.add(utils.padd(location, offset))
|
||||
self.g.pending_chest_open = {
|
||||
'position': location,
|
||||
'positions': tuple(sorted(positions)),
|
||||
'requested_at': time.monotonic(),
|
||||
}
|
||||
self.place_block(location, BlockFace.TOP)
|
||||
|
||||
def handle_window(self, packet):
|
||||
@@ -1042,7 +1047,8 @@ class Game(LegacyGame):
|
||||
self.g.connection.write_packet(ClientTickEnd(), force=True)
|
||||
return True
|
||||
|
||||
def place_block(self, location, face, hand=0, cursor_y=None):
|
||||
def place_block(self, location, face, hand=0, cursor_y=None,
|
||||
sneaking=False):
|
||||
location = tuple(int(value) for value in location)
|
||||
if cursor_y is None:
|
||||
cursor_y = 0.99 if int(face) == 1 else 0.5
|
||||
@@ -1051,7 +1057,18 @@ class Game(LegacyGame):
|
||||
cursor_x=0.5, cursor_y=cursor_y,
|
||||
cursor_z=0.5, inside_block=False, world_border_hit=False,
|
||||
sequence=self._next_sequence())
|
||||
self._send_action(packet)
|
||||
if sneaking:
|
||||
self.g.connection.write_packet(PlayerInputPacket(flags=0x20),
|
||||
force=True)
|
||||
self.g.connection.write_packet(ClientTickEnd(), force=True)
|
||||
try:
|
||||
self._send_action(packet)
|
||||
finally:
|
||||
self.g.connection.write_packet(PlayerInputPacket(flags=0),
|
||||
force=True)
|
||||
self.g.connection.write_packet(ClientTickEnd(), force=True)
|
||||
else:
|
||||
self._send_action(packet)
|
||||
|
||||
def count_window_slots(self):
|
||||
window = self.g.get('window')
|
||||
@@ -1083,3 +1100,4 @@ class Game(LegacyGame):
|
||||
self.g.connection.write_packet(ContainerClosePacket(
|
||||
container_id=window.window_id), force=True)
|
||||
self.g.window = None
|
||||
self.g.pending_chest_open = None
|
||||
|
||||
Reference in New Issue
Block a user