@jsprismarine/client 0.14.2 → 0.15.0-unstable-20261024034805

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 (96) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/dist/Client.cjs.cjs +132 -0
  3. package/dist/Client.d.ts +70 -0
  4. package/dist/Client.d.ts.map +1 -0
  5. package/dist/Client.es.js +125 -0
  6. package/dist/bot/Bot.cjs.cjs +126 -0
  7. package/dist/bot/Bot.d.ts +66 -0
  8. package/dist/bot/Bot.d.ts.map +1 -0
  9. package/dist/bot/Bot.es.js +120 -0
  10. package/dist/bot/Fleet.cjs.cjs +136 -0
  11. package/dist/bot/Fleet.d.ts +68 -0
  12. package/dist/bot/Fleet.d.ts.map +1 -0
  13. package/dist/bot/Fleet.es.js +131 -0
  14. package/dist/bot/Metrics.cjs.cjs +72 -0
  15. package/dist/bot/Metrics.d.ts +59 -0
  16. package/dist/bot/Metrics.d.ts.map +1 -0
  17. package/dist/bot/Metrics.es.js +69 -0
  18. package/dist/bot/Random.cjs.cjs +62 -0
  19. package/dist/bot/Random.d.ts +35 -0
  20. package/dist/bot/Random.d.ts.map +1 -0
  21. package/dist/bot/Random.es.js +57 -0
  22. package/dist/bot/behaviour/Behaviour.cjs.cjs +2 -0
  23. package/dist/bot/behaviour/Behaviour.d.ts +30 -0
  24. package/dist/bot/behaviour/Behaviour.d.ts.map +1 -0
  25. package/dist/bot/behaviour/Behaviour.es.js +0 -0
  26. package/dist/bot/behaviour/Behaviours.cjs.cjs +32 -0
  27. package/dist/bot/behaviour/Behaviours.d.ts +13 -0
  28. package/dist/bot/behaviour/Behaviours.d.ts.map +1 -0
  29. package/dist/bot/behaviour/Behaviours.es.js +28 -0
  30. package/dist/bot/behaviour/BreakBehaviour.cjs.cjs +50 -0
  31. package/dist/bot/behaviour/BreakBehaviour.d.ts +18 -0
  32. package/dist/bot/behaviour/BreakBehaviour.d.ts.map +1 -0
  33. package/dist/bot/behaviour/BreakBehaviour.es.js +45 -0
  34. package/dist/bot/behaviour/ChatBehaviour.cjs.cjs +52 -0
  35. package/dist/bot/behaviour/ChatBehaviour.d.ts +17 -0
  36. package/dist/bot/behaviour/ChatBehaviour.d.ts.map +1 -0
  37. package/dist/bot/behaviour/ChatBehaviour.es.js +47 -0
  38. package/dist/bot/behaviour/LookBehaviour.cjs.cjs +42 -0
  39. package/dist/bot/behaviour/LookBehaviour.d.ts +14 -0
  40. package/dist/bot/behaviour/LookBehaviour.d.ts.map +1 -0
  41. package/dist/bot/behaviour/LookBehaviour.es.js +37 -0
  42. package/dist/bot/behaviour/WalkBehaviour.cjs.cjs +56 -0
  43. package/dist/bot/behaviour/WalkBehaviour.d.ts +20 -0
  44. package/dist/bot/behaviour/WalkBehaviour.d.ts.map +1 -0
  45. package/dist/bot/behaviour/WalkBehaviour.es.js +51 -0
  46. package/dist/cli/Cli.cjs.cjs +151 -0
  47. package/dist/cli/Cli.d.ts +38 -0
  48. package/dist/cli/Cli.d.ts.map +1 -0
  49. package/dist/cli/Cli.es.js +145 -0
  50. package/dist/cli/commands.cjs.cjs +121 -0
  51. package/dist/cli/commands.d.ts +13 -0
  52. package/dist/cli/commands.d.ts.map +1 -0
  53. package/dist/cli/commands.es.js +117 -0
  54. package/dist/cli.cjs.cjs +33 -0
  55. package/dist/cli.d.ts +2 -0
  56. package/dist/cli.d.ts.map +1 -0
  57. package/dist/cli.es.js +31 -0
  58. package/dist/index.cjs.cjs +41 -168
  59. package/dist/index.d.ts +26 -44
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.es.js +19 -165
  62. package/dist/login/Handshake.cjs.cjs +51 -0
  63. package/dist/login/Handshake.d.ts +20 -0
  64. package/dist/login/Handshake.d.ts.map +1 -0
  65. package/dist/login/Handshake.es.js +48 -0
  66. package/dist/login/LoginSequence.cjs.cjs +228 -0
  67. package/dist/login/LoginSequence.d.ts +100 -0
  68. package/dist/login/LoginSequence.d.ts.map +1 -0
  69. package/dist/login/LoginSequence.es.js +222 -0
  70. package/dist/net/ClientPacketRegistry.cjs.cjs +90 -0
  71. package/dist/net/ClientPacketRegistry.d.ts +55 -0
  72. package/dist/net/ClientPacketRegistry.d.ts.map +1 -0
  73. package/dist/net/ClientPacketRegistry.es.js +85 -0
  74. package/dist/net/ClientSession.cjs.cjs +129 -0
  75. package/dist/net/ClientSession.d.ts +75 -0
  76. package/dist/net/ClientSession.d.ts.map +1 -0
  77. package/dist/net/ClientSession.es.js +124 -0
  78. package/dist/net/ITransport.cjs.cjs +12 -0
  79. package/dist/net/ITransport.d.ts +38 -0
  80. package/dist/net/ITransport.d.ts.map +1 -0
  81. package/dist/net/ITransport.es.js +10 -0
  82. package/dist/net/RakNetTransport.cjs.cjs +79 -0
  83. package/dist/net/RakNetTransport.d.ts +37 -0
  84. package/dist/net/RakNetTransport.d.ts.map +1 -0
  85. package/dist/net/RakNetTransport.es.js +74 -0
  86. package/package.json +17 -10
  87. package/dist/_virtual/_rolldown/runtime.cjs.cjs +0 -26
  88. package/dist/_virtual/_rolldown/runtime.es.js +0 -4
  89. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/clear-interval-async.cjs.cjs +0 -28
  90. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/clear-interval-async.es.js +0 -23
  91. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/dynamic/set-interval-async.cjs.cjs +0 -39
  92. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/dynamic/set-interval-async.es.js +0 -34
  93. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/dynamic/set-interval-async2.cjs.cjs +0 -21
  94. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/dynamic/set-interval-async2.es.js +0 -9
  95. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/set-interval-async-timer.cjs.cjs +0 -53
  96. package/dist/node_modules/.pnpm/set-interval-async@3.0.3/node_modules/set-interval-async/dist/set-interval-async-timer.es.js +0 -49
