Implement item cachine for 26.3
This commit is contained in:
+50
-2
@@ -48,6 +48,27 @@ class ContainerClickDropPacket(Packet):
|
||||
VarInt.send(0, packet_buffer) # empty carried item stack
|
||||
|
||||
|
||||
class ContainerClickQuickMovePacket(Packet):
|
||||
"""Shift-click an inventory slot into the open container (protocol 777)."""
|
||||
id = 0x12
|
||||
packet_name = 'container click quick move'
|
||||
|
||||
def write_fields(self, packet_buffer):
|
||||
VarInt.send(self.container_id, packet_buffer)
|
||||
VarInt.send(self.state_id, packet_buffer)
|
||||
Short.send(self.slot, packet_buffer)
|
||||
Byte.send(0, packet_buffer) # mouse button
|
||||
VarInt.send(1, packet_buffer) # ContainerInput.QUICK_MOVE
|
||||
VarInt.send(0, packet_buffer) # no changed-slot predictions
|
||||
VarInt.send(0, packet_buffer) # empty carried item stack
|
||||
|
||||
|
||||
class ContainerClosePacket(Packet):
|
||||
id = 0x13
|
||||
packet_name = 'container close'
|
||||
definition = [{'container_id': VarInt}]
|
||||
|
||||
|
||||
class LegacyGame:
|
||||
def __init__(self, global_state):
|
||||
self.g = global_state
|
||||
@@ -795,6 +816,33 @@ class Game(LegacyGame):
|
||||
sequence=self._next_sequence())
|
||||
self._send_action(packet)
|
||||
|
||||
def count_window_slots(self):
|
||||
window = self.g.get('window')
|
||||
if not window:
|
||||
return 0
|
||||
return sum(
|
||||
item.present
|
||||
for slot, item in window.contents.items()
|
||||
if slot < window.container_slots)
|
||||
|
||||
def click_window(self, slot, button=0, mode=1, item=None):
|
||||
window = self.g.get('window')
|
||||
if not window:
|
||||
return False
|
||||
packet = ContainerClickQuickMovePacket(
|
||||
container_id=window.window_id,
|
||||
state_id=self.g.inventory_state_ids.get(
|
||||
window.window_id, window.state_id),
|
||||
slot=slot,
|
||||
)
|
||||
self.g.connection.write_packet(packet, force=True)
|
||||
self.g.connection.write_packet(ClientTickEnd(), force=True)
|
||||
return True
|
||||
|
||||
def close_window(self):
|
||||
# Container open/close packet migration is not part of the crop path.
|
||||
return None
|
||||
window = self.g.get('window')
|
||||
if not window:
|
||||
return None
|
||||
self.g.connection.write_packet(ContainerClosePacket(
|
||||
container_id=window.window_id), force=True)
|
||||
self.g.window = None
|
||||
|
||||
Reference in New Issue
Block a user