Skip to content

Commit 6248525

Browse files
Merge branch 'datatags-master'
2 parents b709df4 + 3441d42 commit 6248525

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

minecraft/networking/packets/clientbound/play/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .sound_effect_packet import SoundEffectPacket
2323
from .face_player_packet import FacePlayerPacket
2424
from .join_game_and_respawn_packets import JoinGamePacket, RespawnPacket
25+
from .tab_complete_packet import TabCompletePacket
2526

2627

2728
# Formerly known as state_playing_clientbound.
@@ -76,7 +77,11 @@ def get_packets(context):
7677
packets |= {
7778
FacePlayerPacket
7879
}
79-
80+
if context.protocol_later_eq(345) or \
81+
context.protocol_earlier_eq(342):
82+
packets |= {
83+
TabCompletePacket,
84+
}
8085
return packets
8186

8287

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from minecraft.networking.packets import Packet
2+
from minecraft.networking.types import VarInt, Boolean, String, MutableRecord
3+
4+
5+
class TabCompletePacket(Packet):
6+
@staticmethod
7+
def get_id(context):
8+
return 0x0F if context.protocol_later_eq(741) else \
9+
0x10 if context.protocol_later_eq(721) else \
10+
0x11 if context.protocol_later_eq(550) else \
11+
0x10 if context.protocol_later_eq(345) else \
12+
0x0E if context.protocol_later_eq(332) else \
13+
0x0F if context.protocol_later_eq(318) else \
14+
0x0E if context.protocol_later_eq(70) else \
15+
0x3A
16+
17+
packet_name = 'tab complete'
18+
19+
@property
20+
def fields(self):
21+
fields = 'matches',
22+
if self.context.protocol_later_eq(346):
23+
fields += 'transaction_id', 'start', 'length',
24+
return fields
25+
26+
class TabMatch(MutableRecord):
27+
__slots__ = ('match', 'tooltip')
28+
29+
def __init__(self, match, tooltip=None):
30+
self.match = match
31+
self.tooltip = tooltip
32+
33+
def read(self, file_object):
34+
if self.context.protocol_later_eq(346):
35+
self.transaction_id = VarInt.read(file_object)
36+
self.start = VarInt.read(file_object)
37+
self.length = VarInt.read(file_object)
38+
count = VarInt.read(file_object)
39+
self.matches = []
40+
for i in range(count):
41+
match = String.read(file_object)
42+
has_tooltip = False
43+
if self.context.protocol_later_eq(357):
44+
has_tooltip = Boolean.read(file_object)
45+
tooltip = String.read(file_object) if has_tooltip else None
46+
tabmatch = TabCompletePacket.TabMatch(match, tooltip)
47+
self.matches.append(tabmatch)
48+
49+
def write_fields(self, packet_buffer):
50+
if self.context.protocol_later_eq(346):
51+
VarInt.send(self.transaction_id, packet_buffer)
52+
VarInt.send(self.start, packet_buffer)
53+
VarInt.send(self.length, packet_buffer)
54+
VarInt.send(len(self.matches), packet_buffer)
55+
for tabmatch in self.matches:
56+
String.send(tabmatch.match, packet_buffer)
57+
if self.context.protocol_later_eq(357):
58+
Boolean.send(tabmatch.tooltip is not None, packet_buffer)
59+
if tabmatch.tooltip is not None:
60+
String.send(tabmatch.tooltip, packet_buffer)

minecraft/networking/packets/serverbound/play/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010

1111
from .client_settings_packet import ClientSettingsPacket
12+
from .tab_complete_packet import TabCompletePacket
1213

1314

1415
# Formerly known as state_playing_serverbound.
@@ -31,6 +32,12 @@ def get_packets(context):
3132
packets |= {
3233
TeleportConfirmPacket,
3334
}
35+
# For some reason this packet did not exist on protocols 343 & 344.
36+
if context.protocol_later_eq(345) or \
37+
context.protocol_earlier_eq(342):
38+
packets |= {
39+
TabCompletePacket,
40+
}
3441
return packets
3542

3643

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from minecraft.networking.types import VarInt, Boolean, Position, String
2+
from minecraft.networking.packets import Packet
3+
4+
5+
class TabCompletePacket(Packet):
6+
@staticmethod
7+
def get_id(context):
8+
return 0x06 if context.protocol_later_eq(464) else \
9+
0x05 if context.protocol_later_eq(389) else \
10+
0x04 if context.protocol_later_eq(345) else \
11+
0x01 if context.protocol_later_eq(336) else \
12+
0x02 if context.protocol_later_eq(318) else \
13+
0x01 if context.protocol_later_eq(94) else \
14+
0x00 if context.protocol_later_eq(70) else \
15+
0x15 if context.protocol_later_eq(69) else \
16+
0x14
17+
packet_name = 'tab complete'
18+
19+
@property
20+
def fields(self):
21+
fields = 'text',
22+
if self.context.protocol_later_eq(351):
23+
fields += 'transaction_id'
24+
else:
25+
fields += 'has_position', 'looked_at_block',
26+
if self.context.protocol_later_eq(95):
27+
fields += 'assume_command'
28+
29+
def read(self, file_object):
30+
self.transaction_id = VarInt.read(file_object) \
31+
if self.context.protocol_later_eq(351) else None
32+
self.text = String.read(file_object)
33+
if self.context.protocol_earlier_eq(350):
34+
self.assume_command = Boolean.read(file_object) \
35+
if self.context.protocol_later_eq(95) else None
36+
has_position = Boolean.read(file_object)
37+
if has_position:
38+
self.looked_at_block = Position.read(file_object)
39+
40+
def write_fields(self, packet_buffer):
41+
if self.context.protocol_later_eq(351):
42+
VarInt.send(self.transaction_id, packet_buffer)
43+
String.send(self.text, packet_buffer)
44+
if self.context.protocol_earlier_eq(350):
45+
if self.context.protocol_later_eq(95):
46+
Boolean.send(self.assume_command, packet_buffer)
47+
Boolean.send(self.looked_at_block is not None, packet_buffer)
48+
if self.looked_at_block is not None:
49+
Position.send(self.looked_at_block, packet_buffer)

0 commit comments

Comments
 (0)