conflicts

This commit is contained in:
Brian Merriam 2023-03-21 01:54:31 +00:00
commit 3441d42d83
4 changed files with 122 additions and 1 deletions

View File

@ -22,6 +22,7 @@ from .explosion_packet import ExplosionPacket
from .sound_effect_packet import SoundEffectPacket
from .face_player_packet import FacePlayerPacket
from .join_game_and_respawn_packets import JoinGamePacket, RespawnPacket
from .tab_complete_packet import TabCompletePacket
# Formerly known as state_playing_clientbound.
@ -76,7 +77,11 @@ def get_packets(context):
packets |= {
FacePlayerPacket
}
if context.protocol_later_eq(345) or \
context.protocol_earlier_eq(342):
packets |= {
TabCompletePacket,
}
return packets

View File

@ -0,0 +1,60 @@
from minecraft.networking.packets import Packet
from minecraft.networking.types import VarInt, Boolean, String, MutableRecord
class TabCompletePacket(Packet):
@staticmethod
def get_id(context):
return 0x0F if context.protocol_later_eq(741) else \
0x10 if context.protocol_later_eq(721) else \
0x11 if context.protocol_later_eq(550) else \
0x10 if context.protocol_later_eq(345) else \
0x0E if context.protocol_later_eq(332) else \
0x0F if context.protocol_later_eq(318) else \
0x0E if context.protocol_later_eq(70) else \
0x3A
packet_name = 'tab complete'
@property
def fields(self):
fields = 'matches',
if self.context.protocol_later_eq(346):
fields += 'transaction_id', 'start', 'length',
return fields
class TabMatch(MutableRecord):
__slots__ = ('match', 'tooltip')
def __init__(self, match, tooltip=None):
self.match = match
self.tooltip = tooltip
def read(self, file_object):
if self.context.protocol_later_eq(346):
self.transaction_id = VarInt.read(file_object)
self.start = VarInt.read(file_object)
self.length = VarInt.read(file_object)
count = VarInt.read(file_object)
self.matches = []
for i in range(count):
match = String.read(file_object)
has_tooltip = False
if self.context.protocol_later_eq(357):
has_tooltip = Boolean.read(file_object)
tooltip = String.read(file_object) if has_tooltip else None
tabmatch = TabCompletePacket.TabMatch(match, tooltip)
self.matches.append(tabmatch)
def write_fields(self, packet_buffer):
if self.context.protocol_later_eq(346):
VarInt.send(self.transaction_id, packet_buffer)
VarInt.send(self.start, packet_buffer)
VarInt.send(self.length, packet_buffer)
VarInt.send(len(self.matches), packet_buffer)
for tabmatch in self.matches:
String.send(tabmatch.match, packet_buffer)
if self.context.protocol_later_eq(357):
Boolean.send(tabmatch.tooltip is not None, packet_buffer)
if tabmatch.tooltip is not None:
String.send(tabmatch.tooltip, packet_buffer)

View File

@ -9,6 +9,7 @@ from minecraft.networking.types import (
)
from .client_settings_packet import ClientSettingsPacket
from .tab_complete_packet import TabCompletePacket
# Formerly known as state_playing_serverbound.
@ -31,6 +32,12 @@ def get_packets(context):
packets |= {
TeleportConfirmPacket,
}
# For some reason this packet did not exist on protocols 343 & 344.
if context.protocol_later_eq(345) or \
context.protocol_earlier_eq(342):
packets |= {
TabCompletePacket,
}
return packets

View File

@ -0,0 +1,49 @@
from minecraft.networking.types import VarInt, Boolean, Position, String
from minecraft.networking.packets import Packet
class TabCompletePacket(Packet):
@staticmethod
def get_id(context):
return 0x06 if context.protocol_later_eq(464) else \
0x05 if context.protocol_later_eq(389) else \
0x04 if context.protocol_later_eq(345) else \
0x01 if context.protocol_later_eq(336) else \
0x02 if context.protocol_later_eq(318) else \
0x01 if context.protocol_later_eq(94) else \
0x00 if context.protocol_later_eq(70) else \
0x15 if context.protocol_later_eq(69) else \
0x14
packet_name = 'tab complete'
@property
def fields(self):
fields = 'text',
if self.context.protocol_later_eq(351):
fields += 'transaction_id'
else:
fields += 'has_position', 'looked_at_block',
if self.context.protocol_later_eq(95):
fields += 'assume_command'
def read(self, file_object):
self.transaction_id = VarInt.read(file_object) \
if self.context.protocol_later_eq(351) else None
self.text = String.read(file_object)
if self.context.protocol_earlier_eq(350):
self.assume_command = Boolean.read(file_object) \
if self.context.protocol_later_eq(95) else None
has_position = Boolean.read(file_object)
if has_position:
self.looked_at_block = Position.read(file_object)
def write_fields(self, packet_buffer):
if self.context.protocol_later_eq(351):
VarInt.send(self.transaction_id, packet_buffer)
String.send(self.text, packet_buffer)
if self.context.protocol_earlier_eq(350):
if self.context.protocol_later_eq(95):
Boolean.send(self.assume_command, packet_buffer)
Boolean.send(self.looked_at_block is not None, packet_buffer)
if self.looked_at_block is not None:
Position.send(self.looked_at_block, packet_buffer)