-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachePackets.js
59 lines (58 loc) · 1.51 KB
/
cachePackets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var chunkData = new Map();
var abilitiesPacket;
var loginpacket;
var gChunkCaching;
var positionPacket;
var inventory = [];
module.exports = {
init: (client, chunkCaching) => {
gChunkCaching = chunkCaching;
client.on("packet", (data, meta, rawData) => { // each time 2b2t sends a packet
switch (meta.name) {
case "map_chunk":
if(chunkCaching) chunkData.set(data.x + "_" + data.z, rawData);
break;
case "unload_chunk":
if(chunkCaching) chunkData.delete(data.chunkX + "_" + data.chunkZ);
break;
case "respawn":
Object.assign(loginpacket, data);
chunkData = new Map();
inventory = [];
break;
case "login":
loginpacket = data;
break;
// Apparently this makes the game crash when no cheat plus or other anticheats are present
//case "game_state_change":
// loginpacket.gameMode = data.gameMode;
// break;
case "abilities":
abilitiesPacket = rawData;
break;
case "position":
positionPacket = rawData;
break;
case "set_slot":
if(data.windowId == 0) { // windowId 0 is the inventory
inventory[data.slot] = data;
}
}
});
},
join: (proxyClient) => {
proxyClient.write('login', loginpacket);
proxyClient.writeRaw(positionPacket);
proxyClient.writeRaw(abilitiesPacket);
inventory.forEach( (slot) => {
if(slot != null) {
proxyClient.write("set_slot", slot);
}
});
setTimeout( () => {
if(gChunkCaching) chunkData.forEach((data) => {
proxyClient.writeRaw(data);
});
}, 1000);
}
}