@vaitosoi/minejs 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +1 -1
  2. package/assets/minecraft/26.2/packets.json +4758 -0
  3. package/dist/base/buffer.d.ts +2 -0
  4. package/dist/base/buffer.d.ts.map +1 -0
  5. package/dist/base/buffer.js +12 -0
  6. package/dist/base/buffer.js.map +1 -0
  7. package/dist/base/error.d.ts +59 -3
  8. package/dist/base/error.d.ts.map +1 -1
  9. package/dist/base/error.js +123 -7
  10. package/dist/base/error.js.map +1 -1
  11. package/dist/base/http.d.ts +2 -0
  12. package/dist/base/http.d.ts.map +1 -0
  13. package/dist/base/http.js +14 -0
  14. package/dist/base/http.js.map +1 -0
  15. package/dist/base/math.d.ts +22 -1
  16. package/dist/base/math.d.ts.map +1 -1
  17. package/dist/base/math.js +49 -2
  18. package/dist/base/math.js.map +1 -1
  19. package/dist/base/typing.d.ts +7 -1
  20. package/dist/base/typing.d.ts.map +1 -1
  21. package/dist/client/auth.d.ts +41 -7
  22. package/dist/client/auth.d.ts.map +1 -1
  23. package/dist/client/auth.js +96 -39
  24. package/dist/client/auth.js.map +1 -1
  25. package/dist/client/client.d.ts +73 -17
  26. package/dist/client/client.d.ts.map +1 -1
  27. package/dist/client/client.js +111 -44
  28. package/dist/client/client.js.map +1 -1
  29. package/dist/client/tcp.d.ts +17 -206
  30. package/dist/client/tcp.d.ts.map +1 -1
  31. package/dist/client/tcp.js +37 -715
  32. package/dist/client/tcp.js.map +1 -1
  33. package/dist/index.d.ts +12 -12
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +12 -12
  36. package/dist/index.js.map +1 -1
  37. package/dist/message/link.d.ts +10 -0
  38. package/dist/message/link.d.ts.map +1 -0
  39. package/dist/message/link.js +22 -0
  40. package/dist/message/link.js.map +1 -0
  41. package/dist/message/sigCache.d.ts +13 -0
  42. package/dist/message/sigCache.d.ts.map +1 -0
  43. package/dist/message/sigCache.js +26 -0
  44. package/dist/message/sigCache.js.map +1 -0
  45. package/dist/{translator → packet}/decoder.d.ts +14 -1
  46. package/dist/packet/decoder.d.ts.map +1 -0
  47. package/dist/{translator → packet}/decoder.js +24 -3
  48. package/dist/packet/decoder.js.map +1 -0
  49. package/dist/packet/dispatcher.d.ts +53 -0
  50. package/dist/packet/dispatcher.d.ts.map +1 -0
  51. package/dist/packet/dispatcher.js +738 -0
  52. package/dist/packet/dispatcher.js.map +1 -0
  53. package/dist/{translator → packet}/encoder.d.ts +4 -3
  54. package/dist/packet/encoder.d.ts.map +1 -0
  55. package/dist/{translator → packet}/encoder.js +18 -7
  56. package/dist/packet/encoder.js.map +1 -0
  57. package/dist/packet/static.d.ts.map +1 -0
  58. package/dist/packet/static.js.map +1 -0
  59. package/dist/{base → physics}/aabb.d.ts +2 -2
  60. package/dist/physics/aabb.d.ts.map +1 -0
  61. package/dist/{base → physics}/aabb.js +5 -5
  62. package/dist/physics/aabb.js.map +1 -0
  63. package/dist/physics/direction.d.ts.map +1 -0
  64. package/dist/physics/direction.js.map +1 -0
  65. package/dist/{base → physics}/player.d.ts +25 -28
  66. package/dist/physics/player.d.ts.map +1 -0
  67. package/dist/{base → physics}/player.js +81 -68
  68. package/dist/physics/player.js.map +1 -0
  69. package/dist/version/codec.d.ts +18 -0
  70. package/dist/version/codec.d.ts.map +1 -0
  71. package/dist/version/codec.js +235 -0
  72. package/dist/version/codec.js.map +1 -0
  73. package/dist/version/registry.d.ts +236 -0
  74. package/dist/version/registry.d.ts.map +1 -0
  75. package/dist/version/registry.js +284 -0
  76. package/dist/version/registry.js.map +1 -0
  77. package/dist/{base → world}/block.d.ts +5 -5
  78. package/dist/world/block.d.ts.map +1 -0
  79. package/dist/{base → world}/block.js +13 -13
  80. package/dist/world/block.js.map +1 -0
  81. package/dist/{base → world}/entity.d.ts +4 -4
  82. package/dist/world/entity.d.ts.map +1 -0
  83. package/dist/{base → world}/entity.js +6 -6
  84. package/dist/world/entity.js.map +1 -0
  85. package/dist/world/state.d.ts +175 -0
  86. package/dist/world/state.d.ts.map +1 -0
  87. package/dist/world/state.js +163 -0
  88. package/dist/world/state.js.map +1 -0
  89. package/dist/world/tick.d.ts.map +1 -0
  90. package/dist/world/tick.js.map +1 -0
  91. package/package.json +7 -2
  92. package/src/base/buffer.ts +12 -0
  93. package/src/base/error.ts +93 -4
  94. package/src/base/http.ts +10 -0
  95. package/src/base/math.ts +55 -3
  96. package/src/base/typing.ts +9 -1
  97. package/src/client/auth.ts +130 -52
  98. package/src/client/client.ts +182 -50
  99. package/src/client/tcp.ts +45 -967
  100. package/src/index.ts +12 -12
  101. package/src/message/link.ts +17 -0
  102. package/src/message/sigCache.ts +25 -0
  103. package/src/{translator → packet}/decoder.ts +24 -3
  104. package/src/packet/dispatcher.ts +919 -0
  105. package/src/{translator → packet}/encoder.ts +20 -9
  106. package/src/{base → physics}/aabb.ts +5 -5
  107. package/src/{base → physics}/player.ts +106 -65
  108. package/src/version/codec.ts +248 -0
  109. package/src/version/registry.ts +328 -0
  110. package/src/{base → world}/block.ts +12 -11
  111. package/src/{base → world}/entity.ts +5 -5
  112. package/src/world/state.ts +300 -0
  113. package/test/adapter/index.ts +14 -0
  114. package/test/client/index.ts +28 -21
  115. package/test/json/index.ts +3 -0
  116. package/dist/base/aabb.d.ts.map +0 -1
  117. package/dist/base/aabb.js.map +0 -1
  118. package/dist/base/block.d.ts.map +0 -1
  119. package/dist/base/block.js.map +0 -1
  120. package/dist/base/direction.d.ts.map +0 -1
  121. package/dist/base/direction.js.map +0 -1
  122. package/dist/base/entity.d.ts.map +0 -1
  123. package/dist/base/entity.js.map +0 -1
  124. package/dist/base/player.d.ts.map +0 -1
  125. package/dist/base/player.js.map +0 -1
  126. package/dist/base/registry.d.ts +0 -50
  127. package/dist/base/registry.d.ts.map +0 -1
  128. package/dist/base/registry.js +0 -89
  129. package/dist/base/registry.js.map +0 -1
  130. package/dist/base/tick.d.ts.map +0 -1
  131. package/dist/base/tick.js.map +0 -1
  132. package/dist/translator/decoder.d.ts.map +0 -1
  133. package/dist/translator/decoder.js.map +0 -1
  134. package/dist/translator/encoder.d.ts.map +0 -1
  135. package/dist/translator/encoder.js.map +0 -1
  136. package/dist/translator/static.d.ts.map +0 -1
  137. package/dist/translator/static.js.map +0 -1
  138. package/src/base/registry.ts +0 -87
  139. /package/assets/minecraft/{blocks.json → 26.2/blocks.json} +0 -0
  140. /package/assets/minecraft/{entities.json → 26.2/entities.json} +0 -0
  141. /package/dist/{translator → packet}/static.d.ts +0 -0
  142. /package/dist/{translator → packet}/static.js +0 -0
  143. /package/dist/{base → physics}/direction.d.ts +0 -0
  144. /package/dist/{base → physics}/direction.js +0 -0
  145. /package/dist/{base → world}/tick.d.ts +0 -0
  146. /package/dist/{base → world}/tick.js +0 -0
  147. /package/src/{translator → packet}/static.ts +0 -0
  148. /package/src/{base → physics}/direction.ts +0 -0
  149. /package/src/{base → world}/tick.ts +0 -0
