@adhisang/minecraft-modding-mcp 1.0.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 (106) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +765 -0
  4. package/dist/access-widener-parser.d.ts +24 -0
  5. package/dist/access-widener-parser.js +77 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +4 -0
  8. package/dist/config.d.ts +27 -0
  9. package/dist/config.js +178 -0
  10. package/dist/decompiler/vineflower.d.ts +15 -0
  11. package/dist/decompiler/vineflower.js +185 -0
  12. package/dist/errors.d.ts +50 -0
  13. package/dist/errors.js +49 -0
  14. package/dist/hash.d.ts +1 -0
  15. package/dist/hash.js +12 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +1447 -0
  18. package/dist/java-process.d.ts +16 -0
  19. package/dist/java-process.js +120 -0
  20. package/dist/logger.d.ts +3 -0
  21. package/dist/logger.js +21 -0
  22. package/dist/mapping-pipeline-service.d.ts +18 -0
  23. package/dist/mapping-pipeline-service.js +60 -0
  24. package/dist/mapping-service.d.ts +161 -0
  25. package/dist/mapping-service.js +1706 -0
  26. package/dist/maven-resolver.d.ts +22 -0
  27. package/dist/maven-resolver.js +122 -0
  28. package/dist/minecraft-explorer-service.d.ts +43 -0
  29. package/dist/minecraft-explorer-service.js +562 -0
  30. package/dist/mixin-parser.d.ts +34 -0
  31. package/dist/mixin-parser.js +194 -0
  32. package/dist/mixin-validator.d.ts +59 -0
  33. package/dist/mixin-validator.js +274 -0
  34. package/dist/mod-analyzer.d.ts +23 -0
  35. package/dist/mod-analyzer.js +346 -0
  36. package/dist/mod-decompile-service.d.ts +39 -0
  37. package/dist/mod-decompile-service.js +136 -0
  38. package/dist/mod-remap-service.d.ts +17 -0
  39. package/dist/mod-remap-service.js +186 -0
  40. package/dist/mod-search-service.d.ts +28 -0
  41. package/dist/mod-search-service.js +174 -0
  42. package/dist/mojang-tiny-mapping-service.d.ts +13 -0
  43. package/dist/mojang-tiny-mapping-service.js +351 -0
  44. package/dist/nbt/java-nbt-codec.d.ts +3 -0
  45. package/dist/nbt/java-nbt-codec.js +385 -0
  46. package/dist/nbt/json-patch.d.ts +3 -0
  47. package/dist/nbt/json-patch.js +352 -0
  48. package/dist/nbt/pipeline.d.ts +39 -0
  49. package/dist/nbt/pipeline.js +173 -0
  50. package/dist/nbt/typed-json.d.ts +10 -0
  51. package/dist/nbt/typed-json.js +205 -0
  52. package/dist/nbt/types.d.ts +66 -0
  53. package/dist/nbt/types.js +2 -0
  54. package/dist/observability.d.ts +88 -0
  55. package/dist/observability.js +165 -0
  56. package/dist/path-converter.d.ts +12 -0
  57. package/dist/path-converter.js +161 -0
  58. package/dist/path-resolver.d.ts +19 -0
  59. package/dist/path-resolver.js +78 -0
  60. package/dist/registry-service.d.ts +29 -0
  61. package/dist/registry-service.js +214 -0
  62. package/dist/repo-downloader.d.ts +15 -0
  63. package/dist/repo-downloader.js +111 -0
  64. package/dist/resources.d.ts +3 -0
  65. package/dist/resources.js +154 -0
  66. package/dist/search-hit-accumulator.d.ts +38 -0
  67. package/dist/search-hit-accumulator.js +153 -0
  68. package/dist/source-jar-reader.d.ts +13 -0
  69. package/dist/source-jar-reader.js +216 -0
  70. package/dist/source-resolver.d.ts +14 -0
  71. package/dist/source-resolver.js +274 -0
  72. package/dist/source-service.d.ts +404 -0
  73. package/dist/source-service.js +2881 -0
  74. package/dist/storage/artifacts-repo.d.ts +45 -0
  75. package/dist/storage/artifacts-repo.js +209 -0
  76. package/dist/storage/db.d.ts +14 -0
  77. package/dist/storage/db.js +132 -0
  78. package/dist/storage/files-repo.d.ts +78 -0
  79. package/dist/storage/files-repo.js +437 -0
  80. package/dist/storage/index-meta-repo.d.ts +35 -0
  81. package/dist/storage/index-meta-repo.js +97 -0
  82. package/dist/storage/migrations.d.ts +11 -0
  83. package/dist/storage/migrations.js +71 -0
  84. package/dist/storage/schema.d.ts +1 -0
  85. package/dist/storage/schema.js +160 -0
  86. package/dist/storage/sqlite.d.ts +20 -0
  87. package/dist/storage/sqlite.js +111 -0
  88. package/dist/storage/symbols-repo.d.ts +63 -0
  89. package/dist/storage/symbols-repo.js +401 -0
  90. package/dist/symbols/symbol-extractor.d.ts +7 -0
  91. package/dist/symbols/symbol-extractor.js +64 -0
  92. package/dist/tiny-remapper-resolver.d.ts +1 -0
  93. package/dist/tiny-remapper-resolver.js +62 -0
  94. package/dist/tiny-remapper-service.d.ts +16 -0
  95. package/dist/tiny-remapper-service.js +73 -0
  96. package/dist/types.d.ts +120 -0
  97. package/dist/types.js +2 -0
  98. package/dist/version-diff-service.d.ts +41 -0
  99. package/dist/version-diff-service.js +222 -0
  100. package/dist/version-service.d.ts +70 -0
  101. package/dist/version-service.js +411 -0
  102. package/dist/vineflower-resolver.d.ts +1 -0
  103. package/dist/vineflower-resolver.js +62 -0
  104. package/dist/workspace-mapping-service.d.ts +18 -0
  105. package/dist/workspace-mapping-service.js +89 -0
  106. package/package.json +61 -0