package/CHANGELOG.md CHANGED
@@ -1,5 +1,107 @@
1
1
  # @jsprismarine/client
2
2
 
3
+ ## 0.15.0-unstable-20261024034805
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2577](https://github.com/JSPrismarine/JSPrismarine/pull/2577) [`5cd4d0a`](https://github.com/JSPrismarine/JSPrismarine/commit/5cd4d0aaf1b101135135157e9f11c55c4c73a5f9) Thanks [@filiphsps](https://github.com/filiphsps)! - A load-testing harness: N synthetic players against a server, and the numbers they produce.
8
+
9
+ `Fleet` connects a fleet at a configured rate, ticks each bot's behaviours at the server's own twenty per second, and reports what happened - login latency percentiles, RakNet round trip, bytes and packets per direction, how many of the requested bots actually got in, and what each refusal was. A bot that fails to connect is recorded and left out rather than aborting the run, because "how many of five hundred got in" is usually the question being asked.
10
+
11
+ Everything random comes from one seed, derived per bot rather than shared. `Math.random` cannot be seeded, and a run that cannot be repeated is not a measurement: two runs against the same server have to differ because the *server* behaved differently. A single generator handed to five hundred bots would have them take turns drawing from one sequence, so what each did would depend on how the others were scheduled - which is the non-determinism the seed exists to remove.
12
+
13
+ Four behaviours, deliberately separable, because a load test is a question and the question is usually about one kind of traffic: `walk` (chunk streaming and entity tracking), `look` (the broadcast path, without touching streaming), `chat` (fan-out - two hundred bots speaking once each is forty thousand deliveries), and `break` (the three-step action sequence a real client sends).
14
+
15
+ It lives in `packages/client/src/bot/` rather than in a package of its own: it is under a thousand lines, it depends only on the client, and nothing will ever depend on it.
16
+
17
+ **A command line, `jsp-client`**, in the same package and for the same reason - the command line is a way of driving the client, not a separate product.
18
+
19
+ ```
20
+ jsp-client bot --host <address> --count <n> [--behaviour walk,chat,break]
21
+ [--duration 10m] [--ramp 5/s] [--seed 1234] [--view-distance 4]
22
+ [--report report.json]
23
+ jsp-client connect --host <address> [--name Steve]
24
+ jsp-client ping --host <address>
25
+ ```
26
+
27
+ Built on `node:util.parseArgs` rather than a dependency: the repository has no argument library anywhere, Node 21 is already the engine requirement, and a binary that has to stay `bun build --compile`-able has every reason not to grow a dependency tree for five flags. A bare `--duration 60` means sixty *seconds*, because the alternative reading wastes an afternoon. It exits 2 for a command line it cannot read and 1 when any bot failed to get in, so it works as a CI gate and not only as something to read.
28
+
29
+ **Five more packets migrated to `NetworkPacket<T>`** - `MovePlayer`, `PlayerAction`, `RequestChunkRadius`, `ChunkRadiusUpdated` and `LevelChunk` - each pinned against the server's own class byte for byte. Two carry traps worth naming: `MovePlayer`'s length depends on one of its own bytes, since the teleport fields exist only for a teleport, and `PlayerAction` writes its block positions with an *unsigned* y, so writing all three signed encodes every height above 63 one byte differently and the reader takes the block face out of the middle of a coordinate. `LevelChunk` reads its envelope and hands the terrain over unparsed, which is what lets a bot skip the expensive half of the packet that makes up most of a server's output.
30
+
31
+ Two more bugs the real binary found that the tests could not:
32
+
33
+ - **Nothing kept the process alive.** Every handle the client owns is `unref`ed so a library never holds its host process open, which in a process whose only job *is* that client leaves nothing holding the event loop. Node exited between the first await and the answer: `ping` printed nothing, the fleet connected nobody, and both returned zero. Invisible under a test runner, which keeps the loop alive by itself.
34
+ - **The report's round-trip time was always `-`.** A report is produced after the run ends, and the RTT lived only on a session that had already been torn down, so the number no report ever saw was the one the harness existed to measure. The transport keeps the last live measurement now.
35
+
36
+ **`ClientSocket.kill` closed its socket one tick too early.** `disconnect` queues a DISCONNECTION_NOTIFICATION and `dgram.send` is asynchronous however immediate the priority was, so closing the handle in the same tick dropped the datagram and the goodbye was never sent. The server then held the session until it timed out - ten seconds counting against the player limit - and a fleet that reconnected found the server full of clients that had already left. Found by the harness itself, on the fifth fleet of a test run.
37
+
38
+ - [#2577](https://github.com/JSPrismarine/JSPrismarine/pull/2577) [`5cd4d0a`](https://github.com/JSPrismarine/JSPrismarine/commit/5cd4d0aaf1b101135135157e9f11c55c4c73a5f9) Thanks [@filiphsps](https://github.com/filiphsps)! - The client can log in. `@jsprismarine/client` connects to a Bedrock server, completes the handshake and stands in the world - proved by a test that boots a real `Server` in-process and joins it with nothing mocked in between.
39
+
40
+ **`@jsprismarine/auth`, new.** The login identity: the JWT chain, the client data blob, and the P-384 key both are signed with. A package of its own because the proxy shares it - it needs to *verify* an incoming chain when acting as a server in online mode, which a client never does. A provider is chosen at the edge of the application, so which one is in play is a deployment decision rather than a build-time one. `OfflineAuthProvider` signs the single self-signed chain link a real client sends when it is not signed in, and generates its key per instance, because the key *is* the identity: five hundred bots under one name still need five hundred of them.
41
+
42
+ The default skin is generated from flat colour blocks laid over the regions the classic humanoid geometry samples. Mojang's textures cannot be redistributed and a client that refused to log in without one would be useless. It is also not optional in the way it looks: the server builds a `Skin` out of the client data and dereferences eighteen fields without checking any of them, so a client that omits one crashes the login handler rather than being refused.
43
+
44
+ **Ten packets migrated to `NetworkPacket<T>`** - the ones a join cannot do without. `Login` is among them, and is encodable for the first time: `LoginPacket.encodePayload` had been a commented-out block with a hardcoded chain in it since it was written. `StartGame` is deliberately partial, reading the fields a client cannot function without and stopping; the rest is positional and would have to be modelled in full before any of it could be read. Stopping early is safe because a batch length-delimits each packet.
45
+
46
+ **`@jsprismarine/client`, rebuilt.** It was a 230-line proof of concept that could not finish a handshake - it hardcoded RakNet protocol 10 against this repository's own 11, drove a *server* session by passing itself as `this as any`, and sent a Login that encoded nothing. It is now a transport seam, a packet registry with no `Server` in the signature, a batching session and a login state machine, and it depends on `@jsprismarine/protocol` rather than on the server.
47
+
48
+ Three bugs found by pointing it at a real server:
49
+
50
+ - **Inbound batches were dispatched out of order.** Decoding is asynchronous because inflating runs on libuv's thread pool, so a batch takes as long as its *size* says, and a large one was overtaken by every small one that arrived while it was still inflating. A 37 KiB `StartGame` surfacing after the `PlayStatus` that was meant to follow it is not a slow `StartGame`, it is a missing one - the login failed with "the server spawned us without ever sending StartGame" while the packet was still inflating. Inbound is now a chain, the receiving mirror of the one `MinecraftSession` already kept on the way out.
51
+ - **`ResourcePackResponsePacket.encodePayload` could not be read by its own `decodePayload`**: a spare `writeUnsignedShortLE(0)` sat in front of the count. Latent while only the server handled this packet, which decodes and never writes one.
52
+ - **`World.getPlayerData` raised "Player has no XUID"** for every unauthenticated player - a case `LoginHandler` explicitly permits, `savePlayerData` has always written a file for, and the very next line already had a fallback for. It logged as an error on every offline join. Reader and writer now share one key.
53
+
54
+ - [#2577](https://github.com/JSPrismarine/JSPrismarine/pull/2577) [`aeaf717`](https://github.com/JSPrismarine/JSPrismarine/commit/aeaf7171f271b7c6b03df42a6152d1f63b82826b) Thanks [@filiphsps](https://github.com/filiphsps)! - Protocol 2193: Minecraft 1.26.50 and 1.26.51.
55
+
56
+ Everything that was captured for 1.26.40 was captured again from a Bedrock Dedicated Server 1.26.51.1 - the item table (2076 items), the block palette (1477 blocks, 22079 states: 98 new wool and concrete stairs and slabs, a `minecraft:corner` on every stair, four connection states on every fence, pane and bar) and the recipes (1967) - and three things a 2193 client will not get into the world without were captured for the first time: the jigsaw structure rules, sent as `JigsawStructureDataPacket` before `StartGame` because the client disconnects with `MissingStructureData` otherwise; the definitions of the ninety-eight vanilla blocks that 1.26.50 defines in data, which `StartGamePacket` now declares the way a real server does; and the biome definitions, whose packet stopped being two loose lists and became a map of biome data plus a shared string table - a client reaches the world-generation screen with an empty one and gives up, so the real payload is now replayed. `packages/client/tools/capture-server-data.mjs` records all of them in one login.
57
+
58
+ This was found the only way it could be: a retail 1.26.51 client reaching the world-generation screen and stalling. The same client also confirmed that, faced with a server that answers NetherNet's `GET /v1/join` signaling probe with a 404, it falls back to a direct RakNet connection - which is the transport this server speaks.
59
+
60
+ The `LevelChunkPacket` payload wrote its biome sections with the wrong palette header. Each biome sub chunk is a paletted store like the block ones, and its header is `(bitsPerBlock << 1) | networkFlag`; the server wrote `bitsPerBlock 0` but left the network flag clear (`0` instead of `1`), which tells the client the palette is the *persistent* on-disk kind whose entries are NBT compounds. The client then reads the biome value varint as the start of a tag, the whole column decodes to nonsense, and it drops the join at world generation - the last thing standing between a real client and spawning. The section is now `01` (single value, network flag set) plus the biome value per sub chunk, one sub chunk for every one of the client's twenty-four, then the border byte, checked by decoding the packet the server sends and confirming it is consumed to the last byte. This too was invisible to the server's own client, which never deserialized terrain.
61
+
62
+ **The packets the client actually sends were wrong at 2168, and are right now.** The 2168 work was checked with this repository's own client, which reads `StartGame` partially, moves with `MovePlayerPacket` and never touches an inventory - so nothing exercised the paths a real client takes, and several of those had drifted years earlier:
63
+
64
+ - `StartGamePacket` still wrote a movement mode in front of the movement settings. That field left the protocol at 1.21.90, when client authoritative movement was retired, and every field after it went out one byte late. The full layout is now modelled in `@jsprismarine/protocol` and checked by decoding the packet BDS 1.26.51 sends and writing it back byte for byte.
65
+ - A real client moves with `PlayerAuthInputPacket`, every tick, and has since 1.21.80; the server had no decoder for it, so a real player could not move, and neither could they break a block, because a survival break rides in that packet's block actions. Both are read now and go through the same code as `MovePlayer` and `PlayerAction` do.
66
+ - `InventoryTransactionPacket` was read in its 748 layout: no presence byte before the legacy slot list, window ids and flags inferred rather than read, and no `Hand`, which 2193 added. `ItemStackRequestPacket` likewise: an action's selector, the four fixed bytes of a stack net id, the client's own descriptor form for auto-craft ingredients. `ItemStackResponsePacket` wrote none of its three optionals. All three follow gophertunnel's 2193 encoding now, with tests that write the bytes by hand.
67
+ - Block positions in `PlayerActionPacket` were read with an unsigned y, the layout up to 1.26.0; a block below sea level came out in the billions.
68
+
69
+ `PlaySoundPacket` gained the loop count, the range bypass and the two optionals 1.26.50 added, and can be encoded at all. `BuildPlatform` lost its retired members, `UWP` among them: BDS validates a login against the list now and refuses the value the client used to report, so it reports `WIN32`.
70
+
71
+ **The datagen reads Mojang's new publications.** `enums.html` is gone; a release is a `metadata.zip` of JSON schemas attached to a GitHub release, and the schemas list an enum's members without their values. `import-schemas.js` pins two releases - the target for the members, the first later preview whose schemas carry `x-enum-binary-value` for the numbers - into `snapshot/enums.json`, which `generate-enums.js` prefers over the old HTML dump wherever the schemas describe an enum. `DisconnectReason` and `PlayerAuthInputData` are generated from them. The recipe generator reads the `.brarchive` files a 1.26.50 server packs its behaviour packs into, and the palette capture places every block in four settings so that none pops before the save.
72
+
73
+ One thing this release cannot fix: BDS 1.26.51 defaults to `transport=nethernet` and prints that RakNet is no longer a supported transport for players. This server speaks RakNet only. Whether a 1.26.51 client still connects to a RakNet server by address is not something this repository can test.
74
+
75
+ ### Patch Changes
76
+
77
+ - [#2579](https://github.com/JSPrismarine/JSPrismarine/pull/2579) [`ff8648e`](https://github.com/JSPrismarine/JSPrismarine/commit/ff8648e6f92e87f702a1fefc09d306db3307da8a) Thanks [@filiphsps](https://github.com/filiphsps)! - Build declaration files with TypeScript 7 through `tsc-ts`. JSON data exports are now typed structurally (`string`, `number`) instead of as literal values.
78
+
79
+ - [#2577](https://github.com/JSPrismarine/JSPrismarine/pull/2577) [`fae2f4f`](https://github.com/JSPrismarine/JSPrismarine/commit/fae2f4f9952bd5ede5c0bdceaca9bffb11195029) Thanks [@filiphsps](https://github.com/filiphsps)! - Make the server tick at a steady twenty ticks a second, and stop measuring time with a clock that can move underneath us.
80
+
81
+ The tick loop corrected the same lateness twice. `executionTime` was measured from the _end_ of the previous tick, so it already contained that tick's sleep, and `MINECRAFT_TICK_TIME_MS - executionTime` was therefore a complete drift correction on its own. The comparison of `elapsedTime` against `expectedElapsedTime` that followed applied a second one, against the accumulated total. Two corrections for one error is a loop gain of two, and the loop oscillated exactly as that predicts: it alternated a near-zero gap with a near-hundred-millisecond one, averaging a perfectly correct twenty ticks a second while never actually holding fifty milliseconds. Measured against real timers, the interval had a standard deviation of 47 ms around a 50 ms target. Everything that leaves a tick as a batch — entity movement, chunk sends — went out in pairs separated by silence, which is not what a client interpolating between updates expects to receive.
82
+
83
+ Each tick's deadline is now derived from one fixed origin, and the correction happens once. The same measurement gives a standard deviation of zero.
84
+
85
+ Lateness beyond two seconds is now written off with a `Can't keep up!` warning rather than repaid in full. A ten second stall used to be owed back as two hundred consecutive zero-delay ticks, running the world at maximum speed and starving the event loop precisely when it was already in trouble. Shorter hitches are still made up, so a brief stall does not leave the world permanently running late.
86
+
87
+ TPS is measured over a sliding one-second window instead of one that reset its own baseline whenever it crossed a second — the first reading after each reset covered a single tick and was noise reported as a rate. It is also no longer clamped to twenty: a loop making up lost time genuinely runs faster than that, and the clamp meant the one metric that should expose the fault reported perfect health throughout.
88
+
89
+ The `tick` event is awaited. A plugin's tick handler now runs inside the tick like every other piece of tick work, instead of having its continuation land in the middle of some later tick and its rejection escape as an unhandled rejection.
90
+
91
+ In RakNet, every deadline a session keeps — the retransmission timeout, the split reassembly timeout, the session timeout — and every round trip sample now comes from a monotonic clock. On `Date.now()` a forward step from an NTP correction or a suspend/resume expired all of them at once and folded a step-sized round trip into the RTT estimate; a backward step put them out of reach and stopped retransmission until real time caught up. Timestamps that travel on the wire still use `Date.now()`: they are values the peer echoes back, not durations we measure.
92
+
93
+ `Session.update()` now takes that reading itself when given no argument, because a caller mixing the two clocks does not get a slightly wrong answer, it gets epoch milliseconds compared against process-relative ones — every deadline expired at once and the session timed out on its first idle pass. An argument is still accepted, for updating several sessions against one instant and for driving time forward in a test.
94
+
95
+ The RakNet tick loop no longer stops when a session update throws. It scheduled its own next call as the last statement of the callback, so a single session raising an exception took acknowledgements, retransmissions and timeouts down permanently for every connection on the server. Each session is now isolated from the next and the loop reschedules from `finally`. It also subtracts the work it just did from the interval, so the polling rate no longer falls away as sessions are added — with three milliseconds of work per pass it had dropped from ~98 Hz to ~80 Hz.
96
+
97
+ World auto-save ran once. `currentTick / 20 === 120` is true for exactly one value of the counter, so a world was saved two minutes after startup and then never again for the life of the process; it is a remainder now. `World.save` also handed an async callback to `forEach`, which discards the returned promise, so player writes were still in flight — and their failures unobserved — after `save` had resolved. A shutdown save could report success before a single player had reached disk.
98
+ - Updated dependencies [[`74722e8`](https://github.com/JSPrismarine/JSPrismarine/commit/74722e8b07e5865ca42b04ff81503f2a0559bd0b), [`6b60a88`](https://github.com/JSPrismarine/JSPrismarine/commit/6b60a88e40ad9751ea177f4273779869486de7e0), [`5cd4d0a`](https://github.com/JSPrismarine/JSPrismarine/commit/5cd4d0aaf1b101135135157e9f11c55c4c73a5f9), [`b6c3d73`](https://github.com/JSPrismarine/JSPrismarine/commit/b6c3d73168fa0397205e20fcbf3cc19c4d0bac36), [`5cd4d0a`](https://github.com/JSPrismarine/JSPrismarine/commit/5cd4d0aaf1b101135135157e9f11c55c4c73a5f9), [`95c1def`](https://github.com/JSPrismarine/JSPrismarine/commit/95c1defed96f389f944c2b61a70d4fe356d271c7), [`aeaf717`](https://github.com/JSPrismarine/JSPrismarine/commit/aeaf7171f271b7c6b03df42a6152d1f63b82826b), [`ff8648e`](https://github.com/JSPrismarine/JSPrismarine/commit/ff8648e6f92e87f702a1fefc09d306db3307da8a), [`e25f62b`](https://github.com/JSPrismarine/JSPrismarine/commit/e25f62bdba9c0c42193f1f368c69c22cf07e91de), [`fae2f4f`](https://github.com/JSPrismarine/JSPrismarine/commit/fae2f4f9952bd5ede5c0bdceaca9bffb11195029)]:
99
+ - @jsprismarine/protocol@0.15.0-unstable-20261024034805
100
+ - @jsprismarine/raknet@0.15.0-unstable-20261024034805
101
+ - @jsprismarine/minecraft@0.15.0-unstable-20261024034805
102
+ - @jsprismarine/auth@0.15.0-unstable-20261024034805
103
+ - @jsprismarine/logger@0.15.0-unstable-20261024034805
104
+
3
105
  ## 0.14.2
4
106
 
5
107
  ### Patch Changes
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ const require_login_LoginSequence = require("./login/LoginSequence.cjs.cjs");
7
+ const require_net_ClientPacketRegistry = require("./net/ClientPacketRegistry.cjs.cjs");
8
+ const require_net_ClientSession = require("./net/ClientSession.cjs.cjs");
9
+ const require_net_RakNetTransport = require("./net/RakNetTransport.cjs.cjs");
10
+ let _jsprismarine_auth = require("@jsprismarine/auth");
11
+ let _jsprismarine_logger = require("@jsprismarine/logger");
12
+ let _jsprismarine_protocol = require("@jsprismarine/protocol");
13
+ let node_events = require("node:events");
14
+ // src/Client.ts
15
+ /**
16
+ * The protocol version this client speaks.
17
+ *
18
+ * One version, hardcoded, exactly as the server does it. A mismatch is refused by both ends
19
+ * with a message that says which side is behind, which is the least a client owes somebody
20
+ * who cannot connect.
21
+ */
22
+ var PROTOCOL_VERSION = 2193;
23
+ var MINECRAFT_VERSION = "1.26.51";
24
+ /**
25
+ * A Minecraft: Bedrock Edition client, with no interface attached to it.
26
+ *
27
+ * Everything the game needs and nothing it needs a screen for, which is what lets the same
28
+ * object serve the windowed client, the headless one and each of the several hundred
29
+ * connections a load test opens. It owns a transport, a session and a login; what it
30
+ * deliberately does not own is a renderer, an input device or a main loop.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const client = new Client({ host: '127.0.0.1', displayName: 'Steve' });
35
+ * await client.connect();
36
+ * client.on('text', (message) => console.log(message));
37
+ * ```
38
+ */
39
+ var Client = class extends node_events.EventEmitter {
40
+ options;
41
+ logger;
42
+ auth;
43
+ registry = new require_net_ClientPacketRegistry.default();
44
+ transport;
45
+ session;
46
+ login = null;
47
+ startGame = null;
48
+ connected = false;
49
+ constructor(options) {
50
+ super();
51
+ this.options = options;
52
+ this.logger = options.logger ?? new _jsprismarine_logger.Logger();
53
+ this.auth = options.auth ?? new _jsprismarine_auth.OfflineAuthProvider({ displayName: options.displayName ?? "Player" });
54
+ this.registry.registerAll([
55
+ _jsprismarine_protocol.NetworkSettingsPacket,
56
+ _jsprismarine_protocol.PlayStatusPacket,
57
+ _jsprismarine_protocol.ServerToClientHandshakePacket,
58
+ _jsprismarine_protocol.DisconnectPacket,
59
+ _jsprismarine_protocol.ItemRegistryPacket,
60
+ _jsprismarine_protocol.ResourcePacksInfoPacket,
61
+ _jsprismarine_protocol.ResourcePackStackPacket,
62
+ _jsprismarine_protocol.StartGamePacket,
63
+ _jsprismarine_protocol.TextPacket
64
+ ]);
65
+ this.transport = options.transport ?? new require_net_RakNetTransport.default(this.logger, {
66
+ host: options.host,
67
+ port: options.port ?? 19132,
68
+ timeoutMs: options.loginTimeoutMs
69
+ });
70
+ this.session = new require_net_ClientSession.default(this.transport, this.registry, this.logger);
71
+ this.transport.on("close", (reason) => {
72
+ this.connected = false;
73
+ this.login?.onTransportClosed(reason);
74
+ this.emit("disconnect", reason);
75
+ });
76
+ this.session.on("packet", (packet) => this.emit("packet", packet));
77
+ }
78
+ /**
79
+ * Connects, logs in, and resolves once the server has spawned us.
80
+ *
81
+ * One call rather than `connect` then `login`, because there is nothing useful a caller
82
+ * can do between the two: every packet before the spawn belongs to the handshake.
83
+ */
84
+ async connect() {
85
+ if (this.connected) throw new Error("Already connected");
86
+ await this.transport.connect();
87
+ this.connected = true;
88
+ this.login = new require_login_LoginSequence.default(this.session, this.auth, this.logger, {
89
+ protocolVersion: PROTOCOL_VERSION,
90
+ serverAddress: `${this.options.host}:${this.options.port ?? 19132}`,
91
+ timeoutMs: this.options.loginTimeoutMs
92
+ });
93
+ try {
94
+ const { startGame } = await this.login.run();
95
+ this.startGame = startGame;
96
+ this.emit("spawn", startGame);
97
+ return startGame;
98
+ } catch (error) {
99
+ this.transport.close("login failed");
100
+ throw error;
101
+ }
102
+ }
103
+ disconnect(reason = "client disconnect") {
104
+ if (!this.connected) return;
105
+ this.connected = false;
106
+ this.transport.close(reason);
107
+ }
108
+ isConnected() {
109
+ return this.connected;
110
+ }
111
+ /** Null until the login completes. */
112
+ getStartGame() {
113
+ return this.startGame;
114
+ }
115
+ getSession() {
116
+ return this.session;
117
+ }
118
+ getRegistry() {
119
+ return this.registry;
120
+ }
121
+ getStats() {
122
+ return this.transport.getStats();
123
+ }
124
+ async getIdentity() {
125
+ return this.auth.getIdentity();
126
+ }
127
+ };
128
+ exports.MINECRAFT_VERSION = MINECRAFT_VERSION;
129
+ exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
130
+ exports.default = Client;
131
+
132
+ //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@@
1
+ import { Logger } from '@jsprismarine/logger';
2
+ import { EventEmitter } from 'node:events';
3
+ import ClientPacketRegistry from './net/ClientPacketRegistry';
4
+ import ClientSession from './net/ClientSession';
5
+ import type { IAuthProvider } from '@jsprismarine/auth';
6
+ import type { StartGame } from '@jsprismarine/protocol';
7
+ import type { ITransport, TransportStats } from './net/ITransport';
8
+ /**
9
+ * The protocol version this client speaks.
10
+ *
11
+ * One version, hardcoded, exactly as the server does it. A mismatch is refused by both ends
12
+ * with a message that says which side is behind, which is the least a client owes somebody
13
+ * who cannot connect.
14
+ */
15
+ export declare const PROTOCOL_VERSION = 2193;
16
+ export declare const MINECRAFT_VERSION = "1.26.51";
17
+ export interface ClientOptions {
18
+ readonly host: string;
19
+ readonly port?: number;
20
+ /** Defaults to an offline identity under this name. */
21
+ readonly displayName?: string;
22
+ readonly auth?: IAuthProvider;
23
+ readonly logger?: Logger;
24
+ /** Supply one for single player; omit it and the client dials over UDP. */
25
+ readonly transport?: ITransport;
26
+ readonly loginTimeoutMs?: number;
27
+ }
28
+ /**
29
+ * A Minecraft: Bedrock Edition client, with no interface attached to it.
30
+ *
31
+ * Everything the game needs and nothing it needs a screen for, which is what lets the same
32
+ * object serve the windowed client, the headless one and each of the several hundred
33
+ * connections a load test opens. It owns a transport, a session and a login; what it
34
+ * deliberately does not own is a renderer, an input device or a main loop.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const client = new Client({ host: '127.0.0.1', displayName: 'Steve' });
39
+ * await client.connect();
40
+ * client.on('text', (message) => console.log(message));
41
+ * ```
42
+ */
43
+ export default class Client extends EventEmitter {
44
+ private readonly options;
45
+ private readonly logger;
46
+ private readonly auth;
47
+ private readonly registry;
48
+ private readonly transport;
49
+ private readonly session;
50
+ private login;
51
+ private startGame;
52
+ private connected;
53
+ constructor(options: ClientOptions);
54
+ /**
55
+ * Connects, logs in, and resolves once the server has spawned us.
56
+ *
57
+ * One call rather than `connect` then `login`, because there is nothing useful a caller
58
+ * can do between the two: every packet before the spawn belongs to the handshake.
59
+ */
60
+ connect(): Promise<StartGame>;
61
+ disconnect(reason?: string): void;
62
+ isConnected(): boolean;
63
+ /** Null until the login completes. */
64
+ getStartGame(): StartGame | null;
65
+ getSession(): ClientSession;
66
+ getRegistry(): ClientPacketRegistry;
67
+ getStats(): TransportStats;
68
+ getIdentity(): Promise<import("@jsprismarine/auth").Identity>;
69
+ }
70
+ //# sourceMappingURL=Client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAY9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAC9D,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAGhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,YAAY;IAWzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAV3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IAExC,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,SAAS,CAAS;IAE1B,YAAoC,OAAO,EAAE,aAAa,EAmCzD;IAED;;;;;OAKG;IACU,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,CAwBzC;IAEM,UAAU,CAAC,MAAM,SAAsB,GAAG,IAAI,CAKpD;IAEM,WAAW,IAAI,OAAO,CAE5B;IAED,sCAAsC;IAC/B,YAAY,IAAI,SAAS,GAAG,IAAI,CAEtC;IAEM,UAAU,IAAI,aAAa,CAEjC;IAEM,WAAW,IAAI,oBAAoB,CAEzC;IAEM,QAAQ,IAAI,cAAc,CAEhC;IAEY,WAAW,mDAEvB;CACJ"}
@@ -0,0 +1,125 @@
1
+ import LoginSequence from "./login/LoginSequence.es.js";
2
+ import ClientPacketRegistry from "./net/ClientPacketRegistry.es.js";
3
+ import ClientSession from "./net/ClientSession.es.js";
4
+ import RakNetTransport from "./net/RakNetTransport.es.js";
5
+ import { OfflineAuthProvider } from "@jsprismarine/auth";
6
+ import { Logger } from "@jsprismarine/logger";
7
+ import { DisconnectPacket, ItemRegistryPacket, NetworkSettingsPacket, PlayStatusPacket, ResourcePackStackPacket, ResourcePacksInfoPacket, ServerToClientHandshakePacket, StartGamePacket, TextPacket } from "@jsprismarine/protocol";
8
+ import { EventEmitter } from "node:events";
9
+ // src/Client.ts
10
+ /**
11
+ * The protocol version this client speaks.
12
+ *
13
+ * One version, hardcoded, exactly as the server does it. A mismatch is refused by both ends
14
+ * with a message that says which side is behind, which is the least a client owes somebody
15
+ * who cannot connect.
16
+ */
17
+ var PROTOCOL_VERSION = 2193;
18
+ var MINECRAFT_VERSION = "1.26.51";
19
+ /**
20
+ * A Minecraft: Bedrock Edition client, with no interface attached to it.
21
+ *
22
+ * Everything the game needs and nothing it needs a screen for, which is what lets the same
23
+ * object serve the windowed client, the headless one and each of the several hundred
24
+ * connections a load test opens. It owns a transport, a session and a login; what it
25
+ * deliberately does not own is a renderer, an input device or a main loop.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const client = new Client({ host: '127.0.0.1', displayName: 'Steve' });
30
+ * await client.connect();
31
+ * client.on('text', (message) => console.log(message));
32
+ * ```
33
+ */
34
+ var Client = class extends EventEmitter {
35
+ options;
36
+ logger;
37
+ auth;
38
+ registry = new ClientPacketRegistry();
39
+ transport;
40
+ session;
41
+ login = null;
42
+ startGame = null;
43
+ connected = false;
44
+ constructor(options) {
45
+ super();
46
+ this.options = options;
47
+ this.logger = options.logger ?? new Logger();
48
+ this.auth = options.auth ?? new OfflineAuthProvider({ displayName: options.displayName ?? "Player" });
49
+ this.registry.registerAll([
50
+ NetworkSettingsPacket,
51
+ PlayStatusPacket,
52
+ ServerToClientHandshakePacket,
53
+ DisconnectPacket,
54
+ ItemRegistryPacket,
55
+ ResourcePacksInfoPacket,
56
+ ResourcePackStackPacket,
57
+ StartGamePacket,
58
+ TextPacket
59
+ ]);
60
+ this.transport = options.transport ?? new RakNetTransport(this.logger, {
61
+ host: options.host,
62
+ port: options.port ?? 19132,
63
+ timeoutMs: options.loginTimeoutMs
64
+ });
65
+ this.session = new ClientSession(this.transport, this.registry, this.logger);
66
+ this.transport.on("close", (reason) => {
67
+ this.connected = false;
68
+ this.login?.onTransportClosed(reason);
69
+ this.emit("disconnect", reason);
70
+ });
71
+ this.session.on("packet", (packet) => this.emit("packet", packet));
72
+ }
73
+ /**
74
+ * Connects, logs in, and resolves once the server has spawned us.
75
+ *
76
+ * One call rather than `connect` then `login`, because there is nothing useful a caller
77
+ * can do between the two: every packet before the spawn belongs to the handshake.
78
+ */
79
+ async connect() {
80
+ if (this.connected) throw new Error("Already connected");
81
+ await this.transport.connect();
82
+ this.connected = true;
83
+ this.login = new LoginSequence(this.session, this.auth, this.logger, {
84
+ protocolVersion: PROTOCOL_VERSION,
85
+ serverAddress: `${this.options.host}:${this.options.port ?? 19132}`,
86
+ timeoutMs: this.options.loginTimeoutMs
87
+ });
88
+ try {
89
+ const { startGame } = await this.login.run();
90
+ this.startGame = startGame;
91
+ this.emit("spawn", startGame);
92
+ return startGame;
93
+ } catch (error) {
94
+ this.transport.close("login failed");
95
+ throw error;
96
+ }
97
+ }
98
+ disconnect(reason = "client disconnect") {
99
+ if (!this.connected) return;
100
+ this.connected = false;
101
+ this.transport.close(reason);
102
+ }
103
+ isConnected() {
104
+ return this.connected;
105
+ }
106
+ /** Null until the login completes. */
107
+ getStartGame() {
108
+ return this.startGame;
109
+ }
110
+ getSession() {
111
+ return this.session;
112
+ }
113
+ getRegistry() {
114
+ return this.registry;
115
+ }
116
+ getStats() {
117
+ return this.transport.getStats();
118
+ }
119
+ async getIdentity() {
120
+ return this.auth.getIdentity();
121
+ }
122
+ };
123
+ export { MINECRAFT_VERSION, PROTOCOL_VERSION, Client as default };
124
+
125
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2xpZW50LmVzLmpzIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbIi4uL3NyYy9DbGllbnQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgT2ZmbGluZUF1dGhQcm92aWRlciB9IGZyb20gJ0Bqc3ByaXNtYXJpbmUvYXV0aCc7XG5pbXBvcnQgeyBMb2dnZXIgfSBmcm9tICdAanNwcmlzbWFyaW5lL2xvZ2dlcic7XG5pbXBvcnQge1xuICAgIERpc2Nv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FdBQWtDO0VBQzlCLE9BQU8sS0FBSyxVQUFVLFNBQVM7Q0FDbkM7Q0FFQSxNQUFhLGNBQWM7RUFDdkIsT0FBTyxLQUFLLEtBQUssWUFBWTtDQUNqQztBQUNKIn0=
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ const require_Client = require("../Client.cjs.cjs");
7
+ let _jsprismarine_auth = require("@jsprismarine/auth");
8
+ let _jsprismarine_protocol = require("@jsprismarine/protocol");
9
+ // src/bot/Bot.ts
10
+ /** The server's own rate, and therefore the rate a client's input is meaningful at. */
11
+ var TICK_INTERVAL_MS = 50;
12
+ /**
13
+ * One synthetic player: a client, a position it believes in, and the behaviours driving it.
14
+ *
15
+ * The position is the bot's own rather than the client's because the client core has no game
16
+ * state layer yet - it knows where it started, from `StartGame`, and nothing after that. For
17
+ * load generation that is enough and honestly so: a bot walks through walls, and the numbers
18
+ * it produces are still real, because the server does the same work either way.
19
+ */
20
+ var Bot = class {
21
+ options;
22
+ position = {
23
+ x: 0,
24
+ y: 0,
25
+ z: 0
26
+ };
27
+ pitch = 0;
28
+ yaw = 0;
29
+ headYaw = 0;
30
+ runtimeEntityId = 0n;
31
+ identity = {
32
+ xuid: "",
33
+ identity: "",
34
+ displayName: ""
35
+ };
36
+ client;
37
+ ticker;
38
+ ticks = 0;
39
+ stopped = false;
40
+ /** Counted per action name, merged into the fleet report. */
41
+ actions = /* @__PURE__ */ new Map();
42
+ /** From the first packet sent to standing in the world, in milliseconds. */
43
+ loginLatencyMs = null;
44
+ failure = null;
45
+ constructor(options) {
46
+ this.options = options;
47
+ this.client = new require_Client.default({
48
+ host: options.host,
49
+ port: options.port,
50
+ logger: options.logger,
51
+ auth: new _jsprismarine_auth.OfflineAuthProvider({ displayName: options.displayName }),
52
+ loginTimeoutMs: options.loginTimeoutMs
53
+ });
54
+ }
55
+ getClient() {
56
+ return this.client;
57
+ }
58
+ isConnected() {
59
+ return this.client.isConnected();
60
+ }
61
+ /** Connects and logs in, recording how long it took. Throws with the reason if it fails. */
62
+ async connect() {
63
+ const startedAt = performance.now();
64
+ try {
65
+ const startGame = await this.client.connect();
66
+ this.loginLatencyMs = performance.now() - startedAt;
67
+ this.runtimeEntityId = startGame.runtimeEntityId;
68
+ this.position = { ...startGame.position };
69
+ this.identity = await this.client.getIdentity();
70
+ } catch (error) {
71
+ this.failure = error instanceof Error ? error.message : String(error);
72
+ throw error;
73
+ }
74
+ await this.send(new _jsprismarine_protocol.RequestChunkRadiusPacket({
75
+ radius: this.options.viewDistance,
76
+ maxRadius: this.options.viewDistance
77
+ }));
78
+ }
79
+ /** Starts ticking the behaviours. Idempotent. */
80
+ start() {
81
+ if (this.ticker !== void 0 || this.stopped) return;
82
+ this.ticker = setInterval(() => {
83
+ this.tick();
84
+ }, 50);
85
+ this.ticker.unref();
86
+ }
87
+ stop() {
88
+ this.stopped = true;
89
+ clearInterval(this.ticker);
90
+ this.ticker = void 0;
91
+ }
92
+ disconnect(reason = "bot finished") {
93
+ this.stop();
94
+ this.client.disconnect(reason);
95
+ }
96
+ /**
97
+ * Runs one tick of every behaviour.
98
+ *
99
+ * Behaviours run in sequence rather than concurrently: two of them sending a move in the
100
+ * same tick would have the server apply whichever framed first, and a bot that
101
+ * teleported between two positions every tick is not a player.
102
+ */
103
+ async tick() {
104
+ if (this.stopped || !this.client.isConnected()) return;
105
+ const context = {
106
+ bot: this,
107
+ random: this.options.random,
108
+ tick: this.ticks,
109
+ send: (packet) => this.send(packet),
110
+ record: (action) => this.actions.set(action, (this.actions.get(action) ?? 0) + 1)
111
+ };
112
+ for (const behaviour of this.options.behaviours) try {
113
+ await behaviour.tick(context);
114
+ } catch (error) {
115
+ this.options.logger.debug(`Behaviour ${behaviour.name} failed for ${this.options.displayName}: ${error instanceof Error ? error.message : String(error)}`);
116
+ }
117
+ this.ticks++;
118
+ }
119
+ async send(packet) {
120
+ await this.client.getSession().send(packet);
121
+ }
122
+ };
123
+ exports.TICK_INTERVAL_MS = TICK_INTERVAL_MS;
124
+ exports.default = Bot;
125
+
126
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQm90LmNqcy5janMiLCJuYW1lcyI6WyJDbGllbnQiLCJPZmZsaW5lQXV0aFByb3ZpZGVyIiwiUmVxdWVzdENodW5rUmFkaXVzUGFja2V0Il0sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2JvdC9Cb3QudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgT2ZmbGluZUF1dGhQcm92aWRlciB9IGZyb20gJ0Bqc3ByaXNtYXJpbmUvYXV0aCc7XG5pbXBvcnQgQ2xpZW50IGZyb20gJy4uL0NsaWVudCc7XG5pbXBvcnQgeyBSZXF1ZXN0Q2h1bmtSYWRpdXNQYWNrZXQgfSBmcm9tICdAanNwcmlzbWFyaW5lL3Byb3RvY29sJztcblxuaW1wb3J0IHR5cGUgeyBJZGVudGl0eSB9IGZyb20gJ0Bqc3ByaXNtYXJpbmUvYXV0aCc7XG5pbXBvcnQgdHlwZSB7IExvZ2dlciB9IGZyb20gJ0Bqc3ByaXNtYXJpbmUvbG9nZ2VyJztcbmltcG9ydCB0eXBlIHsgTmV0d29ya1BhY2tldCB9IGZyb20gJ0Bqc3ByaXNtYXJpbmUvcHJvdG9jb2wnO1xuaW1wb3J0IHR5cGUgUmFuZG9tIGZyb20gJy4vUmFuZG9tJztcbmltcG9ydCB0eXBlIHsgQmVoYXZpb3VyIH0gZnJvbSAnLi9iZWhhdmlvdXIvQmVoYXZpb3VyJztcblxuLyoqIFRoZSBzZXJ2ZXIncyBvd24gcmF0ZSwgYW5kIHRoZXJlZm9yZSB0aGUgcmF0ZSBhIGNsaWVudCdzIGlucHV0IGlzIG1lYW5pbmdmdWwgYXQuICovXG5leHBvcnQgY29uc3QgVElDS19JTlRFUlZBTF9NUyA9IDUwO1xu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25zdCBjb250ZXh0ID0ge1xuICAgICAgICAgICAgYm90OiB0aGlzLFxuICAgICAgICAgICAgcmFuZG9tOiB0aGlzLm9wdGlvbnMucmFuZG9tLFxuICAgICAgICAgICAgdGljazogdGhpcy50aWNrcyxcbiAgICAgICAgICAgIHNlbmQ6IChwYWNrZXQ6IE5ldHdvcmtQYWNrZXQ8YW55PikgPT4gdGhpcy5zZW5kKHBhY2tldCksXG4gICAgICAgICAgICByZWNvcmQ6IChhY3Rpb246IHN0cmluZykgPT4gdGhpcy5hY3Rpb25zLnNldChhY3Rpb24sICh0aGlzLmFjdGlvbnMuZ2V0KGFjdGlvbikgPz8gMCkgKyAxKVxuICAgICAgICB9O1xuXG4gICAgICAgIGZvciAoY29uc3QgYmVoYXZpb3VyIG9mIHRoaXMub3B0aW9ucy5iZWhhdmlvdXJzKSB7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIGF3YWl0IGJlaGF2aW91ci50aWNrKGNvbnRleHQpO1xuICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3I6IHVua25vd24pIHtcbiAgICAgICAgICAgICAgICAvLyBBIGJlaGF2aW91ciB0aGF0IHRocm93cyBtdXN0IG5vdCB0YWtlIHRoZSBjb25uZWN0aW9uIG91dCBvZiB0aGUgZmxlZXQ6XG4gICAgICAgICAgICAgICAgLy8gbG9zaW5nIGEgYm90IHNpbGVudGx5IGNoYW5nZXMgd2hhdCBpcyBiZWluZyBtZWFzdXJlZC5cbiAgICAgICAgICAgICAgICB0aGlzLm9wdGlvbnMubG9nZ2VyLmRlYnVnKFxuICAgICAgICAgICAgICAgICAgICBgQmVoYXZpb3VyICR7YmVoYXZpb3VyLm5hbWV9IGZhaWxlZCBmb3IgJHt0aGlzLm9wdGlvbnMuZGlzcGxheU5hbWV9OiAke1xuICAgICAgICAgICAgICAgICAgICAgICAgZXJyb3IgaW5zdGFuY2VvZiBFcnJvciA/IGVycm9yLm1lc3NhZ2UgOiBTdHJpbmcoZXJyb3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