package/src/index.ts CHANGED
@@ -1,20 +1,20 @@
1
- export * from "./base/aabb";
2
1
  export * from "./base/bitset";
3
- export * from "./base/block";
4
- export * from "./base/block";
5
- export * from "./base/direction";
6
- export * from "./base/entity";
7
2
  export * from "./base/error";
8
3
  export * from "./base/event";
9
4
  export * from "./base/math";
10
- export * from "./base/player";
11
- export * from "./base/registry";
12
- export * from "./base/tick";
13
5
  export * from "./base/typing";
14
6
  export * from "./client/auth";
15
7
  export * from "./client/client";
16
- export * from "./client/static";
17
8
  export * from "./client/tcp";
18
- export * from "./translator/decoder";
19
- export * from "./translator/encoder";
20
- export * from "./translator/static";
9
+ export * from "./packet/decoder";
10
+ export * from "./packet/encoder";
11
+ export * from "./packet/dispatcher";
12
+ export * from "./physics/aabb";
13
+ export * from "./physics/direction";
14
+ export * from "./physics/player";
15
+ export * from "./version/codec";
16
+ export * from "./version/registry";
17
+ export * from "./world/block";
18
+ export * from "./world/entity";
19
+ export * from "./world/state";
20
+ export * from "./world/tick";
@@ -0,0 +1,17 @@
1
+ export class MessageLink {
2
+ constructor (
3
+ public index: number,
4
+ public sender: string,
5
+ public session: string
6
+ ) { }
7
+
8
+ public static root(sender: string, session: string) {
9
+ return new MessageLink(0, sender, session);
10
+ }
11
+
12
+ public static unsinged(sender: string) { return this.root(sender, "null"); }
13
+
14
+ public isDescendantOf(link: MessageLink) {
15
+ return link.index > this.index && this.sender === link.sender && this.session === link.session;
16
+ }
17
+ }
@@ -0,0 +1,25 @@
1
+ export class SignatureCache {
2
+ private entries: Buffer[];
3
+
4
+ constructor(public capacity: number) {
5
+ this.entries = Array.from({ length: this.capacity });
6
+ }
7
+
8
+ public static default() { return new SignatureCache(128); }
9
+
10
+ public get(index: number) { return this.entries[index]; }
11
+
12
+ public unpack = (messages: { message_id: number, signature?: number[] | undefined }[]) =>
13
+ messages.map(({ message_id: id, signature }) => signature ? Buffer.from(signature) : this.get(id)!);
14
+
15
+ public push(input: Buffer[]) {
16
+ const queue = input.slice();
17
+ const set = new Set(queue.map(v => v.toString("hex")));
18
+ for (let i = 0; i < this.entries.length && queue.length > 0; i++) {
19
+ const entry = !!this.entries[i] && Buffer.from(this.entries[i]!);
20
+ this.entries[i] = queue.pop()!;
21
+ if (entry && !set.has(entry.toString("hex")))
22
+ queue.unshift(entry);
23
+ }
24
+ }
25
+ }
@@ -1,9 +1,10 @@
1
- import { Vec3 } from "../base/direction";
1
+ import { Vec3 } from "../physics/direction";
2
2
  import { CONTINUATION_FLAG, CONTINUE_BIT, MAX_QUANTIZED_VALUE, SCALE_BITS, SEGMENT_BITS } from "./static";
