@vaitosoi/minejs 0.6.0 → 0.6.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 +23 -11
- package/assets/minecraft/26.2/packets.json +0 -12
- package/assets/minecraft/26.3/packets.json +228 -38
- package/dist/binary/encoder.d.ts.map +1 -1
- package/dist/binary/encoder.js +4 -4
- package/dist/binary/encoder.js.map +1 -1
- package/dist/client/client.d.ts +127 -28
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +108 -27
- package/dist/client/client.js.map +1 -1
- package/dist/net/tcp.d.ts +0 -7
- package/dist/net/tcp.d.ts.map +1 -1
- package/dist/net/tcp.js +12 -18
- package/dist/net/tcp.js.map +1 -1
- package/dist/packet/listener.d.ts +1 -1
- package/dist/packet/listener.d.ts.map +1 -1
- package/dist/packet/listener.js +142 -55
- package/dist/packet/listener.js.map +1 -1
- package/dist/packet/sender.d.ts +2 -1
- package/dist/packet/sender.d.ts.map +1 -1
- package/dist/packet/sender.js +17 -6
- package/dist/packet/sender.js.map +1 -1
- package/dist/physics/aabb.d.ts.map +1 -1
- package/dist/physics/aabb.js +10 -2
- package/dist/physics/aabb.js.map +1 -1
- package/dist/physics/direction.js +2 -2
- package/dist/physics/direction.js.map +1 -1
- package/dist/version/codec.d.ts.map +1 -1
- package/dist/version/codec.js +38 -0
- package/dist/version/codec.js.map +1 -1
- package/dist/version/registry.d.ts +6 -1
- package/dist/version/registry.d.ts.map +1 -1
- package/dist/version/registry.js +26 -3
- package/dist/version/registry.js.map +1 -1
- package/dist/world/block.d.ts +44 -2
- package/dist/world/block.d.ts.map +1 -1
- package/dist/world/block.js +61 -21
- package/dist/world/block.js.map +1 -1
- package/dist/world/entity.d.ts +3 -0
- package/dist/world/entity.d.ts.map +1 -1
- package/dist/world/entity.js +3 -0
- package/dist/world/entity.js.map +1 -1
- package/dist/world/state.d.ts +3 -0
- package/dist/world/state.d.ts.map +1 -1
- package/dist/world/state.js +9 -0
- package/dist/world/state.js.map +1 -1
- package/package.json +2 -2
- package/src/binary/encoder.ts +5 -6
- package/src/client/client.ts +174 -51
- package/src/net/tcp.ts +12 -18
- package/src/packet/listener.ts +172 -70
- package/src/packet/sender.ts +18 -7
- package/src/physics/aabb.ts +11 -2
- package/src/physics/direction.ts +2 -2
- package/src/version/codec.ts +32 -0
- package/src/version/registry.ts +35 -5
- package/src/world/block.ts +64 -22
- package/src/world/entity.ts +3 -0
- package/src/world/state.ts +10 -0
- package/test/client/index.ts +13 -6
package/dist/client/client.d.ts
CHANGED
|
@@ -8,11 +8,14 @@ import { Entity } from "../world/state";
|
|
|
8
8
|
import { CacheImplementation } from "../base/cache";
|
|
9
9
|
import { Container, Slot } from "../world/container";
|
|
10
10
|
export type ClientOption = Omit<TCPClientOption, "protocolVersion"> & {
|
|
11
|
+
/**
|
|
12
|
+
* The client version. Supports 26.2 and 26.3
|
|
13
|
+
*/
|
|
11
14
|
version: string;
|
|
12
15
|
/**
|
|
13
|
-
* Whenever should the client verify the message against the signature, if any
|
|
16
|
+
* Whenever should the client verify the message against the signature, if any.
|
|
14
17
|
*
|
|
15
|
-
*
|
|
18
|
+
* In order to set this option to true, you HAVE TO set `shouldVerifyMessageOrder` to true
|
|
16
19
|
*/
|
|
17
20
|
shouldVerifyMessageSignature?: boolean;
|
|
18
21
|
/**
|
|
@@ -40,26 +43,47 @@ export interface ClientEvents {
|
|
|
40
43
|
/**
|
|
41
44
|
* When the client is ready.
|
|
42
45
|
*
|
|
43
|
-
* Specifically, when the packet `Login (play)` is received
|
|
46
|
+
* Specifically, when the packet `Login (play)` is received.
|
|
47
|
+
*
|
|
48
|
+
* Most of the client method require this event to be fired in order to work.
|
|
44
49
|
*/
|
|
45
50
|
ready: [];
|
|
46
51
|
/**
|
|
47
|
-
* When the client got disconnected from
|
|
52
|
+
* When the client got disconnected from server.
|
|
53
|
+
*
|
|
54
|
+
* This event only provide the parsed string. To get the unparsed, or the raw one with decoration, use `disconnectRaw`.
|
|
55
|
+
* But, the `disconnectRaw` is only fired when the disconnection come from the server, or the server disconnect the client.
|
|
56
|
+
* Sometime, the disconnect will be fired within the client, meaning that there will be no `disconnectRaw`
|
|
48
57
|
*/
|
|
49
58
|
disconnect: [reason: string];
|
|
50
59
|
/**
|
|
51
|
-
* When the
|
|
60
|
+
* When the disconnection come with the raw Text Component.
|
|
52
61
|
*/
|
|
53
62
|
disconnectRaw: [textComponent: TextComponent];
|
|
63
|
+
/** The registry_data packet */
|
|
64
|
+
registryData: [data: RegistryData];
|
|
54
65
|
/**
|
|
55
|
-
* When server send `Player Position Synchronization` packet
|
|
66
|
+
* When server send `Player Position Synchronization` packet.
|
|
56
67
|
*
|
|
57
|
-
* Note
|
|
68
|
+
* **Note:** this event is not fired when the client is moved by holding the input.
|
|
69
|
+
*
|
|
70
|
+
* To get the player current position, use `getPosition` method
|
|
58
71
|
*/
|
|
59
72
|
playerPosition: [position: BaseVec3];
|
|
60
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* When the chunk is loaded
|
|
75
|
+
*
|
|
76
|
+
* Explaining the `chunkX`, `sectionY`, `chunkZ`: A chunk in Minecraft is a region which length and width is 16 and the height extends to the limit.
|
|
77
|
+
* But when sending the packet, the chunk is divided into smaller section which volume is 16x16x16.
|
|
78
|
+
* So the `chunkX` and `chunkZ` is the chunk position and `sectionY` is the section within that chunk,
|
|
79
|
+
* counting from the bedrock up to the sky
|
|
80
|
+
*/
|
|
61
81
|
loadChunk: [chunkX: number, sectionY: number, chunkZ: number];
|
|
62
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* When the chunk got deleted by the server
|
|
84
|
+
*
|
|
85
|
+
* See the `chunkX` and `chunkZ` explaination in `loadChunk` events
|
|
86
|
+
*/
|
|
63
87
|
unloadChunk: [chunkX: number, chunkZ: number];
|
|
64
88
|
/** When an entity is spawned or appeared in the client view distance */
|
|
65
89
|
spawnEntity: [entity: Entity];
|
|
@@ -67,21 +91,34 @@ export interface ClientEvents {
|
|
|
67
91
|
updateEntity: [entityId: number];
|
|
68
92
|
/** When an entity go out of client view distance or despawned */
|
|
69
93
|
removeEntity: [entityId: number];
|
|
70
|
-
/** The registry_data packet */
|
|
71
|
-
registryData: [data: RegistryData];
|
|
72
94
|
/** When a chat message got broadcasted */
|
|
73
95
|
message: [message: Message];
|
|
74
96
|
/** When a message is failed to be verified against the signature sent with it */
|
|
75
97
|
failedMessage: [message: Message];
|
|
76
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* The system message
|
|
100
|
+
*
|
|
101
|
+
* This event only provide the parsed string. To get the unparsed, or the raw one with decoration, use `systemMessageRaw`
|
|
102
|
+
*/
|
|
77
103
|
systemMessage: [message: string];
|
|
78
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* The system message with the Text Component for decorations
|
|
106
|
+
*/
|
|
79
107
|
systemMessageRaw: [textComponent: TextComponent];
|
|
80
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* The action bar
|
|
110
|
+
*
|
|
111
|
+
* This event only provide the parsed string. To get the unparsed, or the raw one with decoration, use `actionBarRaw`
|
|
112
|
+
*/
|
|
81
113
|
actionBar: [message: string];
|
|
82
114
|
/** The raw action bar */
|
|
83
115
|
actionBarRaw: [textComponent: TextComponent];
|
|
84
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* When a container is opened
|
|
118
|
+
*
|
|
119
|
+
* This event will be fired when client click on a block (with `openBlock` method) that is a container
|
|
120
|
+
* or when server believe that you just open a container (with open_screen packet).
|
|
121
|
+
*/
|
|
85
122
|
openContainer: [container: Container];
|
|
86
123
|
/** When the opening container is closed */
|
|
87
124
|
closeContainer: [];
|
|
@@ -108,6 +145,34 @@ export interface ClientEvents {
|
|
|
108
145
|
declare const Client_base: new () => TypedEmitter<ClientEvents>;
|
|
109
146
|
/**
|
|
110
147
|
* High-level client.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const client = new Client({
|
|
152
|
+
* playerName: "bot", // Put your name here
|
|
153
|
+
* host: "localhost", // Put the server address
|
|
154
|
+
* port: 25565, // 25565 is the default port, change to your server's port if needed
|
|
155
|
+
* version: "26.2", // The client version
|
|
156
|
+
* loadRegistry: false, //
|
|
157
|
+
* // auth: { // This things is not working yet
|
|
158
|
+
* // client_id: "d86254d8-edf7-4640-90eb-643c99af188e",
|
|
159
|
+
* // method: "loopback",
|
|
160
|
+
* // openBrowser: true,
|
|
161
|
+
* // port: 12345
|
|
162
|
+
* // },
|
|
163
|
+
* // shouldVerifyMessageOrder: true,
|
|
164
|
+
* // shouldVerifyMessageSignature: true
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* // MineJs is a event driven library, the same way DiscordJS work (if you know them).
|
|
168
|
+
* // One thing to note is most of method in this client require client to be ready,
|
|
169
|
+
* // meaning that unless the "ready" event is fired, you can't do, mostly, anything :D
|
|
170
|
+
* client.on("ready", () => console.log("Client is ready :yay:"));
|
|
171
|
+
*
|
|
172
|
+
* // The init step before is just init the data and does not create the connection yet.
|
|
173
|
+
* // This method will create that connection.
|
|
174
|
+
* client.connect();
|
|
175
|
+
* ```
|
|
111
176
|
*/
|
|
112
177
|
export declare class Client extends Client_base {
|
|
113
178
|
private options;
|
|
@@ -128,65 +193,99 @@ export declare class Client extends Client_base {
|
|
|
128
193
|
*/
|
|
129
194
|
connect(): Promise<void>;
|
|
130
195
|
/**
|
|
131
|
-
* Destroy the connection
|
|
196
|
+
* Destroy the connection.
|
|
197
|
+
*
|
|
198
|
+
* Calling this method will also fire the "disconnect" event.
|
|
132
199
|
*/
|
|
133
200
|
disconnect(reason?: string, raw?: TextComponent): void;
|
|
134
201
|
/**
|
|
135
|
-
* Press and hold a key
|
|
202
|
+
* Press and hold a key.
|
|
203
|
+
*
|
|
204
|
+
* This is pretty the same idea as when you play Minecraft.
|
|
205
|
+
* When you need to go forward, you have to hold the key `W`, `S` for backward, etc...
|
|
206
|
+
*
|
|
207
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
136
208
|
*/
|
|
137
|
-
hold(
|
|
209
|
+
hold(input: Input): void;
|
|
138
210
|
/**
|
|
139
|
-
* Release a key
|
|
211
|
+
* Release a key.
|
|
212
|
+
*
|
|
213
|
+
* This is also pretty the same idea as when you play Minecraft.
|
|
214
|
+
* Need to stop, stop holding `W`, `S` key, etc...
|
|
215
|
+
*
|
|
216
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
140
217
|
*/
|
|
141
218
|
release(input: Input): void;
|
|
142
219
|
/**
|
|
143
|
-
* Release all key
|
|
220
|
+
* Release all key.
|
|
221
|
+
*
|
|
222
|
+
* This is the shortcut for release all keys.
|
|
223
|
+
* Instead of calling `release` method for each keys, just call this
|
|
224
|
+
*
|
|
225
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
144
226
|
*/
|
|
145
227
|
stopMoving(): void;
|
|
146
228
|
/**
|
|
147
229
|
* Send a message
|
|
230
|
+
*
|
|
231
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
148
232
|
*/
|
|
149
233
|
chat(message: string): void;
|
|
150
234
|
/**
|
|
151
235
|
* Get the block state at position
|
|
236
|
+
*
|
|
237
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
152
238
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
239
|
+
getBlock(x: number, y: number, z: number): BlockState | null;
|
|
240
|
+
getBlock(position: BaseVec3): BlockState | null;
|
|
155
241
|
/**
|
|
156
|
-
*
|
|
242
|
+
* Get player position
|
|
157
243
|
*
|
|
158
|
-
* @
|
|
244
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
245
|
+
*/
|
|
246
|
+
getPosition(): BaseVec3;
|
|
247
|
+
/**
|
|
248
|
+
* Rotate your face
|
|
159
249
|
*
|
|
160
250
|
* "Yaw is measured in degrees and does not follow classical trigonometry rules.
|
|
161
251
|
* The unit circle of yaw on the XZ-plane starts at (0, 1) and turns counterclockwise, with 90 at (-1, 0), 180 at (0, -1) and 270 at (1, 0).
|
|
162
252
|
*
|
|
163
253
|
* Pitch is measured in degrees, where 0 is looking straight ahead, -90 is looking straight up, and 90 is looking straight down."
|
|
164
254
|
*
|
|
255
|
+
* @see https://minecraft.wiki/w/Java_Edition_protocol/Packets#Synchronize_Player_Position For Yaw and Pitch definition
|
|
256
|
+
*
|
|
165
257
|
* @param yaw In degree
|
|
166
258
|
* @param pitch In degree
|
|
259
|
+
*
|
|
260
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
167
261
|
*/
|
|
168
262
|
lookAt(yaw: number, pitch: number): void;
|
|
169
263
|
/**
|
|
170
264
|
* Get opening container.
|
|
171
265
|
*
|
|
172
|
-
* Return `undefined` if
|
|
266
|
+
* Return `undefined` if nothing is opening
|
|
267
|
+
*
|
|
268
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
173
269
|
*/
|
|
174
270
|
getOpeningContainer(): Container | undefined;
|
|
175
271
|
/**
|
|
176
272
|
* Get carrying item.
|
|
177
273
|
*
|
|
178
|
-
* Return `undefined` if
|
|
274
|
+
* Return `undefined` if nothing is carried
|
|
275
|
+
*
|
|
276
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
179
277
|
*/
|
|
180
278
|
getCarryingItem(): Slot | undefined;
|
|
181
279
|
/**
|
|
182
280
|
* Get player's inventory
|
|
281
|
+
*
|
|
282
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
183
283
|
*/
|
|
184
284
|
getInventory(): Container | undefined;
|
|
185
285
|
/**
|
|
186
286
|
* Open a block.
|
|
187
287
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
288
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
190
289
|
* @returns `true` if the target block is a solid block, or else, return `false`
|
|
191
290
|
*/
|
|
192
291
|
openBlock(x: number, y: number, z: number): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,UAAU,EAA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;;;;;OAMG;IACI,mBAAmB,0BAGzB;IACD;;;;;;OAMG;IACI,eAAe,qBAGrB;IACD;;;;OAIG;IACI,YAAY,0BAGlB;IAED;;;;;OAKG;IACI,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACpD,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;CA8BjD"}
|
package/dist/client/client.js
CHANGED
|
@@ -18,6 +18,34 @@ const error_1 = require("../base/error");
|
|
|
18
18
|
const sender_1 = require("../packet/sender");
|
|
19
19
|
/**
|
|
20
20
|
* High-level client.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const client = new Client({
|
|
25
|
+
* playerName: "bot", // Put your name here
|
|
26
|
+
* host: "localhost", // Put the server address
|
|
27
|
+
* port: 25565, // 25565 is the default port, change to your server's port if needed
|
|
28
|
+
* version: "26.2", // The client version
|
|
29
|
+
* loadRegistry: false, //
|
|
30
|
+
* // auth: { // This things is not working yet
|
|
31
|
+
* // client_id: "d86254d8-edf7-4640-90eb-643c99af188e",
|
|
32
|
+
* // method: "loopback",
|
|
33
|
+
* // openBrowser: true,
|
|
34
|
+
* // port: 12345
|
|
35
|
+
* // },
|
|
36
|
+
* // shouldVerifyMessageOrder: true,
|
|
37
|
+
* // shouldVerifyMessageSignature: true
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // MineJs is a event driven library, the same way DiscordJS work (if you know them).
|
|
41
|
+
* // One thing to note is most of method in this client require client to be ready,
|
|
42
|
+
* // meaning that unless the "ready" event is fired, you can't do, mostly, anything :D
|
|
43
|
+
* client.on("ready", () => console.log("Client is ready :yay:"));
|
|
44
|
+
*
|
|
45
|
+
* // The init step before is just init the data and does not create the connection yet.
|
|
46
|
+
* // This method will create that connection.
|
|
47
|
+
* client.connect();
|
|
48
|
+
* ```
|
|
21
49
|
*/
|
|
22
50
|
class Client extends node_events_1.EventEmitter {
|
|
23
51
|
options;
|
|
@@ -35,6 +63,7 @@ class Client extends node_events_1.EventEmitter {
|
|
|
35
63
|
throw new error_1.HaveSignatureButNotIndex();
|
|
36
64
|
super();
|
|
37
65
|
this.options = options;
|
|
66
|
+
this.loadRegistries();
|
|
38
67
|
// For managing shared data
|
|
39
68
|
this.state = new state_1.SharedState(options);
|
|
40
69
|
// For handling packet
|
|
@@ -84,22 +113,21 @@ class Client extends node_events_1.EventEmitter {
|
|
|
84
113
|
emitEvent(event) {
|
|
85
114
|
this.emit(event.event, ...event.args);
|
|
86
115
|
}
|
|
87
|
-
|
|
116
|
+
loadRegistries() {
|
|
88
117
|
if (Client.loadRegistry)
|
|
89
118
|
return;
|
|
90
119
|
Client.loadRegistry = true;
|
|
91
120
|
const { version } = this.options;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
121
|
+
registry_1.BlockRegistry.load(version);
|
|
122
|
+
registry_1.EntityRegistry.load(version);
|
|
123
|
+
registry_1.PacketRegistry.load(version);
|
|
124
|
+
registry_1.EffectRegistry.load(version);
|
|
96
125
|
}
|
|
97
126
|
// Start / stop
|
|
98
127
|
/**
|
|
99
128
|
* Create a connection to the server
|
|
100
129
|
*/
|
|
101
130
|
async connect() {
|
|
102
|
-
await this.loadRegistries();
|
|
103
131
|
if (!this.state.playerUUID) {
|
|
104
132
|
if (this.options.auth) {
|
|
105
133
|
this.state.authClient = new auth_1.AuthClient(this.options.auth);
|
|
@@ -123,7 +151,9 @@ class Client extends node_events_1.EventEmitter {
|
|
|
123
151
|
});
|
|
124
152
|
}
|
|
125
153
|
/**
|
|
126
|
-
* Destroy the connection
|
|
154
|
+
* Destroy the connection.
|
|
155
|
+
*
|
|
156
|
+
* Calling this method will also fire the "disconnect" event.
|
|
127
157
|
*/
|
|
128
158
|
disconnect(reason = "Disconnect", raw) {
|
|
129
159
|
this.state.state = state_1.ConnectionState.Disconnected;
|
|
@@ -140,77 +170,128 @@ class Client extends node_events_1.EventEmitter {
|
|
|
140
170
|
}
|
|
141
171
|
// Inputs
|
|
142
172
|
/**
|
|
143
|
-
* Press and hold a key
|
|
173
|
+
* Press and hold a key.
|
|
174
|
+
*
|
|
175
|
+
* This is pretty the same idea as when you play Minecraft.
|
|
176
|
+
* When you need to go forward, you have to hold the key `W`, `S` for backward, etc...
|
|
177
|
+
*
|
|
178
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
144
179
|
*/
|
|
145
|
-
hold(
|
|
146
|
-
this.
|
|
180
|
+
hold(input) {
|
|
181
|
+
this.state.checkReady();
|
|
182
|
+
this.player.input(input);
|
|
147
183
|
}
|
|
148
184
|
/**
|
|
149
|
-
* Release a key
|
|
185
|
+
* Release a key.
|
|
186
|
+
*
|
|
187
|
+
* This is also pretty the same idea as when you play Minecraft.
|
|
188
|
+
* Need to stop, stop holding `W`, `S` key, etc...
|
|
189
|
+
*
|
|
190
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
150
191
|
*/
|
|
151
192
|
release(input) {
|
|
193
|
+
this.state.checkReady();
|
|
152
194
|
this.player.releaseInput(input);
|
|
153
195
|
}
|
|
154
196
|
/**
|
|
155
|
-
* Release all key
|
|
197
|
+
* Release all key.
|
|
198
|
+
*
|
|
199
|
+
* This is the shortcut for release all keys.
|
|
200
|
+
* Instead of calling `release` method for each keys, just call this
|
|
201
|
+
*
|
|
202
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
156
203
|
*/
|
|
157
204
|
stopMoving() {
|
|
205
|
+
this.state.checkReady();
|
|
158
206
|
this.player.releaseAllInputs();
|
|
159
207
|
}
|
|
160
208
|
/**
|
|
161
209
|
* Send a message
|
|
210
|
+
*
|
|
211
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
162
212
|
*/
|
|
163
213
|
chat(message) {
|
|
214
|
+
this.state.checkReady();
|
|
164
215
|
this.packetSender.sendMessage(message);
|
|
165
216
|
}
|
|
166
|
-
|
|
217
|
+
getBlock(a, b, c) {
|
|
167
218
|
const vec3 = direction_1.Vec3.loadArgs(a, b, c);
|
|
168
219
|
return this.blocks.at(vec3);
|
|
169
220
|
}
|
|
170
221
|
/**
|
|
171
|
-
*
|
|
222
|
+
* Get player position
|
|
172
223
|
*
|
|
173
|
-
* @
|
|
224
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
225
|
+
*/
|
|
226
|
+
getPosition() {
|
|
227
|
+
this.state.checkReady();
|
|
228
|
+
return structuredClone(this.state.player.position);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Rotate your face
|
|
174
232
|
*
|
|
175
233
|
* "Yaw is measured in degrees and does not follow classical trigonometry rules.
|
|
176
234
|
* The unit circle of yaw on the XZ-plane starts at (0, 1) and turns counterclockwise, with 90 at (-1, 0), 180 at (0, -1) and 270 at (1, 0).
|
|
177
235
|
*
|
|
178
236
|
* Pitch is measured in degrees, where 0 is looking straight ahead, -90 is looking straight up, and 90 is looking straight down."
|
|
179
237
|
*
|
|
238
|
+
* @see https://minecraft.wiki/w/Java_Edition_protocol/Packets#Synchronize_Player_Position For Yaw and Pitch definition
|
|
239
|
+
*
|
|
180
240
|
* @param yaw In degree
|
|
181
241
|
* @param pitch In degree
|
|
242
|
+
*
|
|
243
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
182
244
|
*/
|
|
183
245
|
lookAt(yaw, pitch) {
|
|
246
|
+
this.state.checkReady();
|
|
184
247
|
this.player.setAngle(yaw, pitch);
|
|
185
248
|
}
|
|
186
249
|
/**
|
|
187
250
|
* Get opening container.
|
|
188
251
|
*
|
|
189
|
-
* Return `undefined` if
|
|
252
|
+
* Return `undefined` if nothing is opening
|
|
253
|
+
*
|
|
254
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
190
255
|
*/
|
|
191
|
-
getOpeningContainer() {
|
|
256
|
+
getOpeningContainer() {
|
|
257
|
+
this.state.checkReady();
|
|
258
|
+
return this.state.openingContainer;
|
|
259
|
+
}
|
|
192
260
|
/**
|
|
193
261
|
* Get carrying item.
|
|
194
262
|
*
|
|
195
|
-
* Return `undefined` if
|
|
263
|
+
* Return `undefined` if nothing is carried
|
|
264
|
+
*
|
|
265
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
196
266
|
*/
|
|
197
|
-
getCarryingItem() {
|
|
267
|
+
getCarryingItem() {
|
|
268
|
+
this.state.checkReady();
|
|
269
|
+
return this.state.player?.carryingItem;
|
|
270
|
+
}
|
|
198
271
|
/**
|
|
199
272
|
* Get player's inventory
|
|
273
|
+
*
|
|
274
|
+
* @throws {ClientNotReady} When the client is not ready
|
|
200
275
|
*/
|
|
201
|
-
getInventory() {
|
|
276
|
+
getInventory() {
|
|
277
|
+
this.state.checkReady();
|
|
278
|
+
return this.state.player?.inventory;
|
|
279
|
+
}
|
|
202
280
|
openBlock(a, b, c) {
|
|
203
281
|
this.state.checkReady();
|
|
204
282
|
const vec3 = direction_1.Vec3.loadArgs(a, b, c);
|
|
205
|
-
const
|
|
206
|
-
|
|
283
|
+
const eyePos = new direction_1.Vec3(this.state.player.position).add(0, 1.62, 0);
|
|
284
|
+
const target = new direction_1.Vec3(vec3).add(0.5, 0.5, 0.5); // aim at block center, or use look direction
|
|
285
|
+
const reach = 4.5; // survival reach, adjust as needed
|
|
286
|
+
const dir = target.subtract(eyePos).normalize();
|
|
287
|
+
const to = eyePos.add(dir.scale(reach));
|
|
288
|
+
const clipResult = block_1.BlockGetter.clip(eyePos, to, (pos) => this.blocks.at(pos).shape);
|
|
207
289
|
if (clipResult.miss)
|
|
208
290
|
return false;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}, false, false);
|
|
291
|
+
const cursorX = Math.abs(clipResult.location.x - clipResult.pos.x), cursorY = Math.abs(clipResult.location.y - clipResult.pos.y), cursorZ = Math.abs(clipResult.location.z - clipResult.pos.z);
|
|
292
|
+
if (cursorX > 1 || cursorY > 1 || cursorZ > 1)
|
|
293
|
+
return false;
|
|
294
|
+
this.packetSender.sendUseItemOn("main", vec3, clipResult.direction, { x: cursorX, y: cursorY, z: cursorZ }, false, false);
|
|
214
295
|
return true;
|
|
215
296
|
}
|
|
216
297
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,0CAAuE;AACvE,4CAAkD;AAClD,8CAAkD;AAClD,wCAAyC;AACzC,oCAAiE;AAEjE,kDAA4H;AAC5H,oDAAsD;AAEtD,0CAAkH;AAClH,iDAA8C;AAC9C,4CAAgD;AAChD,iCAAoC;AACpC,uCAA2C;AAC3C,yCAAyD;AACzD,6CAA0C;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,0CAAuE;AACvE,4CAAkD;AAClD,8CAAkD;AAClD,wCAAyC;AACzC,oCAAiE;AAEjE,kDAA4H;AAC5H,oDAAsD;AAEtD,0CAAkH;AAClH,iDAA8C;AAC9C,4CAAgD;AAChD,iCAAoC;AACpC,uCAA2C;AAC3C,yCAAyD;AACzD,6CAA0C;AAmJ1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,YAAoB,SAAS,0BAAqD;IAc1D,OAAO;IAbnB,MAAM,CAAC,YAAY,GAAY,KAAK,CAAC;IAErC,QAAQ,CAAW;IAEnB,MAAM,CAAe;IACrB,QAAQ,CAAkB;IAC1B,MAAM,CAAS;IAEf,GAAG,CAAY;IACf,KAAK,CAAc;IACnB,cAAc,CAAW;IACzB,YAAY,CAAS;IAE7B,YAAoB,OAAqB;QACrC,IAAI,OAAO,CAAC,4BAA4B,KAAK,IAAI,IAAI,OAAO,CAAC,wBAAwB,KAAK,IAAI;YAC1F,MAAM,IAAI,gCAAwB,EAAE,CAAC;QAEzC,KAAK,EAAE,CAAC;uBAJQ,OAAO;QAKvB,IAAI,CAAC,c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AAU,CAAC,SAAS,EACpB,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EACtC,KAAK,EACL,KAAK,CACR,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
package/dist/net/tcp.d.ts
CHANGED
|
@@ -59,13 +59,6 @@ export declare class TCPClient extends TCPClient_base {
|
|
|
59
59
|
private state;
|
|
60
60
|
readonly option: TCPClientOption;
|
|
61
61
|
readonly socket: Socket;
|
|
62
|
-
/**
|
|
63
|
-
* | Value | Meaning |
|
|
64
|
-
* |-------|---------|
|
|
65
|
-
* | 0 | not set yet |
|
|
66
|
-
* | -1 | dont compress |
|
|
67
|
-
* | > 0 | compression threshold |
|
|
68
|
-
*/
|
|
69
62
|
private bufferPool;
|
|
70
63
|
constructor(state: SharedState, option: TCPClientOption, socketOption?: SocketConstructorOpts);
|
|
71
64
|
sendInitPacket: () => void;
|
package/dist/net/tcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp.d.ts","sourceRoot":"","sources":["../../src/net/tcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAIzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAgB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI/C,MAAM,WAAW,eAAe;IAC5B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,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G/B,OAAO,CAAC,UAAU,CAA2B;IAE7C,YACY,KAAK,EAAE,WAAW,EACV,MAAM,EAAE,eAAe,EACvC,YAAY,CAAC,EAAE,qBAAqB,EAIvC;IAEM,cAAc,EAAE,MAAM,IAAI,CAAyC;IACnE,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAyC;IAC1G,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,YAAY,CAAyC;IAEtH;;OAEG;IACI,OAAO,SAyBb;IAEM,UAAU,SAGhB;IAMD,OAAO,CAAC,YAAY;IAmDb,KAAK,CAAC,GAAG,EAAE,MAAM,QASvB;IAEM,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAiCrE;CAEJ"}
|
package/dist/net/tcp.js
CHANGED
|
@@ -23,13 +23,6 @@ class TCPClient extends node_events_1.EventEmitter {
|
|
|
23
23
|
option;
|
|
24
24
|
socket;
|
|
25
25
|
// Internal var
|
|
26
|
-
/**
|
|
27
|
-
* | Value | Meaning |
|
|
28
|
-
* |-------|---------|
|
|
29
|
-
* | 0 | not set yet |
|
|
30
|
-
* | -1 | dont compress |
|
|
31
|
-
* | > 0 | compression threshold |
|
|
32
|
-
*/
|
|
33
26
|
bufferPool = Buffer.alloc(0);
|
|
34
27
|
constructor(state, option, socketOption) {
|
|
35
28
|
super();
|
|
@@ -77,7 +70,7 @@ class TCPClient extends node_events_1.EventEmitter {
|
|
|
77
70
|
*/
|
|
78
71
|
handlePacket() {
|
|
79
72
|
while (this.bufferPool.length > 0) {
|
|
80
|
-
|
|
73
|
+
const decoder = new decoder_1.BinaryDecoder(this.bufferPool);
|
|
81
74
|
let packetLength;
|
|
82
75
|
try {
|
|
83
76
|
packetLength = decoder.readVarInt();
|
|
@@ -89,32 +82,33 @@ class TCPClient extends node_events_1.EventEmitter {
|
|
|
89
82
|
break;
|
|
90
83
|
const expectedPacketEnd = decoder.offset + packetLength;
|
|
91
84
|
let packetID;
|
|
85
|
+
let packetDecoder = new decoder_1.BinaryDecoder(decoder.buffer.subarray(decoder.offset, expectedPacketEnd));
|
|
92
86
|
if (this.state.compressionThreshold === 0)
|
|
93
|
-
packetID =
|
|
87
|
+
packetID = packetDecoder.readVarInt();
|
|
94
88
|
else if (this.state.compressionThreshold === -1) {
|
|
95
|
-
|
|
96
|
-
packetID =
|
|
89
|
+
packetDecoder.readVarInt();
|
|
90
|
+
packetID = packetDecoder.readVarInt();
|
|
97
91
|
}
|
|
98
92
|
else {
|
|
99
|
-
const dataLength =
|
|
93
|
+
const dataLength = packetDecoder.readVarInt();
|
|
100
94
|
if (dataLength === 0) {
|
|
101
|
-
packetID =
|
|
95
|
+
packetID = packetDecoder.readVarInt();
|
|
102
96
|
}
|
|
103
97
|
else {
|
|
104
|
-
const dataBuffer =
|
|
98
|
+
const dataBuffer = packetDecoder.buffer.subarray(packetDecoder.offset);
|
|
105
99
|
const decompressed = (0, node_zlib_1.inflateSync)(dataBuffer);
|
|
106
100
|
if (decompressed.length !== dataLength)
|
|
107
101
|
throw new error_1.UnexpectedValue("decompressed packet data", decompressed.length.toString(), dataLength.toString());
|
|
108
|
-
|
|
109
|
-
packetID =
|
|
102
|
+
packetDecoder = new decoder_1.BinaryDecoder(decompressed);
|
|
103
|
+
packetID = packetDecoder.readVarInt();
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
106
|
if (this.state.clientOptions.debug &&
|
|
113
107
|
this.state.clientOptions.debug.packetLogger &&
|
|
114
108
|
((Array.isArray(this.state.clientOptions.debug.ignoreTCPPacketLogs) && !this.state.clientOptions.debug.ignoreTCPPacketLogs.includes(packetID)) ||
|
|
115
109
|
(!this.state.clientOptions.debug.ignoreTCPPacketLogs)))
|
|
116
|
-
console.log("packet", packetID, "length",
|
|
117
|
-
this.forwardPacket(packetID,
|
|
110
|
+
console.log("packet", packetID, "length", packetDecoder.buffer.length);
|
|
111
|
+
this.forwardPacket(packetID, packetDecoder);
|
|
118
112
|
this.bufferPool = this.bufferPool.subarray(expectedPacketEnd);
|
|
119
113
|
}
|
|
120
114
|
}
|