@zardoy/flying-squid 0.0.123 → 0.0.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/default-settings.json +2 -4
- package/dist/app.js +18 -0
- package/dist/index.js +1 -1
- package/dist/lib/generations.d.ts +1 -1
- package/dist/lib/generations.js +2 -2
- package/dist/lib/generatorForWorldHeight.d.ts +5 -0
- package/dist/lib/generatorForWorldHeight.js +11 -0
- package/dist/lib/modules/dimensionCodec.d.ts +2 -0
- package/dist/lib/modules/dimensionCodec.js +121 -0
- package/dist/lib/modules/effects.js +3 -0
- package/dist/lib/modules/index.js +3 -1
- package/dist/lib/modules/playerLogin.js +3 -2
- package/dist/lib/modules/players.d.ts +6 -0
- package/dist/lib/modules/players.js +42 -16
- package/dist/lib/modules/players.test.d.ts +1 -0
- package/dist/lib/modules/players.test.js +30 -0
- package/dist/lib/modules/portal.d.ts +5 -0
- package/dist/lib/modules/portal.js +179 -0
- package/dist/lib/modules/recipes.d.ts +12 -0
- package/dist/lib/modules/recipes.js +266 -0
- package/dist/lib/modules/title.d.ts +4 -2
- package/dist/lib/modules/title.js +33 -16
- package/dist/lib/modules/title.test.d.ts +1 -0
- package/dist/lib/modules/title.test.js +102 -0
- package/dist/lib/modules/world.d.ts +36 -3
- package/dist/lib/modules/world.js +265 -46
- package/dist/lib/modules/worldManager.d.ts +1 -0
- package/dist/lib/modules/worldManager.js +119 -0
- package/dist/lib/playerDat.d.ts +1 -8
- package/dist/lib/playerDat.js +13 -2
- package/dist/lib/worldGenerations/biomeFix.d.ts +10 -0
- package/dist/lib/worldGenerations/biomeFix.js +19 -0
- package/dist/lib/worldGenerations/empty.js +4 -1
- package/dist/lib/worldGenerations/noise.d.ts +22 -0
- package/dist/lib/worldGenerations/noise.js +248 -0
- package/dist/minigames/oneblock.d.ts +1 -0
- package/dist/minigames/oneblock.js +41 -0
- package/dist/minigames/tntRun.d.ts +1 -0
- package/dist/minigames/tntRun.js +14 -0
- package/dist/modules.d.ts +2 -2
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.player = exports.server = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const user_error_1 = __importDefault(require("../user_error"));
|
|
9
|
+
const builtin_1 = require("minecraft-worldgen/dist/recipe/builtin");
|
|
10
|
+
/**
|
|
11
|
+
* Recipe worlds for experimenting: `/recipe new|set|regen|edit|list|apply|editor`.
|
|
12
|
+
* A recipe world's spec lives in `<world folder>/recipes/<name>.json` (best effort - browser file systems keep it in memory only).
|
|
13
|
+
* Custom channels (JSON in a string, like the other minecraft-web-client channels):
|
|
14
|
+
* - server -> client `minecraft-web-client:recipe-state` { world, spec, builtins: { name: { title, description, params[] } } } (data for a visual editor)
|
|
15
|
+
* - client -> server `minecraft-web-client:recipe-apply` { world, spec } (ops only: regenerates the world)
|
|
16
|
+
* - server -> client `minecraft-web-client:ide-open` (the web client's IDE editor) opens `recipes/<name>.json`; the editor's save arrives as `minecraft-web-client:ide-save` with id `recipe:<name>` and regenerates the world
|
|
17
|
+
*/
|
|
18
|
+
const STATE_CHANNEL = 'minecraft-web-client:recipe-state';
|
|
19
|
+
const APPLY_CHANNEL = 'minecraft-web-client:recipe-apply';
|
|
20
|
+
const IDE_OPEN_CHANNEL = 'minecraft-web-client:ide-open';
|
|
21
|
+
const IDE_SAVE_CHANNEL = 'minecraft-web-client:ide-save';
|
|
22
|
+
const str = ['pstring', { countType: 'i16' }];
|
|
23
|
+
const ideOpenChannel = ['container', [{ name: 'id', type: str }, { name: 'language', type: str }, { name: 'contents', type: str }, { name: 'line', type: 'i32' }, { name: 'column', type: 'i32' }, { name: 'title', type: str }]];
|
|
24
|
+
const ideSaveChannel = ['container', [{ name: 'id', type: str }, { name: 'contents', type: str }, { name: 'language', type: str }, { name: 'line', type: 'i32' }, { name: 'column', type: 'i32' }]];
|
|
25
|
+
const jsonChannel = ['container', [{ name: 'data', type: ['pstring', { countType: 'i16' }] }]];
|
|
26
|
+
const NAME_RE = /^[A-Za-z0-9_-]{1,32}$/;
|
|
27
|
+
const server = function (serv, options) {
|
|
28
|
+
const dir = options.worldFolder ? `${options.worldFolder}/recipes` : undefined;
|
|
29
|
+
const specs = {};
|
|
30
|
+
const fileOf = (name) => dir ? `${dir}/${name}.json` : undefined;
|
|
31
|
+
const save = (name) => {
|
|
32
|
+
const file = fileOf(name);
|
|
33
|
+
if (!file)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
catch { }
|
|
39
|
+
try {
|
|
40
|
+
fs_1.default.writeFileSync(file, JSON.stringify(specs[name], null, 2));
|
|
41
|
+
}
|
|
42
|
+
catch { }
|
|
43
|
+
};
|
|
44
|
+
/** the spec of a recipe world: file (edited by hand / IDE) wins over the remembered one */
|
|
45
|
+
const load = (name) => {
|
|
46
|
+
const file = fileOf(name);
|
|
47
|
+
try {
|
|
48
|
+
if (file && fs_1.default.existsSync(file))
|
|
49
|
+
return JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new user_error_1.default(`recipes/${name}.json is not valid JSON: ${e.message}`);
|
|
53
|
+
}
|
|
54
|
+
return specs[name] ?? serv.worldSpecs[name]?.recipe;
|
|
55
|
+
};
|
|
56
|
+
const validate = (spec) => {
|
|
57
|
+
if (!spec || typeof spec !== 'object')
|
|
58
|
+
throw new user_error_1.default('A recipe is a JSON object: { "builtin": "<name>", "options": {...} } or a full recipe');
|
|
59
|
+
if ('builtin' in spec && !builtin_1.BUILTIN_RECIPES[spec.builtin])
|
|
60
|
+
throw new user_error_1.default(`Unknown built-in recipe '${spec.builtin}'. Built-in: ${Object.keys(builtin_1.BUILTIN_RECIPES).join(', ')}`);
|
|
61
|
+
if (!('builtin' in spec) && !('script' in spec) && typeof spec.name !== 'string')
|
|
62
|
+
throw new user_error_1.default('A full recipe needs a "name"');
|
|
63
|
+
return spec;
|
|
64
|
+
};
|
|
65
|
+
const state = (name) => ({
|
|
66
|
+
world: name,
|
|
67
|
+
spec: specs[name] ?? load(name) ?? null,
|
|
68
|
+
builtins: Object.fromEntries(Object.entries(builtin_1.RECIPE_INFO)),
|
|
69
|
+
recipes: Object.keys(specs)
|
|
70
|
+
});
|
|
71
|
+
const sendState = (player, name, open = false) => {
|
|
72
|
+
try {
|
|
73
|
+
player._client.writeChannel(STATE_CHANNEL, { data: JSON.stringify({ ...state(name), open }) });
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
};
|
|
77
|
+
/** (re)creates the recipe world `name` and moves the players that were inside (plus `also`) into it */
|
|
78
|
+
async function apply(name, spec, also) {
|
|
79
|
+
if (!NAME_RE.test(name))
|
|
80
|
+
throw new user_error_1.default('World names may only contain letters, digits, _ and - (max 32 characters)');
|
|
81
|
+
if (['overworld', 'nether', 'end'].includes(name))
|
|
82
|
+
throw new user_error_1.default(`'${name}' is a core world`);
|
|
83
|
+
validate(spec);
|
|
84
|
+
const prev = serv.worlds[name];
|
|
85
|
+
const seed = prev?.seed;
|
|
86
|
+
const inside = prev ? serv.players.filter(p => p.world === prev) : [];
|
|
87
|
+
if (prev) {
|
|
88
|
+
await serv.removeWorld(name);
|
|
89
|
+
serv.deleteWorldData(name);
|
|
90
|
+
}
|
|
91
|
+
specs[name] = spec;
|
|
92
|
+
save(name);
|
|
93
|
+
const world = serv.createWorld({ name, environment: 'normal', recipe: spec, seed });
|
|
94
|
+
// surfaces generator errors (bad recipe) right away
|
|
95
|
+
try {
|
|
96
|
+
await world.getColumn(0, 0);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
// roll back: a world that cannot generate is useless (the previous spec is not restored - re-run the command with a fixed recipe)
|
|
100
|
+
try {
|
|
101
|
+
await serv.removeWorld(name);
|
|
102
|
+
serv.deleteWorldData(name);
|
|
103
|
+
}
|
|
104
|
+
catch { }
|
|
105
|
+
delete specs[name];
|
|
106
|
+
throw new user_error_1.default(`The recipe failed to generate: ${String(e.message ?? e).split('\n')[0]}`);
|
|
107
|
+
}
|
|
108
|
+
for (const p of new Set([...inside, ...(also ? [also] : [])])) {
|
|
109
|
+
await p.changeWorld(world, { dimension: world.dimensionId });
|
|
110
|
+
sendState(p, name);
|
|
111
|
+
}
|
|
112
|
+
return `World '${name}' generated from ${'builtin' in spec ? `recipe ${spec.builtin}` : 'a custom recipe'}${prev ? ' (regenerated)' : ''}`;
|
|
113
|
+
}
|
|
114
|
+
const parseValue = (v) => { try {
|
|
115
|
+
return JSON.parse(v);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return v;
|
|
119
|
+
} };
|
|
120
|
+
const actions = {
|
|
121
|
+
list() {
|
|
122
|
+
const own = Object.keys(specs).map(n => `${n}: ${'builtin' in specs[n] ? specs[n].builtin : 'custom'}`);
|
|
123
|
+
return `Built-in recipes: ${Object.keys(builtin_1.BUILTIN_RECIPES).join(', ')}\nRecipe worlds: ${own.join(', ') || '-'}`;
|
|
124
|
+
},
|
|
125
|
+
info([builtin]) {
|
|
126
|
+
const info = builtin_1.RECIPE_INFO[builtin];
|
|
127
|
+
if (!info)
|
|
128
|
+
throw new user_error_1.default(`Usage: /recipe info <${Object.keys(builtin_1.RECIPE_INFO).join('|')}>`);
|
|
129
|
+
return `${info.title}: ${info.description}\n` + info.params.map(p => ` ${p.key} (${p.type}${p.min !== undefined ? ` ${p.min}..${p.max}` : ''}, default ${p.default}) ${p.label}`).join('\n');
|
|
130
|
+
},
|
|
131
|
+
async new([name, builtin, ...kv], ctx) {
|
|
132
|
+
if (!name || !builtin)
|
|
133
|
+
throw new user_error_1.default(`Usage: /recipe new <name> <${Object.keys(builtin_1.BUILTIN_RECIPES).join('|')}> [key=value ...]`);
|
|
134
|
+
if (serv.worlds[name] && !specs[name])
|
|
135
|
+
throw new user_error_1.default(`World '${name}' already exists and is not a recipe world`);
|
|
136
|
+
const options = {};
|
|
137
|
+
for (const p of kv) {
|
|
138
|
+
const i = p.indexOf('=');
|
|
139
|
+
if (i > 0)
|
|
140
|
+
options[p.slice(0, i)] = parseValue(p.slice(i + 1));
|
|
141
|
+
}
|
|
142
|
+
return await apply(name, { builtin, options }, ctx.player);
|
|
143
|
+
},
|
|
144
|
+
/** /recipe set <world> key=value ... : change options of a built-in recipe world and regenerate it */
|
|
145
|
+
async set([name, ...kv], ctx) {
|
|
146
|
+
const spec = name ? load(name) : undefined;
|
|
147
|
+
if (!spec || !('builtin' in spec))
|
|
148
|
+
throw new user_error_1.default('Usage: /recipe set <world> key=value ... (the world must be a built-in recipe world; see /recipe info <recipe>)');
|
|
149
|
+
const options = { ...(spec.options ?? {}) };
|
|
150
|
+
for (const p of kv) {
|
|
151
|
+
const i = p.indexOf('=');
|
|
152
|
+
if (i <= 0)
|
|
153
|
+
throw new user_error_1.default(`Expected key=value, got '${p}'`);
|
|
154
|
+
options[p.slice(0, i)] = parseValue(p.slice(i + 1));
|
|
155
|
+
}
|
|
156
|
+
return await apply(name, { ...spec, options }, ctx.player);
|
|
157
|
+
},
|
|
158
|
+
async regen([name], ctx) {
|
|
159
|
+
const spec = name ? load(name) : undefined;
|
|
160
|
+
if (!spec)
|
|
161
|
+
throw new user_error_1.default('Usage: /recipe regen <world> (re-reads recipes/<world>.json and regenerates the world)');
|
|
162
|
+
return await apply(name, spec, ctx.player);
|
|
163
|
+
},
|
|
164
|
+
/** /recipe apply <world> <json> */
|
|
165
|
+
async apply([name], ctx, rest) {
|
|
166
|
+
const json = rest.slice(rest.indexOf(name) + name.length).trim();
|
|
167
|
+
if (!name || !json)
|
|
168
|
+
throw new user_error_1.default('Usage: /recipe apply <world> <json spec>');
|
|
169
|
+
let spec;
|
|
170
|
+
try {
|
|
171
|
+
spec = JSON.parse(json);
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
throw new user_error_1.default(`Invalid JSON: ${e.message}`);
|
|
175
|
+
}
|
|
176
|
+
return await apply(name, spec, ctx.player);
|
|
177
|
+
},
|
|
178
|
+
/** opens the recipe file in the IDE editor of the web client and sends the data for the visual editor */
|
|
179
|
+
edit([name], ctx) {
|
|
180
|
+
const spec = name ? load(name) : undefined;
|
|
181
|
+
if (!spec)
|
|
182
|
+
throw new user_error_1.default('Usage: /recipe edit <world>');
|
|
183
|
+
if (!ctx.player)
|
|
184
|
+
throw new user_error_1.default('Only players can open the editor');
|
|
185
|
+
specs[name] = spec;
|
|
186
|
+
save(name);
|
|
187
|
+
sendState(ctx.player, name);
|
|
188
|
+
try {
|
|
189
|
+
ctx.player._client.writeChannel(IDE_OPEN_CHANNEL, { id: `recipe:${name}`, language: 'json', contents: JSON.stringify(spec, null, 2), line: 0, column: 0, title: `recipes/${name}.json` });
|
|
190
|
+
}
|
|
191
|
+
catch { }
|
|
192
|
+
return `Opened recipes/${name}.json in the editor: save it to regenerate '${name}' (or /recipe regen ${name}).`;
|
|
193
|
+
},
|
|
194
|
+
editor(args, ctx) {
|
|
195
|
+
const name = args[0] ?? Object.keys(serv.worlds).find(n => serv.worlds[n] === ctx.player?.world);
|
|
196
|
+
if (ctx.player)
|
|
197
|
+
sendState(ctx.player, name && specs[name] ? name : (args[0] ?? 'lab'), true);
|
|
198
|
+
return 'Visual editor: docs/recipe-editor.html (standalone page; paste its JSON into /recipe apply <world> <json> or save it as recipes/<world>.json and /recipe regen <world>), or the web client\'s recipe panel (channel minecraft-web-client:recipe-state).';
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
serv.commands.add({
|
|
202
|
+
base: 'recipe',
|
|
203
|
+
info: 'Create / tune / regenerate custom dimensions (world recipes)',
|
|
204
|
+
usage: '/recipe <list|info|new|set|regen|apply|edit|editor> ...',
|
|
205
|
+
op: true,
|
|
206
|
+
parse: (str) => ({ tokens: str.trim().split(/\s+/).filter(Boolean), raw: str }),
|
|
207
|
+
async action({ tokens, raw }, ctx) {
|
|
208
|
+
const [sub, ...args] = tokens;
|
|
209
|
+
const fn = actions[(sub ?? 'list').toLowerCase()];
|
|
210
|
+
if (!fn)
|
|
211
|
+
throw new user_error_1.default(`Unknown subcommand '${sub}'. Try: list, info, new, set, regen, apply, edit, editor`);
|
|
212
|
+
return await fn(args, ctx, raw);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
// recipe worlds restored from the saved world list: remember their specs for /recipe set / regen / edit
|
|
216
|
+
serv.once('pluginsReady', () => {
|
|
217
|
+
for (const [name, spec] of Object.entries(serv.worldSpecs))
|
|
218
|
+
if (spec.recipe && typeof spec.recipe === 'object')
|
|
219
|
+
specs[name] = spec.recipe;
|
|
220
|
+
for (const [name, spec] of Object.entries(serv.worldSpecs))
|
|
221
|
+
if (typeof spec.recipe === 'string')
|
|
222
|
+
specs[name] = { builtin: spec.recipe };
|
|
223
|
+
});
|
|
224
|
+
serv.recipes = { apply, specs, state };
|
|
225
|
+
};
|
|
226
|
+
exports.server = server;
|
|
227
|
+
const player = function (player, serv) {
|
|
228
|
+
player._client.registerChannel(STATE_CHANNEL, jsonChannel);
|
|
229
|
+
player._client.registerChannel(APPLY_CHANNEL, jsonChannel);
|
|
230
|
+
player._client.registerChannel(IDE_OPEN_CHANNEL, ideOpenChannel);
|
|
231
|
+
player._client.registerChannel(IDE_SAVE_CHANNEL, ideSaveChannel);
|
|
232
|
+
player._client.on(IDE_SAVE_CHANNEL, async (packet) => {
|
|
233
|
+
if (!packet.id?.startsWith('recipe:'))
|
|
234
|
+
return;
|
|
235
|
+
try {
|
|
236
|
+
if (!player.op)
|
|
237
|
+
throw new user_error_1.default('Only operators can change recipes');
|
|
238
|
+
const message = await serv.recipes.apply(packet.id.slice('recipe:'.length), JSON.parse(packet.contents), player);
|
|
239
|
+
player.chat(message);
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
player.chat(`Recipe: ${e.message}`);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
player._client.on(APPLY_CHANNEL, async (packet) => {
|
|
246
|
+
try {
|
|
247
|
+
if (!player.op)
|
|
248
|
+
throw new user_error_1.default('Only operators can change recipes');
|
|
249
|
+
const { world, spec } = JSON.parse(packet.data);
|
|
250
|
+
const message = await serv.recipes.apply(world, spec, player);
|
|
251
|
+
player.chat(message);
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
player.chat(`Recipe: ${e.message}`);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
player.on('spawned', () => {
|
|
258
|
+
const name = Object.keys(serv.worlds).find(n => serv.worlds[n] === player.world);
|
|
259
|
+
if (name && serv.recipes.specs[name])
|
|
260
|
+
try {
|
|
261
|
+
player._client.writeChannel(STATE_CHANNEL, { data: JSON.stringify(serv.recipes.state(name)) });
|
|
262
|
+
}
|
|
263
|
+
catch { }
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
exports.player = player;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export declare const server: (serv: Server, options: Options) => void;
|
|
2
2
|
declare global {
|
|
3
3
|
interface Server {
|
|
4
|
-
sendTitle: (player: Player, title:
|
|
4
|
+
sendTitle: (player: Player, title: any, subtitle?: any, fadeIn?: number, stay?: number, fadeOut?: number) => void;
|
|
5
|
+
sendTitleText: (player: Player, title: any) => void;
|
|
6
|
+
sendSubtitle: (player: Player, subtitle: any) => void;
|
|
5
7
|
setTitleTimes: (player: Player, fadeIn?: number, stay?: number, fadeOut?: number) => void;
|
|
6
|
-
sendActionBar: (player: Player, message:
|
|
8
|
+
sendActionBar: (player: Player, message: any) => void;
|
|
7
9
|
clearTitle: (player: Player) => void;
|
|
8
10
|
resetTitle: (player: Player) => void;
|
|
9
11
|
}
|
|
@@ -4,18 +4,15 @@ exports.server = void 0;
|
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const server = function (serv, options) {
|
|
6
6
|
const supportsNewTitle = (0, utils_1.versionToNumber)(options.version) >= (0, utils_1.versionToNumber)('1.17');
|
|
7
|
+
const titleText = (text) => serv._createNetworkEncodedChatComponent?.(text) ?? JSON.stringify(typeof text === 'string' ? { text } : text);
|
|
7
8
|
serv.sendTitle = (player, title, subtitle, fadeIn = 10, stay = 70, fadeOut = 20) => {
|
|
8
9
|
if (supportsNewTitle) {
|
|
9
10
|
// 1.17+ uses separate packets
|
|
10
11
|
if (title) {
|
|
11
|
-
|
|
12
|
-
text: JSON.stringify({ text: title })
|
|
13
|
-
});
|
|
12
|
+
serv.sendTitleText(player, title);
|
|
14
13
|
}
|
|
15
14
|
if (subtitle) {
|
|
16
|
-
|
|
17
|
-
text: JSON.stringify({ text: subtitle })
|
|
18
|
-
});
|
|
15
|
+
serv.sendSubtitle(player, subtitle);
|
|
19
16
|
}
|
|
20
17
|
player._client.write('set_title_time', {
|
|
21
18
|
fadeIn,
|
|
@@ -31,19 +28,39 @@ const server = function (serv, options) {
|
|
|
31
28
|
fadeOut
|
|
32
29
|
});
|
|
33
30
|
if (title) {
|
|
34
|
-
|
|
35
|
-
action: 0,
|
|
36
|
-
text: JSON.stringify({ text: title })
|
|
37
|
-
});
|
|
31
|
+
serv.sendTitleText(player, title);
|
|
38
32
|
}
|
|
39
33
|
if (subtitle) {
|
|
40
|
-
|
|
41
|
-
action: 1,
|
|
42
|
-
text: JSON.stringify({ text: subtitle })
|
|
43
|
-
});
|
|
34
|
+
serv.sendSubtitle(player, subtitle);
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
37
|
};
|
|
38
|
+
serv.sendTitleText = (player, title) => {
|
|
39
|
+
if (supportsNewTitle) {
|
|
40
|
+
player._client.write('set_title_text', {
|
|
41
|
+
text: titleText(title)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
player._client.write('title', {
|
|
46
|
+
action: 0,
|
|
47
|
+
text: titleText(title)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
serv.sendSubtitle = (player, subtitle) => {
|
|
52
|
+
if (supportsNewTitle) {
|
|
53
|
+
player._client.write('set_title_subtitle', {
|
|
54
|
+
text: titleText(subtitle)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
player._client.write('title', {
|
|
59
|
+
action: 1,
|
|
60
|
+
text: titleText(subtitle)
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
47
64
|
serv.setTitleTimes = (player, fadeIn = 10, stay = 70, fadeOut = 20) => {
|
|
48
65
|
if (supportsNewTitle) {
|
|
49
66
|
player._client.write('set_title_time', {
|
|
@@ -65,14 +82,14 @@ const server = function (serv, options) {
|
|
|
65
82
|
if (supportsNewTitle) {
|
|
66
83
|
// 1.17+ has dedicated action bar packet
|
|
67
84
|
player._client.write('action_bar', {
|
|
68
|
-
text:
|
|
85
|
+
text: titleText(message)
|
|
69
86
|
});
|
|
70
87
|
}
|
|
71
88
|
else {
|
|
72
89
|
// Pre-1.17 uses title packet with action 2
|
|
73
90
|
player._client.write('title', {
|
|
74
91
|
action: 2, // Action bar
|
|
75
|
-
text:
|
|
92
|
+
text: titleText(message)
|
|
76
93
|
});
|
|
77
94
|
}
|
|
78
95
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const title_1 = require("./title");
|
|
5
|
+
const players_1 = require("./players");
|
|
6
|
+
const createHarness = (version) => {
|
|
7
|
+
const writes = [];
|
|
8
|
+
const serv = {
|
|
9
|
+
_createNetworkEncodedChatComponent: (value) => JSON.stringify(typeof value === 'string' ? { text: value } : value)
|
|
10
|
+
};
|
|
11
|
+
const player = {
|
|
12
|
+
_client: {
|
|
13
|
+
write: (name, params) => writes.push({ name, params })
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
(0, title_1.server)(serv, { version });
|
|
17
|
+
return { serv, player, writes };
|
|
18
|
+
};
|
|
19
|
+
(0, vitest_1.test)('sendTitle writes JSON components using the 1.17+ title packets', () => {
|
|
20
|
+
const { serv, player, writes } = createHarness('1.20.4');
|
|
21
|
+
serv.sendTitle(player, { text: 'Hello', color: 'gold' });
|
|
22
|
+
(0, vitest_1.expect)(writes).toEqual([
|
|
23
|
+
{
|
|
24
|
+
name: 'set_title_text',
|
|
25
|
+
params: { text: '{"text":"Hello","color":"gold"}' }
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'set_title_time',
|
|
29
|
+
params: { fadeIn: 10, stay: 70, fadeOut: 20 }
|
|
30
|
+
}
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.test)('sendActionBar writes JSON components using legacy title packets', () => {
|
|
34
|
+
const { serv, player, writes } = createHarness('1.16.5');
|
|
35
|
+
serv.sendActionBar(player, { text: 'Ready', color: 'green' });
|
|
36
|
+
(0, vitest_1.expect)(writes).toEqual([
|
|
37
|
+
{
|
|
38
|
+
name: 'title',
|
|
39
|
+
params: {
|
|
40
|
+
action: 2,
|
|
41
|
+
text: '{"text":"Ready","color":"green"}'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.test)('sendTitleText writes text without resetting title times', () => {
|
|
47
|
+
const { serv, player, writes } = createHarness('1.20.4');
|
|
48
|
+
serv.sendTitleText(player, { text: 'Hello', color: 'gold' });
|
|
49
|
+
(0, vitest_1.expect)(writes).toEqual([
|
|
50
|
+
{
|
|
51
|
+
name: 'set_title_text',
|
|
52
|
+
params: { text: '{"text":"Hello","color":"gold"}' }
|
|
53
|
+
}
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.test)('title command preserves timings when sending title text', () => {
|
|
57
|
+
const writes = [];
|
|
58
|
+
const commands = {};
|
|
59
|
+
const player = {
|
|
60
|
+
type: 'player',
|
|
61
|
+
_client: {
|
|
62
|
+
write: (name, params) => writes.push({ name, params })
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const serv = {
|
|
66
|
+
mcData: {},
|
|
67
|
+
commands: {
|
|
68
|
+
add: command => { commands[command.base] = command; }
|
|
69
|
+
},
|
|
70
|
+
selectorString: () => [player],
|
|
71
|
+
_createNetworkEncodedChatComponent: (value) => JSON.stringify(typeof value === 'string' ? { text: value } : value)
|
|
72
|
+
};
|
|
73
|
+
(0, title_1.server)(serv, { version: '1.20.4' });
|
|
74
|
+
(0, players_1.server)(serv, { version: '1.20.4' });
|
|
75
|
+
const titleCommand = commands.title;
|
|
76
|
+
titleCommand.action(titleCommand.parse('@a times 1 2 3'), {});
|
|
77
|
+
titleCommand.action(titleCommand.parse('@a title {"text":"Hello"}'), {});
|
|
78
|
+
(0, vitest_1.expect)(writes).toEqual([
|
|
79
|
+
{
|
|
80
|
+
name: 'set_title_time',
|
|
81
|
+
params: { fadeIn: 1, stay: 2, fadeOut: 3 }
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'set_title_text',
|
|
85
|
+
params: { text: '{"text":"Hello"}' }
|
|
86
|
+
}
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
(0, vitest_1.test)('title command rejects extra arguments for clear and reset', () => {
|
|
90
|
+
const commands = {};
|
|
91
|
+
const serv = {
|
|
92
|
+
mcData: {},
|
|
93
|
+
commands: {
|
|
94
|
+
add: command => { commands[command.base] = command; }
|
|
95
|
+
},
|
|
96
|
+
selectorString: () => [{ type: 'player', _client: { write: () => { } } }]
|
|
97
|
+
};
|
|
98
|
+
(0, title_1.server)(serv, { version: '1.20.4' });
|
|
99
|
+
(0, players_1.server)(serv, { version: '1.20.4' });
|
|
100
|
+
(0, vitest_1.expect)(() => commands.title.action(commands.title.parse('@a clear extra'), {})).toThrow('Clear does not accept extra arguments');
|
|
101
|
+
(0, vitest_1.expect)(() => commands.title.action(commands.title.parse('@a reset extra'), {})).toThrow('Reset does not accept extra arguments');
|
|
102
|
+
});
|
|
@@ -3,15 +3,38 @@ import { LevelDatFull } from 'prismarine-provider-anvil/src/level';
|
|
|
3
3
|
import { Vec3 } from 'vec3';
|
|
4
4
|
export declare const server: ServerModule;
|
|
5
5
|
export declare const player: (player: Player, serv: Server, settings: Options) => void;
|
|
6
|
+
export type WorldEnvironment = 'normal' | 'nether' | 'end';
|
|
7
|
+
export interface WorldSpec {
|
|
8
|
+
name: string;
|
|
9
|
+
/** client dimension type of the world (default normal) */
|
|
10
|
+
environment?: WorldEnvironment;
|
|
11
|
+
/** generator name (see generations.js; default: the server generator, nether/end variants for noise) */
|
|
12
|
+
generator?: string;
|
|
13
|
+
seed?: number | bigint | string;
|
|
14
|
+
/** noise generator overworld preset: default | amplified | large_biomes | caves | floating_islands */
|
|
15
|
+
preset?: string;
|
|
16
|
+
/** noise generator custom dimension: built-in recipe name (`mining` | `islands` | `chaos`), `{ builtin, options }`, `{ script, options }` or a recipe object (see docs/worlds.md) */
|
|
17
|
+
recipe?: string | Record<string, any>;
|
|
18
|
+
/** extra generator options */
|
|
19
|
+
options?: Record<string, any>;
|
|
20
|
+
}
|
|
6
21
|
export interface CustomWorld extends World {
|
|
22
|
+
/** releases the chunk generator (worker side caches) */
|
|
23
|
+
disposeGenerator?: () => Promise<void>;
|
|
7
24
|
blockEntityData: Record<string, any>;
|
|
8
25
|
portals: any[];
|
|
9
|
-
seed: number;
|
|
26
|
+
seed: number | bigint;
|
|
10
27
|
generatorName: string;
|
|
28
|
+
environment: WorldEnvironment;
|
|
29
|
+
/** dimension id used in respawn packets: -1 nether, 0 overworld, 1 end */
|
|
30
|
+
dimensionId: number;
|
|
31
|
+
worldName: string;
|
|
11
32
|
}
|
|
12
33
|
export declare const usedServerPathsV1: string[];
|
|
13
34
|
declare global {
|
|
14
35
|
interface Options {
|
|
36
|
+
/** Extra worlds created at startup (also creatable with `/mv create`): `{ name, environment: 'normal' | 'nether' | 'end', generator?, seed?, preset? }` */
|
|
37
|
+
worlds?: WorldSpec[];
|
|
15
38
|
/**
|
|
16
39
|
* @default false
|
|
17
40
|
* Whether to broadcast a message when the server saves.
|
|
@@ -19,6 +42,8 @@ declare global {
|
|
|
19
42
|
broadcastSaves?: boolean;
|
|
20
43
|
}
|
|
21
44
|
interface Server {
|
|
45
|
+
/** removes the saved chunks of an extra world (the world must not be loaded) */
|
|
46
|
+
deleteWorldData: (name: string) => void;
|
|
22
47
|
/** Global spawn and respawn point for every player */
|
|
23
48
|
spawnPoint?: Vec3;
|
|
24
49
|
/** Parsed level.dat of the loaded world (only if worldFolder is specificed) */
|
|
@@ -28,12 +53,20 @@ declare global {
|
|
|
28
53
|
"overworld": CustomWorld;
|
|
29
54
|
/** Contains the nether world. This **WILL** be used when a player travels through a portal if they are in the overworld! */
|
|
30
55
|
"netherworld": CustomWorld;
|
|
56
|
+
/** The End world (dimension id 1) */
|
|
57
|
+
"endworld": CustomWorld;
|
|
58
|
+
/** Spec each registered world was created from (name -> spec) */
|
|
59
|
+
worldSpecs: Record<string, WorldSpec>;
|
|
60
|
+
/** Creates, registers and returns a new world (Multiverse-style: any number of worlds, each with an environment and a generator) */
|
|
61
|
+
createWorld: (spec: WorldSpec) => CustomWorld;
|
|
62
|
+
/** Unregisters a world (players inside are moved to the overworld); core worlds cannot be removed */
|
|
63
|
+
removeWorld: (name: string) => Promise<void>;
|
|
31
64
|
/** Saves block in world and sends block update to all players of the same world. */
|
|
32
65
|
"setBlock": (world: CustomWorld, position: Vec3, stateId: number) => Promise<void>;
|
|
33
66
|
/** Sends a block action to all players of the same world. */
|
|
34
67
|
"setBlockAction": (world: CustomWorld, position: Vec3, actionId: number, actionParam: any) => Promise<void>;
|
|
35
|
-
/** Alias to serv.overworld.seed */
|
|
36
|
-
seed: number;
|
|
68
|
+
/** Alias to serv.overworld.seed (64-bit; bigint for seeds past 2^53) */
|
|
69
|
+
seed: number | bigint;
|
|
37
70
|
writeLevelDat: () => Promise<void>;
|
|
38
71
|
"overworldOriginalGenerator": (chunkX: number, chunkZ: number) => any;
|
|
39
72
|
"overworldGeneratorOverride"?: (chunkX: number, chunkZ: number, generationOptions: any) => any;
|