@vaitosoi/minejs 0.4.3 → 0.5.1
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.
- package/README.md +12 -4
- package/assets/minecraft/26.2/effects.json +42 -0
- package/assets/minecraft/26.2/packets.json +1 -1
- package/dist/base/bitset.d.ts +43 -4
- package/dist/base/bitset.d.ts.map +1 -1
- package/dist/base/bitset.js +251 -30
- package/dist/base/bitset.js.map +1 -1
- package/dist/base/buffer.d.ts +1 -0
- package/dist/base/buffer.d.ts.map +1 -1
- package/dist/base/buffer.js +1 -0
- package/dist/base/buffer.js.map +1 -1
- package/dist/base/cache.d.ts +24 -0
- package/dist/base/cache.d.ts.map +1 -0
- package/dist/base/cache.js +58 -0
- package/dist/base/cache.js.map +1 -0
- package/dist/base/error.d.ts +7 -0
- package/dist/base/error.d.ts.map +1 -1
- package/dist/base/error.js +12 -1
- package/dist/base/error.js.map +1 -1
- package/dist/base/http.d.ts +1 -0
- package/dist/base/http.d.ts.map +1 -1
- package/dist/base/http.js +1 -0
- package/dist/base/http.js.map +1 -1
- package/dist/base/math.d.ts +14 -0
- package/dist/base/math.d.ts.map +1 -1
- package/dist/base/math.js +41 -0
- package/dist/base/math.js.map +1 -1
- package/dist/base/typing.d.ts +12 -0
- package/dist/base/typing.d.ts.map +1 -1
- package/dist/{packet → binary}/decoder.d.ts +4 -0
- package/dist/binary/decoder.d.ts.map +1 -0
- package/dist/{packet → binary}/decoder.js +4 -0
- package/dist/binary/decoder.js.map +1 -0
- package/dist/{packet → binary}/encoder.d.ts +6 -2
- package/dist/binary/encoder.d.ts.map +1 -0
- package/dist/{packet → binary}/encoder.js +10 -2
- package/dist/binary/encoder.js.map +1 -0
- package/dist/{packet → binary}/static.d.ts.map +1 -1
- package/dist/{packet → binary}/static.js.map +1 -1
- package/dist/client/client.d.ts +23 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +32 -15
- package/dist/client/client.js.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/message/link.d.ts +3 -0
- package/dist/message/link.d.ts.map +1 -1
- package/dist/message/link.js +3 -0
- package/dist/message/link.js.map +1 -1
- package/dist/message/sigCache.d.ts +5 -0
- package/dist/message/sigCache.d.ts.map +1 -1
- package/dist/message/sigCache.js +5 -0
- package/dist/message/sigCache.js.map +1 -1
- package/dist/{client → net}/tcp.d.ts +3 -3
- package/dist/net/tcp.d.ts.map +1 -0
- package/dist/{client → net}/tcp.js +3 -3
- package/dist/net/tcp.js.map +1 -0
- package/dist/packet/{dispatcher.d.ts → listener.d.ts} +10 -18
- package/dist/packet/listener.d.ts.map +1 -0
- package/dist/packet/{dispatcher.js → listener.js} +74 -137
- package/dist/packet/listener.js.map +1 -0
- package/dist/packet/sender.d.ts +28 -0
- package/dist/packet/sender.d.ts.map +1 -0
- package/dist/packet/sender.js +147 -0
- package/dist/packet/sender.js.map +1 -0
- package/dist/physics/aabb.d.ts +3 -0
- package/dist/physics/aabb.d.ts.map +1 -1
- package/dist/physics/aabb.js +12 -8
- package/dist/physics/aabb.js.map +1 -1
- package/dist/physics/direction.d.ts +3 -0
- package/dist/physics/direction.d.ts.map +1 -1
- package/dist/physics/direction.js +3 -0
- package/dist/physics/direction.js.map +1 -1
- package/dist/physics/player.d.ts +4 -0
- package/dist/physics/player.d.ts.map +1 -1
- package/dist/physics/player.js +24 -3
- package/dist/physics/player.js.map +1 -1
- package/dist/version/codec.d.ts +5 -1
- package/dist/version/codec.d.ts.map +1 -1
- package/dist/version/codec.js +25 -5
- package/dist/version/codec.js.map +1 -1
- package/dist/version/registry.d.ts +25 -2
- package/dist/version/registry.d.ts.map +1 -1
- package/dist/version/registry.js +43 -6
- package/dist/version/registry.js.map +1 -1
- package/dist/world/block.d.ts +5 -0
- package/dist/world/block.d.ts.map +1 -1
- package/dist/world/block.js +56 -0
- package/dist/world/block.js.map +1 -1
- package/dist/world/state.d.ts +22 -0
- package/dist/world/state.d.ts.map +1 -1
- package/dist/world/state.js +19 -0
- package/dist/world/state.js.map +1 -1
- package/package.json +8 -10
- package/src/base/bitset.ts +311 -31
- package/src/base/buffer.ts +1 -0
- package/src/base/cache.ts +62 -0
- package/src/base/error.ts +9 -0
- package/src/base/http.ts +1 -0
- package/src/base/math.ts +45 -1
- package/src/base/typing.ts +11 -0
- package/src/{packet → binary}/decoder.ts +4 -0
- package/src/{packet → binary}/encoder.ts +10 -2
- package/src/client/client.ts +54 -19
- package/src/index.ts +12 -4
- package/src/message/link.ts +3 -0
- package/src/message/sigCache.ts +5 -0
- package/src/{client → net}/tcp.ts +4 -8
- package/src/packet/{dispatcher.ts → listener.ts} +93 -175
- package/src/packet/sender.ts +179 -0
- package/src/physics/aabb.ts +12 -8
- package/src/physics/direction.ts +3 -0
- package/src/physics/player.ts +22 -3
- package/src/version/codec.ts +27 -6
- package/src/version/registry.ts +59 -3
- package/src/world/block.ts +72 -2
- package/src/world/state.ts +42 -2
- package/test/bitset/index.ts +3 -8
- package/test/client/index.ts +12 -2
- package/test/state/index.ts +7 -0
- package/dist/client/tcp.d.ts.map +0 -1
- package/dist/client/tcp.js.map +0 -1
- package/dist/packet/decoder.d.ts.map +0 -1
- package/dist/packet/decoder.js.map +0 -1
- package/dist/packet/dispatcher.d.ts.map +0 -1
- package/dist/packet/dispatcher.js.map +0 -1
- package/dist/packet/encoder.d.ts.map +0 -1
- package/dist/packet/encoder.js.map +0 -1
- /package/dist/{packet → binary}/static.d.ts +0 -0
- /package/dist/{packet → binary}/static.js +0 -0
- /package/src/{packet → binary}/static.ts +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base implementation for the Cache class
|
|
3
|
+
*/
|
|
4
|
+
export abstract class CacheImplementation<T = any> {
|
|
5
|
+
public abstract put(key: string, item: T): void;
|
|
6
|
+
public abstract get(key: string): T | undefined;
|
|
7
|
+
public abstract del(key: string): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The LRU cache implementation.
|
|
12
|
+
*
|
|
13
|
+
* @see https://en.wikipedia.org/wiki/Cache_replacement_policies#Time-Aware,_Least_Recently_Used_(TLRU)
|
|
14
|
+
*/
|
|
15
|
+
export class LRUCache<T> extends CacheImplementation<T> {
|
|
16
|
+
private hash: Map<string, T> = new Map();
|
|
17
|
+
private list: string[] = [];
|
|
18
|
+
|
|
19
|
+
constructor(private capacity: number) {
|
|
20
|
+
super();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public put(key: string, item: T): void {
|
|
24
|
+
if (this.hash.has(key)) {
|
|
25
|
+
const oldIndex = this.list.indexOf(key);
|
|
26
|
+
if (oldIndex > -1)
|
|
27
|
+
this.list.splice(oldIndex, 1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.hash.set(key, item);
|
|
31
|
+
this.list.push(key);
|
|
32
|
+
|
|
33
|
+
this.truncateHash();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public get(key: string) {
|
|
37
|
+
if (!this.hash.has(key)) return undefined;
|
|
38
|
+
|
|
39
|
+
const item = this.hash.get(key);
|
|
40
|
+
const oldIndex = this.list.indexOf(key);
|
|
41
|
+
if (oldIndex > -1)
|
|
42
|
+
this.list.splice(oldIndex, 1);
|
|
43
|
+
this.list.push(key);
|
|
44
|
+
|
|
45
|
+
return item;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public del(key: string): void {
|
|
49
|
+
const oldIndex = this.list.indexOf(key);
|
|
50
|
+
if (oldIndex > -1)
|
|
51
|
+
this.list.splice(oldIndex, 1);
|
|
52
|
+
this.hash.delete(key);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private truncateHash() {
|
|
56
|
+
while (this.list.length > this.capacity) {
|
|
57
|
+
const popping = this.list.pop();
|
|
58
|
+
if (popping)
|
|
59
|
+
this.hash.delete(popping);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/base/error.ts
CHANGED
|
@@ -211,4 +211,13 @@ export class HaveSignatureButNotIndex extends Error {
|
|
|
211
211
|
constructor() {
|
|
212
212
|
super (`expecting both shouldVerifyMessageOrder set to true when shouldVerifyMessageSignature set to true`);
|
|
213
213
|
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @hidden
|
|
218
|
+
*/
|
|
219
|
+
export class MessageTooLong extends Error {
|
|
220
|
+
constructor(public message: string) {
|
|
221
|
+
super(`your message is exceeding the 256 characters long limit, got ${message.length} characters`);
|
|
222
|
+
}
|
|
214
223
|
}
|
package/src/base/http.ts
CHANGED
package/src/base/math.ts
CHANGED
|
@@ -112,4 +112,48 @@ export function minecraftSha1(
|
|
|
112
112
|
function mcHexDigest(digest: Buffer | Uint8Array): string {
|
|
113
113
|
const bigint = BigInt(`0x${digest.toString('hex')}`);
|
|
114
114
|
return BigInt.asIntN(digest.length * 8, bigint).toString(16);
|
|
115
|
-
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Simplified implementation of Java's Long.numberOfTrailingZeros
|
|
119
|
+
* @param n
|
|
120
|
+
* @returns
|
|
121
|
+
* @hidden
|
|
122
|
+
*/
|
|
123
|
+
export function numberOfTrailingZeros(n: bigint): number {
|
|
124
|
+
if (n === 0n) {
|
|
125
|
+
return 64;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let count = 0;
|
|
129
|
+
while ((n & 1n) === 0n) {
|
|
130
|
+
count++;
|
|
131
|
+
n >>= 1n;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return count;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Simplified implementation of Java's Long.numberOfLeadingZeros
|
|
139
|
+
* @param n
|
|
140
|
+
* @returns
|
|
141
|
+
* @hidden
|
|
142
|
+
*/
|
|
143
|
+
export function numberOfLeadingZeros(n: bigint): number {
|
|
144
|
+
if (n === 0n) {
|
|
145
|
+
return 64;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let count = 0;
|
|
149
|
+
// Start checking from bit 63 (the most significant bit)
|
|
150
|
+
for (let i = 63; i >= 0; i--) {
|
|
151
|
+
if ((n & (1n << BigInt(i))) === 0n) {
|
|
152
|
+
count++;
|
|
153
|
+
} else {
|
|
154
|
+
break; // Stop at the first 1 bit
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return count;
|
|
159
|
+
}
|
package/src/base/typing.ts
CHANGED
|
@@ -8,3 +8,14 @@ export type If<Condition extends boolean, True, False = null> = Condition extend
|
|
|
8
8
|
* @see https://minecraft.wiki/w/Text_component_format
|
|
9
9
|
*/
|
|
10
10
|
export type TextComponent = Record<string, any>;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Representing the data in Registry Data packet
|
|
15
|
+
*
|
|
16
|
+
* @see https://minecraft.wiki/w/Java_Edition_protocol/Packets#Registry_Data
|
|
17
|
+
*/
|
|
18
|
+
export interface RegistryData {
|
|
19
|
+
registry_id: string,
|
|
20
|
+
entries: { entry_id: string, data: Record<string, any> | null }[]
|
|
21
|
+
}
|
|
@@ -6,6 +6,7 @@ import { unzipSync } from "zlib";
|
|
|
6
6
|
import { minBigInt } from "../base/math";
|
|
7
7
|
import { inspect } from "util";
|
|
8
8
|
|
|
9
|
+
/** @hidden */
|
|
9
10
|
export function getTextFromTextComponent(component: any): string {
|
|
10
11
|
if (component === null || component === undefined) return "null";
|
|
11
12
|
switch (typeof component) {
|
|
@@ -31,6 +32,9 @@ export function getTextFromTextComponent(component: any): string {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Binary decoding helper class
|
|
37
|
+
*/
|
|
34
38
|
export class BinaryDecoder {
|
|
35
39
|
public buffer: Buffer = Buffer.alloc(0);
|
|
36
40
|
public offset: number = 0;
|
|
@@ -3,6 +3,7 @@ import { CONTINUATION_FLAG, CONTINUE_BIT, isFixedSizeTag, isTag, MAX_QUANTIZED_V
|
|
|
3
3
|
import { InvalidValue, NumberTooBig, UnexpectedValue } from "../base/error";
|
|
4
4
|
import { FixedSizeTag, Tag } from "./static";
|
|
5
5
|
|
|
6
|
+
/** @hidden */
|
|
6
7
|
export function makeMovementFlag(onGround: boolean, pushingWall: boolean) {
|
|
7
8
|
let flag = 0;
|
|
8
9
|
if (onGround)
|
|
@@ -12,6 +13,9 @@ export function makeMovementFlag(onGround: boolean, pushingWall: boolean) {
|
|
|
12
13
|
return flag;
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Binary encoding helper
|
|
18
|
+
*/
|
|
15
19
|
export class BinaryEncoder {
|
|
16
20
|
private buffer = Buffer.alloc(0);
|
|
17
21
|
|
|
@@ -62,9 +66,13 @@ export class BinaryEncoder {
|
|
|
62
66
|
*/
|
|
63
67
|
public writeInt(val: number) { return this.write(4, val, (buf) => buf.writeInt32BE); }
|
|
64
68
|
/**
|
|
65
|
-
* Write
|
|
69
|
+
* Write 8 bytes singed integer
|
|
66
70
|
*/
|
|
67
|
-
public writeLong(val: bigint
|
|
71
|
+
public writeLong(val: bigint | number) {
|
|
72
|
+
// Cast to BigInt
|
|
73
|
+
const v = typeof val === "bigint" ? val : BigInt(val);
|
|
74
|
+
return this.write(8, v, (buf) => buf.writeBigInt64BE);
|
|
75
|
+
}
|
|
68
76
|
/**
|
|
69
77
|
* Write 4 bytes float
|
|
70
78
|
*/
|
package/src/client/client.ts
CHANGED
|
@@ -3,17 +3,19 @@ import { BlockManager, BlockState } from "../world/block";
|
|
|
3
3
|
import { EntitiesManager } from "../world/entity";
|
|
4
4
|
import { Input, Player } from "../physics/player";
|
|
5
5
|
import { TickLoop } from "../world/tick";
|
|
6
|
-
import { Message, TCPClient, TCPClientOption } from "
|
|
6
|
+
import { Message, TCPClient, TCPClientOption } from "../net/tcp";
|
|
7
7
|
import { TypedEmmiter as TypedEmitter } from "../base/event";
|
|
8
|
-
import { BlockRegistry, EntityRegistry, PacketRegistry, ProtocolVersionMapping } from "../version/registry";
|
|
8
|
+
import { BlockRegistry, EffectRegistry, EntityRegistry, PacketRegistry, ProtocolVersionMapping } from "../version/registry";
|
|
9
9
|
import { BaseVec3, Vec3 } from "../physics/direction";
|
|
10
|
-
import { TextComponent } from "../base/typing";
|
|
10
|
+
import { RegistryData, TextComponent } from "../base/typing";
|
|
11
11
|
import { ClientStatus, ConnectionState, EmittedEvent as EmittedEvent, Entity, SharedState } from "../world/state";
|
|
12
|
-
import {
|
|
12
|
+
import { Listener } from "../packet/listener";
|
|
13
13
|
import { VersionCodec } from "../version/codec";
|
|
14
14
|
import { AuthClient } from "./auth";
|
|
15
15
|
import { computeUUID } from "../base/math";
|
|
16
16
|
import { HaveSignatureButNotIndex } from "../base/error";
|
|
17
|
+
import { Sender } from "../packet/sender";
|
|
18
|
+
import { CacheImplementation } from "../base/cache";
|
|
17
19
|
|
|
18
20
|
export type ClientOption = Omit<TCPClientOption, "protocolVersion"> & {
|
|
19
21
|
version: string,
|
|
@@ -23,12 +25,26 @@ export type ClientOption = Omit<TCPClientOption, "protocolVersion"> & {
|
|
|
23
25
|
*
|
|
24
26
|
* When set this option to true, you HAVE TO set `shouldVerifyMessageOrder` to true
|
|
25
27
|
*/
|
|
26
|
-
shouldVerifyMessageSignature?: boolean
|
|
28
|
+
shouldVerifyMessageSignature?: boolean,
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Should verify the message orders to keep the sync with server.
|
|
30
32
|
*/
|
|
31
|
-
shouldVerifyMessageOrder?: boolean
|
|
33
|
+
shouldVerifyMessageOrder?: boolean,
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether to load the whole chunk section (16x16x16) and keep them in the cache or just load the needed block.
|
|
37
|
+
*
|
|
38
|
+
* Please consider this carefully since this can consume a lot of resource to calculate the whole chunk section and store it while you may not need that much.
|
|
39
|
+
*
|
|
40
|
+
* This option is useful when you have to constantly access to the world chunk, e.g pathfinding.
|
|
41
|
+
*/
|
|
42
|
+
loadAndCacheChunk?: boolean,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Custom cache class. Default to `LRUCache`
|
|
46
|
+
*/
|
|
47
|
+
cacheImplementation?: new () => CacheImplementation<Uint16Array>,
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
export interface ClientEvents {
|
|
@@ -71,6 +87,8 @@ export interface ClientEvents {
|
|
|
71
87
|
updateEntity: [entityId: number],
|
|
72
88
|
/** When an entity go out of client view distance or despawned */
|
|
73
89
|
removeEntity: [entityId: number],
|
|
90
|
+
/** The registry_data packet */
|
|
91
|
+
registryData: [data: RegistryData],
|
|
74
92
|
|
|
75
93
|
// Chat
|
|
76
94
|
/** When a chat message got broadcasted */
|
|
@@ -101,6 +119,8 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
101
119
|
|
|
102
120
|
private tcp: TCPClient;
|
|
103
121
|
private state: SharedState<IsReady>;
|
|
122
|
+
private packetListener: Listener;
|
|
123
|
+
private packetSender: Sender;
|
|
104
124
|
|
|
105
125
|
constructor(private options: ClientOption) {
|
|
106
126
|
if (options.shouldVerifyMessageSignature === true && options.shouldVerifyMessageOrder !== true)
|
|
@@ -111,7 +131,8 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
111
131
|
// For managing shared data
|
|
112
132
|
this.state = new SharedState(options);
|
|
113
133
|
// For handling packet
|
|
114
|
-
|
|
134
|
+
this.packetSender = new Sender(this.state, this.emit.bind(this));
|
|
135
|
+
this.packetListener = new Listener(this.state, this.emit.bind(this), this.packetSender);
|
|
115
136
|
// For reading packet
|
|
116
137
|
const versionCodec = new VersionCodec(this.state);
|
|
117
138
|
// For throwing packet through internet
|
|
@@ -126,12 +147,12 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
126
147
|
this.tcp.forwardPacket = versionCodec.handlePacket.bind(versionCodec);
|
|
127
148
|
this.tcp.parsePacket = versionCodec.encodePacket.bind(versionCodec);
|
|
128
149
|
this.tcp.sendInitPacket = () => {
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
this.packetSender.sendHandshake();
|
|
151
|
+
this.packetSender.sendLoginStart();
|
|
131
152
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
versionCodec.consumePacket =
|
|
153
|
+
this.packetSender.sendPacket = this.tcp.sendPacket.bind(this.tcp);
|
|
154
|
+
this.packetListener.disconnect = this.disconnect.bind(this);
|
|
155
|
+
versionCodec.consumePacket = this.packetListener.handlePacket.bind(this.packetListener);
|
|
135
156
|
|
|
136
157
|
// For querying data
|
|
137
158
|
this.blocks = new BlockManager(this.state);
|
|
@@ -143,10 +164,10 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
143
164
|
this.entities,
|
|
144
165
|
this.blocks,
|
|
145
166
|
);
|
|
146
|
-
this.player.sendPlayerPos =
|
|
147
|
-
this.player.sendPlayerPosRot =
|
|
148
|
-
this.player.sendPlayerRot =
|
|
149
|
-
this.player.sendPlayerStatus =
|
|
167
|
+
this.player.sendPlayerPos = this.packetSender.sendPlayerPos;
|
|
168
|
+
this.player.sendPlayerPosRot = this.packetSender.sendPlayerPosRot;
|
|
169
|
+
this.player.sendPlayerRot = this.packetSender.sendPlayerRot;
|
|
170
|
+
this.player.sendPlayerStatus = this.packetSender.sendPlayerStatus;
|
|
150
171
|
|
|
151
172
|
// For tick-tock tick-tock
|
|
152
173
|
this.tickLoop = new TickLoop(() => {
|
|
@@ -159,6 +180,11 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
159
180
|
// Forward TCP events
|
|
160
181
|
this.tcp.on("connect", () => this.emit("connect"));
|
|
161
182
|
this.tcp.on("destroy", () => this.emit("destroy"));
|
|
183
|
+
this.on("loadChunk", (sx, sy, sz) => this.blocks.deleteChunkCache(sx, sy, sz));
|
|
184
|
+
this.on("unloadChunk", (sx, sz) => {
|
|
185
|
+
for (let sy = 0; sy < 16; sy++)
|
|
186
|
+
this.blocks.deleteChunkCache(sx, sy, sz);
|
|
187
|
+
});
|
|
162
188
|
}
|
|
163
189
|
|
|
164
190
|
private emitEvent(event: EmittedEvent) {
|
|
@@ -168,9 +194,11 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
168
194
|
private async loadRegistries() {
|
|
169
195
|
if (Client.loadRegistry) return;
|
|
170
196
|
Client.loadRegistry = true;
|
|
171
|
-
|
|
172
|
-
await
|
|
173
|
-
await
|
|
197
|
+
const { version } = this.options;
|
|
198
|
+
await BlockRegistry.load(version);
|
|
199
|
+
await EntityRegistry.load(version);
|
|
200
|
+
await PacketRegistry.load(version);
|
|
201
|
+
await EffectRegistry.load(version);
|
|
174
202
|
}
|
|
175
203
|
|
|
176
204
|
// Start / stop
|
|
@@ -239,6 +267,13 @@ export class Client<IsReady extends boolean = boolean> extends (EventEmitter as
|
|
|
239
267
|
this.player.releaseAllInputs();
|
|
240
268
|
}
|
|
241
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Send a message
|
|
272
|
+
*/
|
|
273
|
+
public chat(message: string) {
|
|
274
|
+
this.packetSender.sendMessage(message);
|
|
275
|
+
}
|
|
276
|
+
|
|
242
277
|
// World
|
|
243
278
|
/**
|
|
244
279
|
* Get the block state at position
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
export * from "./base/bitset";
|
|
2
|
+
export * from "./base/buffer";
|
|
3
|
+
export * from "./base/cache";
|
|
2
4
|
export * from "./base/error";
|
|
3
5
|
export * from "./base/event";
|
|
6
|
+
export * from "./base/http";
|
|
4
7
|
export * from "./base/math";
|
|
5
8
|
export * from "./base/typing";
|
|
9
|
+
export * from "./binary/decoder";
|
|
10
|
+
export * from "./binary/encoder";
|
|
11
|
+
export * from "./binary/static";
|
|
6
12
|
export * from "./client/auth";
|
|
7
13
|
export * from "./client/client";
|
|
8
|
-
export * from "./client/
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./
|
|
14
|
+
export * from "./client/static";
|
|
15
|
+
export * from "./message/link";
|
|
16
|
+
export * from "./message/sigCache";
|
|
17
|
+
export * from "./net/tcp";
|
|
18
|
+
export * from "./packet/listener";
|
|
19
|
+
export * from "./packet/sender";
|
|
12
20
|
export * from "./physics/aabb";
|
|
13
21
|
export * from "./physics/direction";
|
|
14
22
|
export * from "./physics/player";
|
package/src/message/link.ts
CHANGED
package/src/message/sigCache.ts
CHANGED
|
@@ -3,18 +3,14 @@ import { EventEmitter } from "node:events";
|
|
|
3
3
|
import { deflateSync, inflateSync } from "node:zlib";
|
|
4
4
|
|
|
5
5
|
import { TypedEmmiter } from "../base/event";
|
|
6
|
-
import { BinaryDecoder } from "../
|
|
7
|
-
import { BinaryEncoder } from "../
|
|
8
|
-
import { AuthOption } from "
|
|
6
|
+
import { BinaryDecoder } from "../binary/decoder";
|
|
7
|
+
import { BinaryEncoder } from "../binary/encoder";
|
|
8
|
+
import { AuthOption } from "../client/auth";
|
|
9
9
|
import { ClientStatus, SharedState } from "../world/state";
|
|
10
10
|
import { EncodeResult } from "../version/codec";
|
|
11
11
|
import { TextComponent } from "../base/typing";
|
|
12
12
|
import { NotImplemented, SockerIsNotWritable, UnexpectedValue } from "../base/error";
|
|
13
13
|
|
|
14
|
-
// Minecraft related typing
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
14
|
// TCP related typing
|
|
19
15
|
export interface TCPClientOption {
|
|
20
16
|
/** Server host */
|
|
@@ -72,7 +68,7 @@ export interface Message {
|
|
|
72
68
|
/**
|
|
73
69
|
* Low-level client. You SHOULD NOT use this client unless you know what are you doing
|
|
74
70
|
*
|
|
75
|
-
* @see https://minecraft.wiki/w/Java_Edition_protocol/Packets
|
|
71
|
+
* @see https://minecraft.wiki/w/Java_Edition_protocol/Packets
|
|
76
72
|
*/
|
|
77
73
|
export class TCPClient extends (EventEmitter as new () => TypedEmmiter<TCPClientEvents>) {
|
|
78
74
|
public readonly socket: Socket;
|