packet-events-js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +398 -0
  2. package/package.json +31 -0
  3. package/src/auth/AuthHandler.js +138 -0
  4. package/src/auth/MojangAPI.js +186 -0
  5. package/src/client/MinecraftClient.js +336 -0
  6. package/src/crypto/Encryption.js +125 -0
  7. package/src/events/EventEmitter.js +267 -0
  8. package/src/events/PacketEvent.js +78 -0
  9. package/src/index.js +18 -0
  10. package/src/manager/PacketManager.js +258 -0
  11. package/src/protocol/ConnectionState.js +37 -0
  12. package/src/protocol/PacketDirection.js +8 -0
  13. package/src/protocol/ProtocolVersion.js +141 -0
  14. package/src/protocol/packets/Packet.js +119 -0
  15. package/src/protocol/packets/PacketRegistry.js +145 -0
  16. package/src/protocol/packets/handshake/HandshakePacket.js +44 -0
  17. package/src/protocol/packets/index.js +265 -0
  18. package/src/protocol/packets/login/DisconnectPacket.js +71 -0
  19. package/src/protocol/packets/login/EncryptionRequestPacket.js +47 -0
  20. package/src/protocol/packets/login/EncryptionResponsePacket.js +34 -0
  21. package/src/protocol/packets/login/LoginStartPacket.js +35 -0
  22. package/src/protocol/packets/login/LoginSuccessPacket.js +61 -0
  23. package/src/protocol/packets/login/SetCompressionPacket.js +29 -0
  24. package/src/protocol/packets/play/ChatPacket.js +238 -0
  25. package/src/protocol/packets/play/ChunkPacket.js +122 -0
  26. package/src/protocol/packets/play/EntityPacket.js +302 -0
  27. package/src/protocol/packets/play/KeepAlivePacket.js +55 -0
  28. package/src/protocol/packets/play/PlayerPositionPacket.js +266 -0
  29. package/src/protocol/packets/status/PingPacket.js +29 -0
  30. package/src/protocol/packets/status/PongPacket.js +29 -0
  31. package/src/protocol/packets/status/StatusRequestPacket.js +20 -0
  32. package/src/protocol/packets/status/StatusResponsePacket.js +58 -0
  33. package/src/protocol/types/NBT.js +594 -0
  34. package/src/protocol/types/Position.js +125 -0
  35. package/src/protocol/types/TextComponent.js +355 -0
  36. package/src/protocol/types/UUID.js +105 -0
  37. package/src/protocol/types/VarInt.js +144 -0
  38. package/src/protocol/types/index.js +5 -0
  39. package/src/utils/Logger.js +207 -0
  40. package/src/utils/PacketBuffer.js +389 -0
