Skip to content

Commit 7cfbc0e

Browse files
committed
Clarify PrefixedIdRequest markers and use ProtocolVersion constants
1 parent 1e1ea50 commit 7cfbc0e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

api/src/main/java/com/turikhay/mc/mapmodcompanion/PrefixedIdRequest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
* Description of a packet sent by VoxelMap-style clients to request the
1414
* server's {@code world_id}.
1515
*
16-
* <p>Clients send this packet to learn how the server expects the id to be
17-
* encoded. Use {@link #parse(byte[], Integer)} to interpret the request and
18-
* {@link #constructId(int)} to produce a {@link PrefixedId} for the response.</p>
16+
* <p>The packet itself has no internal structure that influences how the
17+
* server responds. The {@link #parse(byte[], Integer)} method examines the raw
18+
* bytes and sets markers such as zero-padding length and the presence of the
19+
* magic marker {@link Id#MAGIC_MARKER}. These markers indicate which client
20+
* family and version range issued the request, allowing the server to craft a
21+
* matching {@link PrefixedId} via {@link #constructId(int)}.</p>
1922
*
2023
* <pre>{@code
2124
* PrefixedIdRequest request = PrefixedIdRequest.parse(data, protocolVersion);
@@ -72,7 +75,8 @@ public String toString() {
7275
}
7376

7477
/**
75-
* Parses a VoxelMap-style request packet.
78+
* Parses a VoxelMap-style request packet and sets markers describing the
79+
* client family and version range.
7680
*
7781
* @param payload raw packet bytes
7882
* @param protocolVersion client's protocol version or {@code null} if unknown;
@@ -105,7 +109,7 @@ public static PrefixedIdRequest parse(byte[] payload, @Nullable Integer protocol
105109
}
106110
switch (padding) {
107111
case 1:
108-
if (protocolVersion != null && protocolVersion <= 753) { // 1.16.3 and below
112+
if (protocolVersion != null && protocolVersion <= ProtocolVersion.MINECRAFT_1_16_3) { // 1.16.3 and below
109113
// VoxelMap Forge 1.13.2 - 1.16.3
110114
return new PrefixedIdRequest(1, false);
111115
}

api/src/test/java/PrefixedIdRequestParserTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ void voxelMapForge1_12_2() throws MalformedPacketException {
1818
void voxelMapForge1_13_2UpTo1_16_3() throws MalformedPacketException {
1919
test(
2020
Arrays.asList(
21-
404,
22-
498,
23-
578,
24-
753
21+
ProtocolVersion.MINECRAFT_1_13_2,
22+
ProtocolVersion.MINECRAFT_1_14_4,
23+
ProtocolVersion.MINECRAFT_1_15_2,
24+
ProtocolVersion.MINECRAFT_1_16_3
2525
),
2626
new PrefixedIdRequest(1, false),
2727
new byte[] { 0, 42, 0 }

0 commit comments

Comments
 (0)