3
3
  import { StringSizeExceedLimit, UnexpectedValue } from "../base/error";
4
4
  import { Tag } from "./static";
5
5
  import { unzipSync } from "zlib";
6
6
  import { minBigInt } from "../base/math";
7
+ import { inspect } from "util";
7
8
 
8
9
  export function getTextFromTextComponent(component: any): string {
9
10
  if (component === null || component === undefined) return "null";
@@ -23,7 +24,7 @@ export function getTextFromTextComponent(component: any): string {
23
24
  } else if ("keybind" in component)
24
25
  return component["keybind"];
25
26
  else
26
- throw new UnexpectedValue("type of component", "string or object", typeof component);
27
+ throw new UnexpectedValue("value of component", "text component object", inspect(component, undefined, null));
27
28
  }
28
29
  default:
29
30
  throw new UnexpectedValue("type of component", "string or object", typeof component);
@@ -396,6 +397,27 @@ export class BinaryDecoder {
396
397
  return readX(this);
397
398
  }
398
399
 
400
+ /**
401
+ * Represents a set of IDs in a certain registry (implied by context), either directly (enumerated IDs) or indirectly (tag name).
402
+ * | Field Name | Field Type | Meaning |
403
+ * |------------|------------|---------|
404
+ * | Type | VarInt | Value used to determine the data that follows. It can be either: 0 - Represents a named set of IDs defined by a tag. Anything else - Represents an ad-hoc set of IDs enumerated inline. |
405
+ * | Tag Name | Optional Identifier | The registry tag defining the ID set. Only present if Type is 0. |
406
+ * | IDs | Optional Array of VarInt | An array of registry IDs. Only present if Type is not 0. The size of the array is equal to Type - 1. |
407
+ */
408
+ public readIdSet() {
409
+ const type = this.readVarInt();
410
+ let tagName: string | null = null,
411
+ ids: number[] | null = null;
412
+ if (type === 0) tagName = this.readString();
413
+ else ids = this.readArray(type - 1, decoder => decoder.readVarInt());
414
+ return {
415
+ type,
416
+ tagName,
417
+ ids
418
+ };
419
+ }
420
+
399
421
  /**
400
422
  * Read Chat Type Decoration
401
423
  *
@@ -609,7 +631,6 @@ export class SNBTDecoder {
609
631
  outer:
610
632
  while (true) {
611
633
  ch = this.source[this.offset]!;
612
- console.dir({ ch, type });
613
634
 
614
635
  switch (ch) {
615
636
  case "[":