@@ -0,0 +1,238 @@
1
+ import { Packet } from '../Packet.js';
2
+ import { TextComponent } from '../../types/TextComponent.js';
3
+ import { UUID } from '../../types/UUID.js';
4
+
5
+ export class ChatMessageServerboundPacket extends Packet {
6
+ static get packetId() { return 0x06; }
7
+ static get packetName() { return 'ChatMessageServerbound'; }
8
+
9
+ constructor() {
10
+ super();
11
+
12
+ this.message = '';
13
+
14
+ this.messageTimestamp = 0n;
15
+
16
+ this.salt = 0n;
17
+
18
+ this.signature = null;
19
+
20
+ this.messageCount = 0;
21
+
22
+ this.acknowledged = Buffer.alloc(0);
23
+ }
24
+
25
+ read(buffer, context) {
26
+ this.message = buffer.readString(256);
27
+ this.messageTimestamp = buffer.readLong();
28
+ this.salt = buffer.readLong();
29
+ this.signature = buffer.readOptional(() => buffer.readBytes(256));
30
+ this.messageCount = buffer.readVarInt();
31
+ this.acknowledged = buffer.readBytes(3);
32
+ }
33
+
34
+ write(buffer, context) {
35
+ buffer.writeString(this.message);
36
+ buffer.writeLong(this.messageTimestamp);
37
+ buffer.writeLong(this.salt);
38
+ buffer.writeOptional(this.signature, (sig) => buffer.writeBytes(sig));
39
+ buffer.writeVarInt(this.messageCount);
40
+ buffer.writeBytes(this.acknowledged);
41
+ }
42
+
43
+ toJSON() {
44
+ return {
45
+ ...super.toJSON(),
46
+ message: this.message,
47
+ messageTimestamp: this.messageTimestamp.toString(),
48
+ hasSignature: this.signature !== null
49
+ };
50
+ }
51
+ }
52
+
53
+ export class SystemChatMessagePacket extends Packet {
54
+ static get packetId() { return 0x6C; }
55
+ static get packetName() { return 'SystemChatMessage'; }
56
+
57
+ constructor() {
58
+ super();
59
+
60
+ this.content = null;
61
+
62
+ this.overlay = false;
63
+ }
64
+
65
+ read(buffer, context) {
66
+ const jsonStr = buffer.readString(262144);
67
+
68
+ try {
69
+ const json = JSON.parse(jsonStr);
70
+ this.content = TextComponent.fromJSON(json);
71
+ } catch (e) {
72
+ this.content = TextComponent.text(jsonStr);
73
+ }
74
+
75
+ this.overlay = buffer.readBoolean();
76
+ }
77
+
78
+ write(buffer, context) {
79
+ const json = this.content instanceof TextComponent ?
80
+ JSON.stringify(this.content.toJSON()) :
81
+ JSON.stringify(this.content);
82
+
83
+ buffer.writeString(json);
84
+ buffer.writeBoolean(this.overlay);
85
+ }
86
+
87
+ getPlainText() {
88
+ if (this.content instanceof TextComponent) {
89
+ return this.content.toPlainText();
90
+ }
91
+ return String(this.content);
92
+ }
93
+
94
+ toJSON() {
95
+ return {
96
+ ...super.toJSON(),
97
+ content: this.content instanceof TextComponent ?
98
+ this.content.toJSON() : this.content,
99
+ overlay: this.overlay
100
+ };
101
+ }
102
+ }
103
+
104
+ export class PlayerChatMessagePacket extends Packet {
105
+ static get packetId() { return 0x39; }
106
+ static get packetName() { return 'PlayerChatMessage'; }
107
+
108
+ constructor() {
109
+ super();
110
+
111
+ this.sender = null;
112
+
113
+ this.index = 0;
114
+
115
+ this.signature = null;
116
+
117
+ this.body = '';
118
+
119
+ this.timestamp = 0n;
120
+
121
+ this.salt = 0n;
122
+
123
+ this.unsignedContent = null;
124
+
125
+ this.filterType = 0;
126
+
127
+ this.chatType = 0;
128
+
129
+ this.networkName = null;
130
+
131
+ this.networkTargetName = null;
132
+ }
133
+
134
+ read(buffer, context) {
135
+ this.sender = buffer.readUUID();
136
+ this.index = buffer.readVarInt();
137
+ this.signature = buffer.readOptional(() => buffer.readBytes(256));
138
+ this.body = buffer.readString(256);
139
+ this.timestamp = buffer.readLong();
140
+ this.salt = buffer.readLong();
141
+
142
+ const prevCount = buffer.readVarInt();
143
+ for (let i = 0; i < prevCount; i++) {
144
+ buffer.readVarInt();
145
+ buffer.readBytes(256);
146
+ }
147
+
148
+ this.unsignedContent = buffer.readOptional(() => {
149
+ const json = buffer.readString(262144);
150
+ try {
151
+ return TextComponent.fromJSON(JSON.parse(json));
152
+ } catch (e) {
153
+ return TextComponent.text(json);
154
+ }
155
+ });
156
+
157
+ this.filterType = buffer.readVarInt();
158
+
159
+ if (this.filterType === 2) {
160
+
161
+ buffer.readByteArray();
162
+ }
163
+
164
+ this.chatType = buffer.readVarInt();
165
+
166
+ const networkNameJson = buffer.readString(262144);
167
+ try {
168
+ this.networkName = TextComponent.fromJSON(JSON.parse(networkNameJson));
169
+ } catch (e) {
170
+ this.networkName = TextComponent.text(networkNameJson);
171
+ }
172
+
173
+ this.networkTargetName = buffer.readOptional(() => {
174
+ const json = buffer.readString(262144);
175
+ try {
176
+ return TextComponent.fromJSON(JSON.parse(json));
177
+ } catch (e) {
178
+ return TextComponent.text(json);
179
+ }
180
+ });
181
+ }
182
+
183
+ write(buffer, context) {
184
+
185
+ buffer.writeUUID(this.sender);
186
+ buffer.writeVarInt(this.index);
187
+ buffer.writeOptional(this.signature, (sig) => buffer.writeBytes(sig));
188
+ buffer.writeString(this.body);
189
+ buffer.writeLong(this.timestamp);
190
+ buffer.writeLong(this.salt);
191
+ buffer.writeVarInt(0);
192
+
193
+ buffer.writeOptional(this.unsignedContent, (content) => {
194
+ const json = content instanceof TextComponent ?
195
+ JSON.stringify(content.toJSON()) : JSON.stringify(content);
196
+ buffer.writeString(json);
197
+ });
198
+
199
+ buffer.writeVarInt(this.filterType);
200
+ buffer.writeVarInt(this.chatType);
201
+
202
+ const nameJson = this.networkName instanceof TextComponent ?
203
+ JSON.stringify(this.networkName.toJSON()) :
204
+ JSON.stringify({ text: String(this.networkName) });
205
+ buffer.writeString(nameJson);
206
+
207
+ buffer.writeOptional(this.networkTargetName, (name) => {
208
+ const json = name instanceof TextComponent ?
209
+ JSON.stringify(name.toJSON()) : JSON.stringify({ text: String(name) });
210
+ buffer.writeString(json);
211
+ });
212
+ }
213
+
214
+ getMessage() {
215
+ if (this.unsignedContent) {
216
+ return this.unsignedContent instanceof TextComponent ?
217
+ this.unsignedContent.toPlainText() : String(this.unsignedContent);
218
+ }
219
+ return this.body;
220
+ }
221
+
222
+ toJSON() {
223
+ return {
224
+ ...super.toJSON(),
225
+ sender: this.sender?.toString(),
226
+ body: this.body,
227
+ unsignedContent: this.unsignedContent instanceof TextComponent ?
228
+ this.unsignedContent.toJSON() : this.unsignedContent,
229
+ chatType: this.chatType
230
+ };
231
+ }
232
+ }
233
+
234
+ export default {
235
+ ChatMessageServerboundPacket,
236
+ SystemChatMessagePacket,
237
+ PlayerChatMessagePacket
238
+ };
@@ -0,0 +1,122 @@
1
+ import { Packet } from '../Packet.js';
2
+ import { NBTReader, NBTCompound } from '../../types/NBT.js';
3
+
4
+ export class ChunkDataPacket extends Packet {
5
+ static get packetId() { return 0x27; }
6
+ static get packetName() { return 'ChunkData'; }
7
+
8
+ constructor() {
9
+ super();
10
+
11
+ this.chunkX = 0;
12
+
13
+ this.chunkZ = 0;
14
+
15
+ this.heightmaps = null;
16
+
17
+ this.data = Buffer.alloc(0);
18
+
19
+ this.blockEntities = [];
20
+
21
+ this.lightData = null;
22
+ }
23
+
24
+ read(buffer, context) {
25
+ this.chunkX = buffer.readInt();
26
+ this.chunkZ = buffer.readInt();
27
+
28
+ this.heightmaps = buffer.readNBT(false);
29
+
30
+ this.data = buffer.readByteArray();
31
+
32
+ const blockEntityCount = buffer.readVarInt();
33
+ this.blockEntities = [];
34
+
35
+ for (let i = 0; i < blockEntityCount; i++) {
36
+ const packedXZ = buffer.readUByte();
37
+ const y = buffer.readShort();
38
+ const type = buffer.readVarInt();
39
+ const nbt = buffer.readNBT(false);
40
+
41
+ this.blockEntities.push({
42
+ localX: packedXZ >> 4,
43
+ localZ: packedXZ & 0xF,
44
+ y,
45
+ type,
46
+ data: nbt
47
+ });
48
+ }
49
+
50
+ if (buffer.isReadable(1)) {
51
+ this.lightData = buffer.readRemainingBytes();
52
+ }
53
+ }
54
+
55
+ write(buffer, context) {
56
+ buffer.writeInt(this.chunkX);
57
+ buffer.writeInt(this.chunkZ);
58
+
59
+ buffer.writeNBT(this.heightmaps || new NBTCompound(), false);
60
+ buffer.writeByteArray(this.data);
61
+
62
+ buffer.writeVarInt(this.blockEntities.length);
63
+
64
+ for (const entity of this.blockEntities) {
65
+ buffer.writeUByte((entity.localX << 4) | (entity.localZ & 0xF));
66
+ buffer.writeShort(entity.y);
67
+ buffer.writeVarInt(entity.type);
68
+ buffer.writeNBT(entity.data || new NBTCompound(), false);
69
+ }
70
+
71
+ if (this.lightData) {
72
+ buffer.writeBytes(this.lightData);
73
+ }
74
+ }
75
+
76
+ getChunkPos() {
77
+ return [this.chunkX, this.chunkZ];
78
+ }
79
+
80
+ toJSON() {
81
+ return {
82
+ ...super.toJSON(),
83
+ chunkX: this.chunkX,
84
+ chunkZ: this.chunkZ,
85
+ dataSize: this.data.length,
86
+ blockEntityCount: this.blockEntities.length
87
+ };
88
+ }
89
+ }
90
+
91
+ export class UnloadChunkPacket extends Packet {
92
+ static get packetId() { return 0x21; }
93
+ static get packetName() { return 'UnloadChunk'; }
94
+
95
+ constructor() {
96
+ super();
97
+
98
+ this.chunkX = 0;
99
+
100
+ this.chunkZ = 0;
101
+ }
102
+
103
+ read(buffer, context) {
104
+ this.chunkX = buffer.readInt();
105
+ this.chunkZ = buffer.readInt();
106
+ }
107
+
108
+ write(buffer, context) {
109
+ buffer.writeInt(this.chunkX);
110
+ buffer.writeInt(this.chunkZ);
111
+ }
112
+
113
+ toJSON() {
114
+ return {
115
+ ...super.toJSON(),
116
+ chunkX: this.chunkX,
117
+ chunkZ: this.chunkZ
118
+ };
119
+ }
120
+ }
121
+
122
+ export default { ChunkDataPacket, UnloadChunkPacket };
@@ -0,0 +1,302 @@
1
+ import { Packet } from '../Packet.js';
2
+ import { UUID } from '../../types/UUID.js';
3
+ import { TextComponent } from '../../types/TextComponent.js';
4
+
5
+ export class SpawnEntityPacket extends Packet {
6
+ static get packetId() { return 0x01; }
7
+ static get packetName() { return 'SpawnEntity'; }
8
+
9
+ constructor() {
10
+ super();
11
+
12
+ this.entityId = 0;
13
+
14
+ this.entityUUID = null;
15
+
16
+ this.type = 0;
17
+
18
+ this.x = 0;
19
+
20
+ this.y = 0;
21
+
22
+ this.z = 0;
23
+
24
+ this.pitch = 0;
25
+
26
+ this.yaw = 0;
27
+
28
+ this.headYaw = 0;
29
+
30
+ this.data = 0;
31
+
32
+ this.velocityX = 0;
33
+
34
+ this.velocityY = 0;
35
+
36
+ this.velocityZ = 0;
37
+ }
38
+
39
+ read(buffer, context) {
40
+ this.entityId = buffer.readVarInt();
41
+ this.entityUUID = buffer.readUUID();
42
+ this.type = buffer.readVarInt();
43
+ this.x = buffer.readDouble();
44
+ this.y = buffer.readDouble();
45
+ this.z = buffer.readDouble();
46
+ this.pitch = buffer.readAngle();
47
+ this.yaw = buffer.readAngle();
48
+ this.headYaw = buffer.readAngle();
49
+ this.data = buffer.readVarInt();
50
+ this.velocityX = buffer.readShort();
51
+ this.velocityY = buffer.readShort();
52
+ this.velocityZ = buffer.readShort();
53
+ }
54
+
55
+ write(buffer, context) {
56
+ buffer.writeVarInt(this.entityId);
57
+ buffer.writeUUID(this.entityUUID);
58
+ buffer.writeVarInt(this.type);
59
+ buffer.writeDouble(this.x);
60
+ buffer.writeDouble(this.y);
61
+ buffer.writeDouble(this.z);
62
+ buffer.writeAngle(this.pitch);
63
+ buffer.writeAngle(this.yaw);
64
+ buffer.writeAngle(this.headYaw);
65
+ buffer.writeVarInt(this.data);
66
+ buffer.writeShort(this.velocityX);
67
+ buffer.writeShort(this.velocityY);
68
+ buffer.writeShort(this.velocityZ);
69
+ }
70
+
71
+ toJSON() {
72
+ return {
73
+ ...super.toJSON(),
74
+ entityId: this.entityId,
75
+ entityUUID: this.entityUUID?.toString(),
76
+ type: this.type,
77
+ x: this.x,
78
+ y: this.y,
79
+ z: this.z
80
+ };
81
+ }
82
+ }
83
+
84
+ export class RemoveEntitiesPacket extends Packet {
85
+ static get packetId() { return 0x42; }
86
+ static get packetName() { return 'RemoveEntities'; }
87
+
88
+ constructor() {
89
+ super();
90
+
91
+ this.entityIds = [];
92
+ }
93
+
94
+ read(buffer, context) {
95
+ this.entityIds = buffer.readArray(() => buffer.readVarInt());
96
+ }
97
+
98
+ write(buffer, context) {
99
+ buffer.writeArray(this.entityIds, (id) => buffer.writeVarInt(id));
100
+ }
101
+
102
+ toJSON() {
103
+ return {
104
+ ...super.toJSON(),
105
+ entityIds: this.entityIds
106
+ };
107
+ }
108
+ }
109
+
110
+ export class UpdateEntityPositionPacket extends Packet {
111
+ static get packetId() { return 0x2E; }
112
+ static get packetName() { return 'UpdateEntityPosition'; }
113
+
114
+ constructor() {
115
+ super();
116
+
117
+ this.entityId = 0;
118
+
119
+ this.deltaX = 0;
120
+
121
+ this.deltaY = 0;
122
+
123
+ this.deltaZ = 0;
124
+
125
+ this.onGround = false;
126
+ }
127
+
128
+ read(buffer, context) {
129
+ this.entityId = buffer.readVarInt();
130
+ this.deltaX = buffer.readShort();
131
+ this.deltaY = buffer.readShort();
132
+ this.deltaZ = buffer.readShort();
133
+ this.onGround = buffer.readBoolean();
134
+ }
135
+
136
+ write(buffer, context) {
137
+ buffer.writeVarInt(this.entityId);
138
+ buffer.writeShort(this.deltaX);
139
+ buffer.writeShort(this.deltaY);
140
+ buffer.writeShort(this.deltaZ);
141
+ buffer.writeBoolean(this.onGround);
142
+ }
143
+
144
+ getDeltaXBlocks() {
145
+ return this.deltaX / 4096;
146
+ }
147
+
148
+ getDeltaYBlocks() {
149
+ return this.deltaY / 4096;
150
+ }
151
+
152
+ getDeltaZBlocks() {
153
+ return this.deltaZ / 4096;
154
+ }
155
+
156
+ toJSON() {
157
+ return {
158
+ ...super.toJSON(),
159
+ entityId: this.entityId,
160
+ deltaX: this.getDeltaXBlocks(),
161
+ deltaY: this.getDeltaYBlocks(),
162
+ deltaZ: this.getDeltaZBlocks(),
163
+ onGround: this.onGround
164
+ };
165
+ }
166
+ }
167
+
168
+ export class SetEntityMetadataPacket extends Packet {
169
+ static get packetId() { return 0x58; }
170
+ static get packetName() { return 'SetEntityMetadata'; }
171
+
172
+ constructor() {
173
+ super();
174
+
175
+ this.entityId = 0;
176
+
177
+ this.metadata = new Map();
178
+ }
179
+
180
+ read(buffer, context) {
181
+ this.entityId = buffer.readVarInt();
182
+
183
+ while (true) {
184
+ const index = buffer.readUByte();
185
+
186
+ if (index === 0xFF) {
187
+ break;
188
+ }
189
+
190
+ const type = buffer.readVarInt();
191
+ const value = this._readMetadataValue(buffer, type);
192
+
193
+ this.metadata.set(index, { type, value });
194
+ }
195
+ }
196
+
197
+ write(buffer, context) {
198
+ buffer.writeVarInt(this.entityId);
199
+
200
+ for (const [index, { type, value }] of this.metadata) {
201
+ buffer.writeUByte(index);
202
+ buffer.writeVarInt(type);
203
+ this._writeMetadataValue(buffer, type, value);
204
+ }
205
+
206
+ buffer.writeUByte(0xFF);
207
+ }
208
+
209
+ _readMetadataValue(buffer, type) {
210
+ switch (type) {
211
+ case 0: return buffer.readByte();
212
+ case 1: return buffer.readVarInt();
213
+ case 2: return buffer.readVarLong();
214
+ case 3: return buffer.readFloat();
215
+ case 4: return buffer.readString();
216
+ case 5:
217
+ const json = buffer.readString();
218
+ try {
219
+ return TextComponent.fromJSON(JSON.parse(json));
220
+ } catch (e) {
221
+ return TextComponent.text(json);
222
+ }
223
+ case 6:
224
+ return buffer.readOptional(() => {
225
+ const j = buffer.readString();
226
+ try {
227
+ return TextComponent.fromJSON(JSON.parse(j));
228
+ } catch (e) {
229
+ return TextComponent.text(j);
230
+ }
231
+ });
232
+ case 7:
233
+ return buffer.readBoolean() ? { } : null;
234
+ case 8: return buffer.readBoolean();
235
+ case 9:
236
+ return {
237
+ x: buffer.readFloat(),
238
+ y: buffer.readFloat(),
239
+ z: buffer.readFloat()
240
+ };
241
+ case 10: return buffer.readPosition();
242
+ case 11: return buffer.readOptional(() => buffer.readPosition());
243
+ case 12: return buffer.readVarInt();
244
+ case 13: return buffer.readOptional(() => buffer.readUUID());
245
+ case 14: return buffer.readVarInt();
246
+ case 15: return buffer.readVarInt();
247
+ case 16: return buffer.readNBT();
248
+ case 17:
249
+ return { type: buffer.readVarInt() };
250
+ case 18:
251
+ return {
252
+ villagerType: buffer.readVarInt(),
253
+ profession: buffer.readVarInt(),
254
+ level: buffer.readVarInt()
255
+ };
256
+ case 19: return buffer.readOptional(() => buffer.readVarInt());
257
+ case 20: return buffer.readVarInt();
258
+ default:
259
+
260
+ return null;
261
+ }
262
+ }
263
+
264
+ _writeMetadataValue(buffer, type, value) {
265
+ switch (type) {
266
+ case 0: buffer.writeByte(value); break;
267
+ case 1: buffer.writeVarInt(value); break;
268
+ case 2: buffer.writeVarLong(value); break;
269
+ case 3: buffer.writeFloat(value); break;
270
+ case 4: buffer.writeString(value); break;
271
+ case 5:
272
+ const json = value instanceof TextComponent ?
273
+ JSON.stringify(value.toJSON()) : JSON.stringify(value);
274
+ buffer.writeString(json);
275
+ break;
276
+ case 8: buffer.writeBoolean(value); break;
277
+
278
+ default:
279
+ break;
280
+ }
281
+ }
282
+
283
+ toJSON() {
284
+ const metadata = {};
285
+ for (const [index, { type, value }] of this.metadata) {
286
+ metadata[index] = { type, value };
287
+ }
288
+
289
+ return {
290
+ ...super.toJSON(),
291
+ entityId: this.entityId,
292
+ metadata
293
+ };
294
+ }
295
+ }
296
+
297
+ export default {
298
+ SpawnEntityPacket,
299
+ RemoveEntitiesPacket,
300
+ UpdateEntityPositionPacket,
301
+ SetEntityMetadataPacket
302
+ };
@@ -0,0 +1,55 @@
1
+ import { Packet } from '../Packet.js';
2
+
3
+ export class KeepAliveClientboundPacket extends Packet {
4
+ static get packetId() { return 0x26; }
5
+ static get packetName() { return 'KeepAliveClientbound'; }
6
+
7
+ constructor() {
8
+ super();
9
+
10
+ this.keepAliveId = 0n;
11
+ }
12
+
13
+ read(buffer, context) {
14
+ this.keepAliveId = buffer.readLong();
15
+ }
16
+
17
+ write(buffer, context) {
18
+ buffer.writeLong(this.keepAliveId);
19
+ }
20
+
21
+ toJSON() {
22
+ return {
23
+ ...super.toJSON(),
24
+ keepAliveId: this.keepAliveId.toString()
25
+ };
26
+ }
27
+ }
28
+
29
+ export class KeepAliveServerboundPacket extends Packet {
30
+ static get packetId() { return 0x18; }
31
+ static get packetName() { return 'KeepAliveServerbound'; }
32
+
33
+ constructor() {
34
+ super();
35
+
36
+ this.keepAliveId = 0n;
37
+ }
38
+
39
+ read(buffer, context) {
40
+ this.keepAliveId = buffer.readLong();
41
+ }
42
+
43
+ write(buffer, context) {
44
+ buffer.writeLong(this.keepAliveId);
45
+ }
46
+
47
+ toJSON() {
48
+ return {
49
+ ...super.toJSON(),
50
+ keepAliveId: this.keepAliveId.toString()
51
+ };
52
+ }
53
+ }
54
+
55
+ export default { KeepAliveClientboundPacket, KeepAliveServerboundPacket };