Skip to content

Commit 4cf7e58

Browse files
committed
refine API docs
1 parent ab824b8 commit 4cf7e58

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
* modifications.
66
* <p>
77
* These constants can be used with the platform specific networking API to
8-
* register listeners or send packets. For example, registering the world id
9-
* channel on Fabric would look like:
8+
* register listeners or send packets. For example:
109
*
1110
* <pre>{@code
12-
* ClientPlayNetworking.registerGlobalReceiver(
13-
* Channels.WORLDID_CHANNEL,
14-
* (client, handler, buf, responseSender) -> { /* ... *\/ }
15-
* );
11+
* registerChannel(Channels.WORLDID_CHANNEL, data -> {
12+
* // ...
13+
* });
1614
* }</pre>
1715
*/
1816
public interface Channels {

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
*/
99
public interface Id {
1010

11-
/** Magic value used in some packet formats. */
11+
/**
12+
* Flag value used by VoxelMap-style packets.
13+
* <p>
14+
* When present at the start of a packet, the value {@code 42} signals that
15+
* the payload follows the VoxelMap format.
16+
*/
1217
int MAGIC_MARKER = 42;
1318

1419
/**
@@ -42,6 +47,13 @@ default <IdType> IdType withId(int id) {
4247

4348
/**
4449
* Converts raw packet bytes into an {@link Id} instance.
50+
* <p>
51+
* Implementations are typically stateless and expose a shared
52+
* {@code instance()} method so they can be reused:
53+
*
54+
* <pre>{@code
55+
* PrefixedId id = PrefixedId.Deserializer.instance().deserialize(data);
56+
* }</pre>
4557
*
4658
* @param <IdType> type of id produced
4759
*/
@@ -58,6 +70,13 @@ interface Deserializer<IdType extends Id> {
5870

5971
/**
6072
* Produces raw packet bytes from an {@link Id} instance.
73+
* <p>
74+
* Like deserializers, serializers commonly provide a shared
75+
* {@code instance()} for reuse:
76+
*
77+
* <pre>{@code
78+
* byte[] data = PrefixedId.Serializer.instance().serialize(id);
79+
* }</pre>
6180
*
6281
* @param <IdType> type of id to serialize
6382
*/

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public interface LevelMapProperties {
99

1010
/**
1111
* Deserializes standard id packets.
12+
*
13+
* <pre>{@code
14+
* StandardId id = LevelMapProperties.Deserializer.instance().deserialize(data);
15+
* }</pre>
1216
*/
1317
class Deserializer implements Id.Deserializer<StandardId> {
1418
private static Deserializer INSTANCE;
@@ -38,6 +42,10 @@ public static Deserializer instance() {
3842

3943
/**
4044
* Serializes standard ids into packet byte arrays.
45+
*
46+
* <pre>{@code
47+
* byte[] data = LevelMapProperties.Serializer.instance().serialize(id);
48+
* }</pre>
4149
*/
4250
class Serializer implements Id.Serializer<StandardId> {
4351
private static Serializer INSTANCE;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
/**
88
* Identifier encoded with a zero-prefixed length and optional magic marker.
9+
* When present, the marker has the value {@link Id#MAGIC_MARKER} (42) which
10+
* flags a VoxelMap-style packet.
911
* <p>
1012
* The format matches the one used by Xaero's minimap when responding to world
1113
* id requests. The {@link Deserializer} and {@link Serializer} nested classes
@@ -144,6 +146,10 @@ public static Deserializer instance() {
144146

145147
/**
146148
* Serializes {@link PrefixedId} instances into packet byte arrays.
149+
*
150+
* <pre>{@code
151+
* byte[] data = PrefixedId.Serializer.instance().serialize(id);
152+
* }</pre>
147153
*/
148154
public static class Serializer implements Id.Serializer<PrefixedId> {
149155
private static Serializer INSTANCE;
@@ -157,7 +163,7 @@ public byte[] serialize(PrefixedId id) {
157163
out.writeByte(0); // packetId, or prefix
158164
}
159165
if (id.usesMagicByte) {
160-
out.writeByte(MAGIC_MARKER); // 42 (literally)
166+
out.writeByte(MAGIC_MARKER); // VoxelMap-style flag (42)
161167
}
162168
byte[] data = String.valueOf(id.getId()).getBytes(StandardCharsets.UTF_8);
163169
out.write(data.length); // length

0 commit comments

Comments
 (0)