@spyglassmc/java-edition 0.1.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 (94) hide show
  1. package/README.md +36 -0
  2. package/lib/binder/index.d.ts +15 -0
  3. package/lib/binder/index.js +102 -0
  4. package/lib/common/index.d.ts +7 -0
  5. package/lib/common/index.js +60 -0
  6. package/lib/dependency/common.d.ts +26 -0
  7. package/lib/dependency/common.js +39 -0
  8. package/lib/dependency/index.d.ts +30 -0
  9. package/lib/dependency/index.js +172 -0
  10. package/lib/dependency/mcmeta.d.ts +79 -0
  11. package/lib/dependency/mcmeta.js +205 -0
  12. package/lib/index.d.ts +6 -0
  13. package/lib/index.js +76 -0
  14. package/lib/json/checker/data/advancement.d.ts +14 -0
  15. package/lib/json/checker/data/advancement.js +450 -0
  16. package/lib/json/checker/data/biome.d.ts +4 -0
  17. package/lib/json/checker/data/biome.js +151 -0
  18. package/lib/json/checker/data/common.d.ts +22 -0
  19. package/lib/json/checker/data/common.js +286 -0
  20. package/lib/json/checker/data/dimension.d.ts +4 -0
  21. package/lib/json/checker/data/dimension.js +238 -0
  22. package/lib/json/checker/data/feature.d.ts +9 -0
  23. package/lib/json/checker/data/feature.js +733 -0
  24. package/lib/json/checker/data/index.d.ts +4 -0
  25. package/lib/json/checker/data/index.js +43 -0
  26. package/lib/json/checker/data/loot_table.d.ts +8 -0
  27. package/lib/json/checker/data/loot_table.js +279 -0
  28. package/lib/json/checker/data/recipe.d.ts +2 -0
  29. package/lib/json/checker/data/recipe.js +53 -0
  30. package/lib/json/checker/data/structure.d.ts +8 -0
  31. package/lib/json/checker/data/structure.js +148 -0
  32. package/lib/json/checker/data/tag.d.ts +7 -0
  33. package/lib/json/checker/data/tag.js +38 -0
  34. package/lib/json/checker/data/text_component.d.ts +2 -0
  35. package/lib/json/checker/data/text_component.js +142 -0
  36. package/lib/json/checker/index.d.ts +5 -0
  37. package/lib/json/checker/index.js +28 -0
  38. package/lib/json/checker/util/advancement.d.ts +3 -0
  39. package/lib/json/checker/util/advancement.js +20 -0
  40. package/lib/json/checker/util/block_states.d.ts +13 -0
  41. package/lib/json/checker/util/block_states.js +85 -0
  42. package/lib/json/checker/util/color.d.ts +4 -0
  43. package/lib/json/checker/util/color.js +64 -0
  44. package/lib/json/checker/util/index.d.ts +8 -0
  45. package/lib/json/checker/util/index.js +20 -0
  46. package/lib/json/checker/util/nbt.d.ts +17 -0
  47. package/lib/json/checker/util/nbt.js +71 -0
  48. package/lib/json/checker/util/recipe.d.ts +6 -0
  49. package/lib/json/checker/util/recipe.js +16 -0
  50. package/lib/json/checker/util/uuid.d.ts +2 -0
  51. package/lib/json/checker/util/uuid.js +12 -0
  52. package/lib/json/checker/util/version.d.ts +46 -0
  53. package/lib/json/checker/util/version.js +54 -0
  54. package/lib/json/index.d.ts +4 -0
  55. package/lib/json/index.js +32 -0
  56. package/lib/mcfunction/checker/index.d.ts +7 -0
  57. package/lib/mcfunction/checker/index.js +217 -0
  58. package/lib/mcfunction/colorizer/index.d.ts +6 -0
  59. package/lib/mcfunction/colorizer/index.js +38 -0
  60. package/lib/mcfunction/common/index.d.ts +7 -0
  61. package/lib/mcfunction/common/index.js +47 -0
  62. package/lib/mcfunction/completer/argument.d.ts +5 -0
  63. package/lib/mcfunction/completer/argument.js +292 -0
  64. package/lib/mcfunction/completer/index.d.ts +2 -0
  65. package/lib/mcfunction/completer/index.js +14 -0
  66. package/lib/mcfunction/index.d.ts +8 -0
  67. package/lib/mcfunction/index.js +72 -0
  68. package/lib/mcfunction/inlayHintProvider.d.ts +4 -0
  69. package/lib/mcfunction/inlayHintProvider.js +40 -0
  70. package/lib/mcfunction/node/argument.d.ts +187 -0
  71. package/lib/mcfunction/node/argument.js +281 -0
  72. package/lib/mcfunction/node/index.d.ts +2 -0
  73. package/lib/mcfunction/node/index.js +14 -0
  74. package/lib/mcfunction/parser/argument.d.ts +15 -0
  75. package/lib/mcfunction/parser/argument.js +934 -0
  76. package/lib/mcfunction/parser/index.d.ts +2 -0
  77. package/lib/mcfunction/parser/index.js +14 -0
  78. package/lib/mcfunction/signatureHelpProvider.d.ts +8 -0
  79. package/lib/mcfunction/signatureHelpProvider.js +103 -0
  80. package/lib/mcfunction/tree/1.15.d.ts +9 -0
  81. package/lib/mcfunction/tree/1.15.js +542 -0
  82. package/lib/mcfunction/tree/1.16.d.ts +10 -0
  83. package/lib/mcfunction/tree/1.16.js +77 -0
  84. package/lib/mcfunction/tree/1.17.d.ts +12 -0
  85. package/lib/mcfunction/tree/1.17.js +166 -0
  86. package/lib/mcfunction/tree/1.18.d.ts +26 -0
  87. package/lib/mcfunction/tree/1.18.js +6 -0
  88. package/lib/mcfunction/tree/1.19.d.ts +26 -0
  89. package/lib/mcfunction/tree/1.19.js +6 -0
  90. package/lib/mcfunction/tree/argument.d.ts +179 -0
  91. package/lib/mcfunction/tree/argument.js +3 -0
  92. package/lib/mcfunction/tree/index.d.ts +7 -0
  93. package/lib/mcfunction/tree/index.js +19 -0
  94. package/package.json +41 -0
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Fluids = exports.symbolRegistrar = exports.getMcmetaSummaryUris = exports.resolveConfiguredVersion = exports.getMajorVersion = void 0;
23
+ const core = __importStar(require("@spyglassmc/core"));
24
+ const common_1 = require("./common");
25
+ function getMajorVersion(version) {
26
+ const dotIndex = version.release_target.indexOf('.', 2);
27
+ return (dotIndex > 2 ? version.release_target.slice(0, dotIndex) : version.release_target);
28
+ }
29
+ exports.getMajorVersion = getMajorVersion;
30
+ /**
31
+ * @param inputVersion {@link Config.env.gameVersion}
32
+ */
33
+ function resolveConfiguredVersion(inputVersion, { packMcmeta, versions }) {
34
+ function toVersionInfo(index) {
35
+ if (index < 0) {
36
+ index = 0;
37
+ }
38
+ const version = versions[index];
39
+ return {
40
+ id: version.id,
41
+ name: version.name,
42
+ major: getMajorVersion(version),
43
+ isLatest: index === 0,
44
+ };
45
+ }
46
+ if (versions.length === 0) {
47
+ throw new Error('mcmeta version list is empty');
48
+ }
49
+ inputVersion = inputVersion.toLowerCase();
50
+ versions = versions.sort((a, b) => b.data_version - a.data_version);
51
+ if (inputVersion === 'auto') {
52
+ if (packMcmeta) {
53
+ const major = common_1.PackVersionMap[packMcmeta.pack.pack_format];
54
+ if (major) {
55
+ return toVersionInfo(versions.findIndex(v => getMajorVersion(v) === major));
56
+ }
57
+ }
58
+ return toVersionInfo(0);
59
+ }
60
+ else if (inputVersion === 'latest release') {
61
+ return toVersionInfo(versions.findIndex(v => v.type === 'release'));
62
+ }
63
+ else if (inputVersion === 'latest snapshot') {
64
+ return toVersionInfo(versions.findIndex(v => v.type === 'snapshot'));
65
+ }
66
+ return toVersionInfo(versions.findIndex(v => inputVersion === v.id.toLowerCase() || inputVersion === v.name.toLowerCase()));
67
+ }
68
+ exports.resolveConfiguredVersion = resolveConfiguredVersion;
69
+ function getMcmetaSummaryUris(version, isLatest, source) {
70
+ const tag = isLatest ? 'summary' : `${version}-summary`;
71
+ function getUri(path) {
72
+ return source.toLowerCase() === 'jsdelivr'
73
+ ? `https://cdn.jsdelivr.net/gh/misode/mcmeta@${tag}/${path}`
74
+ : `https://raw.githubusercontent.com/misode/mcmeta/${tag}/${path}`;
75
+ }
76
+ return {
77
+ blocks: getUri('blocks/data.json.gz'),
78
+ commands: getUri('commands/data.json.gz'),
79
+ registries: getUri('registries/data.json.gz'),
80
+ };
81
+ }
82
+ exports.getMcmetaSummaryUris = getMcmetaSummaryUris;
83
+ function symbolRegistrar(summary) {
84
+ const McmetaSummaryUri = 'mcmeta://summary/registries.json';
85
+ const SoundsBaseUri = 'https://misode.github.io/sounds/';
86
+ const WikiBaseUri = 'https://minecraft.fandom.com/wiki/';
87
+ const getWikiPageName = (id) => id === 'empty' ? 'Air' : id.split('_').map(v => `${v.charAt(0).toUpperCase()}${v.slice(1)}`).join('_');
88
+ /**
89
+ * Add states of blocks or fluids to the symbol table.
90
+ */
91
+ function addStatesSymbols(category, states, symbols) {
92
+ const capitalizedCategory = `${category[0].toUpperCase()}${category.slice(1)}`;
93
+ for (const [id, [properties, defaults]] of Object.entries(states)) {
94
+ const uri = `${WikiBaseUri}${getWikiPageName(id)}`;
95
+ symbols
96
+ .query(uri, category, core.ResourceLocation.lengthen(id))
97
+ .onEach(Object.entries(properties), ([state, values], blockQuery) => {
98
+ const defaultValue = defaults[state];
99
+ blockQuery.member(`${uri}#${capitalizedCategory}_states`, state, stateQuery => {
100
+ stateQuery
101
+ .enter({
102
+ data: { subcategory: 'state' },
103
+ usage: { type: 'declaration' },
104
+ })
105
+ .onEach(values, value => {
106
+ stateQuery.member(value, valueQuery => {
107
+ valueQuery.enter({
108
+ data: { subcategory: 'state_value' },
109
+ usage: { type: 'declaration' },
110
+ });
111
+ if (value === defaultValue) {
112
+ stateQuery.amend({
113
+ data: {
114
+ relations: {
115
+ default: { category, path: valueQuery.path },
116
+ },
117
+ },
118
+ });
119
+ }
120
+ });
121
+ });
122
+ });
123
+ });
124
+ }
125
+ }
126
+ function addRegistriesSymbols(registries, symbols) {
127
+ function isCategory(str) {
128
+ return (core.FileCategories.includes(str) || core.RegistryCategories.includes(str));
129
+ }
130
+ const getUri = (registryId, entryId) => {
131
+ /* istanbul ignore next */
132
+ switch (registryId) {
133
+ case 'attribute':
134
+ return `${WikiBaseUri}Attribute#Attributes`;
135
+ case 'block':
136
+ case 'enchantment':
137
+ case 'entity_type':
138
+ case 'fluid':
139
+ case 'item':
140
+ case 'mob_effect':
141
+ return `${WikiBaseUri}${getWikiPageName(entryId)}`;
142
+ case 'block_entity_type':
143
+ return `${WikiBaseUri}${getWikiPageName(entryId)}#Block_data`;
144
+ case 'custom_stat':
145
+ return `${WikiBaseUri}Statistics#List_of_custom_statistic_names`;
146
+ case 'game_event':
147
+ return `${WikiBaseUri}Game_event`;
148
+ case 'loot_condition_type':
149
+ return `${WikiBaseUri}Predicate#JSON_structure`;
150
+ case 'loot_function_type':
151
+ return `${WikiBaseUri}Item_modifier#JSON_structure`;
152
+ case 'loot_number_provider_type':
153
+ case 'loot_score_provider_type':
154
+ return `${WikiBaseUri}Loot_table#Number_Providers`;
155
+ case 'loot_pool_entry_type':
156
+ return `${WikiBaseUri}Loot_table#Tags`;
157
+ case 'motive':
158
+ return `${WikiBaseUri}Painting#Canvases`;
159
+ case 'potion':
160
+ return `${WikiBaseUri}Potion#Item_data`;
161
+ case 'particle_type':
162
+ return `${WikiBaseUri}Java_Edition_data_values#Particles`;
163
+ case 'recipe_serializer':
164
+ return `${WikiBaseUri}Recipe#${entryId}`;
165
+ case 'sound_event':
166
+ return `${SoundsBaseUri}?sound=${entryId}`;
167
+ case 'stat_type':
168
+ return `${WikiBaseUri}Statistics#Statistic_types_and_names`;
169
+ case 'villager_profession':
170
+ return `${WikiBaseUri}Villager#Villager_profession`;
171
+ case 'villager_type':
172
+ return `${WikiBaseUri}Villager#Villager_type`;
173
+ case 'worldgen/biome_source':
174
+ return `${WikiBaseUri}Java_Edition_data_values#Biome_sources`;
175
+ case 'worldgen/chunk_generator':
176
+ return `${WikiBaseUri}Java_Edition_data_values#Chunk_generators`;
177
+ default:
178
+ return McmetaSummaryUri;
179
+ }
180
+ };
181
+ for (const [registryId, registry] of Object.entries(registries)) {
182
+ if (isCategory(registryId)) {
183
+ for (const entryId of registry) {
184
+ symbols
185
+ .query(getUri(registryId, entryId), registryId, core.ResourceLocation.lengthen(entryId))
186
+ .enter({ usage: { type: 'declaration' } });
187
+ }
188
+ }
189
+ }
190
+ }
191
+ return symbols => {
192
+ addRegistriesSymbols(summary.registries, symbols);
193
+ addStatesSymbols('block', summary.blocks, symbols);
194
+ addStatesSymbols('fluid', summary.fluids, symbols);
195
+ };
196
+ }
197
+ exports.symbolRegistrar = symbolRegistrar;
198
+ exports.Fluids = {
199
+ flowing_lava: [{ falling: ['false', 'true'], level: ['1', '2', '3', '4', '5', '6', '7', '8'] }, { falling: 'false', level: '1' }],
200
+ flowing_water: [{ falling: ['false', 'true'], level: ['1', '2', '3', '4', '5', '6', '7', '8'] }, { falling: 'false', level: '1' }],
201
+ lava: [{ falling: ['false', 'true'] }, { falling: 'false' }],
202
+ water: [{ falling: ['false', 'true'] }, { falling: 'false' }],
203
+ };
204
+ //#endregion
205
+ //# sourceMappingURL=mcmeta.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import * as core from '@spyglassmc/core';
2
+ export * as dependency from './dependency';
3
+ export * as json from './json';
4
+ export * as mcf from './mcfunction';
5
+ export declare const initialize: core.ProjectInitializer;
6
+ //# sourceMappingURL=index.d.ts.map
package/lib/index.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.initialize = exports.mcf = exports.json = exports.dependency = void 0;
23
+ const core = __importStar(require("@spyglassmc/core"));
24
+ const nbt = __importStar(require("@spyglassmc/nbt"));
25
+ const binder_1 = require("./binder");
26
+ const dependency_1 = require("./dependency");
27
+ const jeJson = __importStar(require("./json"));
28
+ const jeMcf = __importStar(require("./mcfunction"));
29
+ exports.dependency = __importStar(require("./dependency"));
30
+ exports.json = __importStar(require("./json"));
31
+ exports.mcf = __importStar(require("./mcfunction"));
32
+ const initialize = async (ctx) => {
33
+ async function getPackMcmeta() {
34
+ let ans;
35
+ const uri = `${projectRoot}pack.mcmeta`;
36
+ try {
37
+ const data = await core.fileUtil.readJson(uri);
38
+ dependency_1.PackMcmeta.assert(data);
39
+ ans = data;
40
+ }
41
+ catch (e) {
42
+ if (!core.isEnoent(e)) {
43
+ // `pack.mcmeta` exists but broken. Log an error.
44
+ logger.error(`[je.initialize] Failed loading pack.mcmeta “${uri}”`, e);
45
+ }
46
+ }
47
+ return ans;
48
+ }
49
+ const { config, downloader, logger, meta, projectRoot } = ctx;
50
+ meta.registerUriBinder(binder_1.uriBinder);
51
+ const versions = await (0, dependency_1.getVersions)(ctx.downloader);
52
+ if (!versions) {
53
+ ctx.logger.error('[je-initialize] Failed loading game version list. Expect everything to be broken.');
54
+ return;
55
+ }
56
+ const packMcmeta = await getPackMcmeta();
57
+ const { major, id: version, isLatest } = (0, dependency_1.resolveConfiguredVersion)(config.env.gameVersion, { packMcmeta, versions });
58
+ meta.registerDependencyProvider('@mc-nbtdoc', () => (0, dependency_1.getMcNbtdoc)(downloader, version, isLatest));
59
+ const summary = await (0, dependency_1.getMcmetaSummary)(downloader, logger, version, isLatest, config.env.dataSource, config.env.mcmetaSummaryOverrides);
60
+ if (!summary.blocks || !summary.commands || !summary.fluids || !summary.registries) {
61
+ ctx.logger.error('[je-initialize] Failed loading mcmeta summaries. Expect everything to be broken.');
62
+ return;
63
+ }
64
+ meta.registerSymbolRegistrar('mcmeta-summary', {
65
+ checksum: summary.checksum,
66
+ registrar: (0, dependency_1.symbolRegistrar)(summary),
67
+ });
68
+ jeJson.initialize(ctx);
69
+ jeMcf.initialize(ctx, summary.commands, major);
70
+ nbt.initialize(ctx);
71
+ return {
72
+ loadedVersion: major,
73
+ };
74
+ };
75
+ exports.initialize = initialize;
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ export declare const item_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
2
+ export declare const block_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
3
+ export declare const fluid_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
4
+ export declare const location_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
5
+ export declare const distance_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
6
+ export declare const mob_effect_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
7
+ export declare const statistic_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
8
+ export declare const player_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
9
+ export declare const entity_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
10
+ export declare const damage_source_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
11
+ export declare const damage_predicate: import("@spyglassmc/json/lib/checker").JsonChecker;
12
+ export declare const criterion: import("@spyglassmc/json/lib/checker").JsonChecker;
13
+ export declare const advancement: import("@spyglassmc/json/lib/checker").JsonChecker;
14
+ //# sourceMappingURL=advancement.d.ts.map