@@ -0,0 +1,385 @@
1
+ import { createError, ERROR_CODES, isAppError } from "../errors.js";
2
+ import { assertValidTypedNbtDocument } from "./typed-json.js";
3
+ const TAG_ID_BY_NAME = {
4
+ end: 0,
5
+ byte: 1,
6
+ short: 2,
7
+ int: 3,
8
+ long: 4,
9
+ float: 5,
10
+ double: 6,
11
+ byteArray: 7,
12
+ string: 8,
13
+ list: 9,
14
+ compound: 10,
15
+ intArray: 11,
16
+ longArray: 12
17
+ };
18
+ const TAG_NAME_BY_ID = Object.fromEntries(Object.entries(TAG_ID_BY_NAME).map(([name, id]) => [id, name]));
19
+ function parseError(message, details) {
20
+ return createError({
21
+ code: ERROR_CODES.NBT_PARSE_FAILED,
22
+ message,
23
+ details
24
+ });
25
+ }
26
+ function encodeError(message, details) {
27
+ return createError({
28
+ code: ERROR_CODES.NBT_ENCODE_FAILED,
29
+ message,
30
+ details
31
+ });
32
+ }
33
+ function resolveTagName(tagId, pointer) {
34
+ const tagName = TAG_NAME_BY_ID[tagId];
35
+ if (!tagName) {
36
+ throw parseError("Unknown NBT tag id.", { tagId, jsonPointer: pointer });
37
+ }
38
+ return tagName;
39
+ }
40
+ class NbtReader {
41
+ buffer;
42
+ offset = 0;
43
+ constructor(buffer) {
44
+ this.buffer = buffer;
45
+ }
46
+ ensure(length) {
47
+ if (this.offset + length > this.buffer.length) {
48
+ throw parseError("Unexpected end of NBT payload.", {
49
+ offset: this.offset,
50
+ requiredBytes: length,
51
+ remainingBytes: this.buffer.length - this.offset
52
+ });
53
+ }
54
+ }
55
+ readUInt8() {
56
+ this.ensure(1);
57
+ const value = this.buffer.readUInt8(this.offset);
58
+ this.offset += 1;
59
+ return value;
60
+ }
61
+ readInt8() {
62
+ this.ensure(1);
63
+ const value = this.buffer.readInt8(this.offset);
64
+ this.offset += 1;
65
+ return value;
66
+ }
67
+ readUInt16() {
68
+ this.ensure(2);
69
+ const value = this.buffer.readUInt16BE(this.offset);
70
+ this.offset += 2;
71
+ return value;
72
+ }
73
+ readInt16() {
74
+ this.ensure(2);
75
+ const value = this.buffer.readInt16BE(this.offset);
76
+ this.offset += 2;
77
+ return value;
78
+ }
79
+ readInt32() {
80
+ this.ensure(4);
81
+ const value = this.buffer.readInt32BE(this.offset);
82
+ this.offset += 4;
83
+ return value;
84
+ }
85
+ readFloat32() {
86
+ this.ensure(4);
87
+ const value = this.buffer.readFloatBE(this.offset);
88
+ this.offset += 4;
89
+ return value;
90
+ }
91
+ readFloat64() {
92
+ this.ensure(8);
93
+ const value = this.buffer.readDoubleBE(this.offset);
94
+ this.offset += 8;
95
+ return value;
96
+ }
97
+ readInt64() {
98
+ this.ensure(8);
99
+ const value = this.buffer.readBigInt64BE(this.offset);
100
+ this.offset += 8;
101
+ return value;
102
+ }
103
+ readString() {
104
+ const byteLength = this.readUInt16();
105
+ this.ensure(byteLength);
106
+ const value = this.buffer.toString("utf8", this.offset, this.offset + byteLength);
107
+ this.offset += byteLength;
108
+ return value;
109
+ }
110
+ remainingBytes() {
111
+ return this.buffer.length - this.offset;
112
+ }
113
+ }
114
+ class NbtWriter {
115
+ chunks = [];
116
+ writeUInt8(value) {
117
+ const chunk = Buffer.allocUnsafe(1);
118
+ chunk.writeUInt8(value, 0);
119
+ this.chunks.push(chunk);
120
+ }
121
+ writeInt8(value) {
122
+ const chunk = Buffer.allocUnsafe(1);
123
+ chunk.writeInt8(value, 0);
124
+ this.chunks.push(chunk);
125
+ }
126
+ writeUInt16(value) {
127
+ const chunk = Buffer.allocUnsafe(2);
128
+ chunk.writeUInt16BE(value, 0);
129
+ this.chunks.push(chunk);
130
+ }
131
+ writeInt16(value) {
132
+ const chunk = Buffer.allocUnsafe(2);
133
+ chunk.writeInt16BE(value, 0);
134
+ this.chunks.push(chunk);
135
+ }
136
+ writeInt32(value) {
137
+ const chunk = Buffer.allocUnsafe(4);
138
+ chunk.writeInt32BE(value, 0);
139
+ this.chunks.push(chunk);
140
+ }
141
+ writeFloat32(value) {
142
+ const chunk = Buffer.allocUnsafe(4);
143
+ chunk.writeFloatBE(value, 0);
144
+ this.chunks.push(chunk);
145
+ }
146
+ writeFloat64(value) {
147
+ const chunk = Buffer.allocUnsafe(8);
148
+ chunk.writeDoubleBE(value, 0);
149
+ this.chunks.push(chunk);
150
+ }
151
+ writeInt64(value) {
152
+ const chunk = Buffer.allocUnsafe(8);
153
+ chunk.writeBigInt64BE(value, 0);
154
+ this.chunks.push(chunk);
155
+ }
156
+ writeString(value) {
157
+ const encoded = Buffer.from(value, "utf8");
158
+ if (encoded.length > 0xffff) {
159
+ throw encodeError("NBT string length exceeds uint16.", { byteLength: encoded.length });
160
+ }
161
+ this.writeUInt16(encoded.length);
162
+ this.chunks.push(encoded);
163
+ }
164
+ toBuffer() {
165
+ return Buffer.concat(this.chunks);
166
+ }
167
+ }
168
+ function readPayload(reader, tagId, pointer) {
169
+ const tagName = resolveTagName(tagId, pointer);
170
+ switch (tagName) {
171
+ case "byte":
172
+ return { type: "byte", value: reader.readInt8() };
173
+ case "short":
174
+ return { type: "short", value: reader.readInt16() };
175
+ case "int":
176
+ return { type: "int", value: reader.readInt32() };
177
+ case "long":
178
+ return { type: "long", value: reader.readInt64().toString() };
179
+ case "float":
180
+ return { type: "float", value: reader.readFloat32() };
181
+ case "double":
182
+ return { type: "double", value: reader.readFloat64() };
183
+ case "byteArray": {
184
+ const length = reader.readInt32();
185
+ if (length < 0) {
186
+ throw parseError("NBT byte array length cannot be negative.", {
187
+ length,
188
+ jsonPointer: pointer
189
+ });
190
+ }
191
+ const value = [];
192
+ for (let i = 0; i < length; i += 1) {
193
+ value.push(reader.readInt8());
194
+ }
195
+ return { type: "byteArray", value };
196
+ }
197
+ case "string":
198
+ return { type: "string", value: reader.readString() };
199
+ case "list": {
200
+ const elementTagId = reader.readUInt8();
201
+ const elementType = resolveTagName(elementTagId, `${pointer}/elementType`);
202
+ const length = reader.readInt32();
203
+ if (length < 0) {
204
+ throw parseError("NBT list length cannot be negative.", {
205
+ length,
206
+ jsonPointer: pointer
207
+ });
208
+ }
209
+ if (elementType === "end" && length > 0) {
210
+ throw parseError("NBT list with elementType end must be empty.", {
211
+ length,
212
+ jsonPointer: pointer
213
+ });
214
+ }
215
+ const value = [];
216
+ for (let i = 0; i < length; i += 1) {
217
+ value.push(readPayload(reader, elementTagId, `${pointer}/value/${i}`));
218
+ }
219
+ return {
220
+ type: "list",
221
+ elementType,
222
+ value
223
+ };
224
+ }
225
+ case "compound": {
226
+ const value = {};
227
+ while (true) {
228
+ const childType = reader.readUInt8();
229
+ if (childType === TAG_ID_BY_NAME.end) {
230
+ break;
231
+ }
232
+ const childName = reader.readString();
233
+ value[childName] = readPayload(reader, childType, `${pointer}/value/${childName}`);
234
+ }
235
+ return { type: "compound", value };
236
+ }
237
+ case "intArray": {
238
+ const length = reader.readInt32();
239
+ if (length < 0) {
240
+ throw parseError("NBT int array length cannot be negative.", {
241
+ length,
242
+ jsonPointer: pointer
243
+ });
244
+ }
245
+ const value = [];
246
+ for (let i = 0; i < length; i += 1) {
247
+ value.push(reader.readInt32());
248
+ }
249
+ return { type: "intArray", value };
250
+ }
251
+ case "longArray": {
252
+ const length = reader.readInt32();
253
+ if (length < 0) {
254
+ throw parseError("NBT long array length cannot be negative.", {
255
+ length,
256
+ jsonPointer: pointer
257
+ });
258
+ }
259
+ const value = [];
260
+ for (let i = 0; i < length; i += 1) {
261
+ value.push(reader.readInt64().toString());
262
+ }
263
+ return { type: "longArray", value };
264
+ }
265
+ case "end":
266
+ throw parseError("TAG_End is only valid as a compound terminator.", {
267
+ jsonPointer: pointer
268
+ });
269
+ default:
270
+ throw parseError("Unsupported NBT tag encountered.", {
271
+ jsonPointer: pointer,
272
+ tagName
273
+ });
274
+ }
275
+ }
276
+ function writePayload(writer, node, pointer) {
277
+ switch (node.type) {
278
+ case "byte":
279
+ writer.writeInt8(node.value);
280
+ return;
281
+ case "short":
282
+ writer.writeInt16(node.value);
283
+ return;
284
+ case "int":
285
+ writer.writeInt32(node.value);
286
+ return;
287
+ case "long":
288
+ writer.writeInt64(BigInt(node.value));
289
+ return;
290
+ case "float":
291
+ writer.writeFloat32(node.value);
292
+ return;
293
+ case "double":
294
+ writer.writeFloat64(node.value);
295
+ return;
296
+ case "byteArray":
297
+ writer.writeInt32(node.value.length);
298
+ for (const value of node.value) {
299
+ writer.writeInt8(value);
300
+ }
301
+ return;
302
+ case "string":
303
+ writer.writeString(node.value);
304
+ return;
305
+ case "list":
306
+ writer.writeUInt8(TAG_ID_BY_NAME[node.elementType]);
307
+ writer.writeInt32(node.value.length);
308
+ for (let i = 0; i < node.value.length; i += 1) {
309
+ writePayload(writer, node.value[i], `${pointer}/value/${i}`);
310
+ }
311
+ return;
312
+ case "compound":
313
+ for (const [name, child] of Object.entries(node.value)) {
314
+ writer.writeUInt8(TAG_ID_BY_NAME[child.type]);
315
+ writer.writeString(name);
316
+ writePayload(writer, child, `${pointer}/value/${name}`);
317
+ }
318
+ writer.writeUInt8(TAG_ID_BY_NAME.end);
319
+ return;
320
+ case "intArray":
321
+ writer.writeInt32(node.value.length);
322
+ for (const value of node.value) {
323
+ writer.writeInt32(value);
324
+ }
325
+ return;
326
+ case "longArray":
327
+ writer.writeInt32(node.value.length);
328
+ for (const value of node.value) {
329
+ writer.writeInt64(BigInt(value));
330
+ }
331
+ return;
332
+ default:
333
+ throw encodeError("Unsupported typed NBT node for encoding.", {
334
+ jsonPointer: pointer,
335
+ nodeType: node.type
336
+ });
337
+ }
338
+ }
339
+ export function decodeJavaNbt(buffer) {
340
+ try {
341
+ const reader = new NbtReader(buffer);
342
+ const rootTagId = reader.readUInt8();
343
+ if (rootTagId === TAG_ID_BY_NAME.end) {
344
+ throw parseError("Root NBT tag cannot be TAG_End.");
345
+ }
346
+ const rootName = reader.readString();
347
+ const root = readPayload(reader, rootTagId, "/root");
348
+ const document = { rootName, root };
349
+ if (reader.remainingBytes() > 0) {
350
+ throw parseError("Trailing bytes remain after decoding NBT payload.", {
351
+ trailingBytes: reader.remainingBytes()
352
+ });
353
+ }
354
+ assertValidTypedNbtDocument(document);
355
+ return document;
356
+ }
357
+ catch (error) {
358
+ if (isAppError(error)) {
359
+ if (error.code === ERROR_CODES.NBT_PARSE_FAILED ||
360
+ error.code === ERROR_CODES.NBT_INVALID_TYPED_JSON) {
361
+ throw error;
362
+ }
363
+ }
364
+ throw parseError("Failed to decode Java NBT payload.");
365
+ }
366
+ }
367
+ export function encodeJavaNbt(document) {
368
+ assertValidTypedNbtDocument(document);
369
+ try {
370
+ const writer = new NbtWriter();
371
+ writer.writeUInt8(TAG_ID_BY_NAME[document.root.type]);
372
+ writer.writeString(document.rootName);
373
+ writePayload(writer, document.root, "/root");
374
+ return writer.toBuffer();
375
+ }
376
+ catch (error) {
377
+ if (isAppError(error)) {
378
+ if (error.code === ERROR_CODES.NBT_INVALID_TYPED_JSON || error.code === ERROR_CODES.NBT_ENCODE_FAILED) {
379
+ throw error;
380
+ }
381
+ }
382
+ throw encodeError("Failed to encode Java NBT payload.");
383
+ }
384
+ }
385
+ //# sourceMappingURL=java-nbt-codec.js.map
@@ -0,0 +1,3 @@
1
+ import { type TypedNbtDocument } from "./typed-json.js";
2
+ import type { ApplyJsonPatchResult } from "./types.js";
3
+ export declare function applyJsonPatch(document: TypedNbtDocument, patch: unknown): ApplyJsonPatchResult;