@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
package/dist/app.js
CHANGED
|
@@ -31,6 +31,15 @@ const argv = yargs
|
|
|
31
31
|
.option('ver', {
|
|
32
32
|
description: 'The version of the server to run (for clients and world)',
|
|
33
33
|
type: 'string',
|
|
34
|
+
})
|
|
35
|
+
.option('generation', {
|
|
36
|
+
alias: 'g',
|
|
37
|
+
description: 'World generator name (noise, superflat, empty, ...); env GENERATION also works',
|
|
38
|
+
type: 'string',
|
|
39
|
+
})
|
|
40
|
+
.option('seed', {
|
|
41
|
+
description: 'World seed (decimal string, 64-bit ok)',
|
|
42
|
+
type: 'string',
|
|
34
43
|
})
|
|
35
44
|
.option('world', {
|
|
36
45
|
description: 'Path to Java world save folder',
|
|
@@ -58,6 +67,15 @@ if (argv.port)
|
|
|
58
67
|
settings.port = +argv.port;
|
|
59
68
|
if (argv.ver)
|
|
60
69
|
settings.version = argv.ver;
|
|
70
|
+
const generationName = argv.generation ?? process.env.GENERATION;
|
|
71
|
+
if (generationName) {
|
|
72
|
+
settings.generation = { ...settings.generation, name: generationName, options: { ...settings.generation?.options } };
|
|
73
|
+
}
|
|
74
|
+
const seedArg = argv.seed ?? process.env.SEED;
|
|
75
|
+
if (seedArg !== undefined) {
|
|
76
|
+
settings.generation = settings.generation ?? { name: 'noise', options: {} };
|
|
77
|
+
settings.generation.options = { ...settings.generation.options, seed: seedArg };
|
|
78
|
+
}
|
|
61
79
|
if (argv.world)
|
|
62
80
|
settings.worldFolder = argv.world === 'false' ? false : argv.world;
|
|
63
81
|
if (!require('./lib/version').supportedVersions.includes(settings.version)) {
|
package/dist/index.js
CHANGED
|
@@ -195,7 +195,7 @@ class MCServer extends events_1.EventEmitter {
|
|
|
195
195
|
for (const value of values.filter(value => value.status === 'fulfilled')) {
|
|
196
196
|
// todo remove when updated to typescript 5.5
|
|
197
197
|
//@ts-ignore
|
|
198
|
-
if (value.value) {
|
|
198
|
+
if (typeof value.value === 'function') {
|
|
199
199
|
//@ts-ignore
|
|
200
200
|
server.cleanupFunctions.push(value.value);
|
|
201
201
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export let grass_field: typeof import("./worldGenerations/grass_field");
|
|
2
|
-
export let diamond_square: any;
|
|
3
2
|
export let empty: (options: any) => (chunkX: any, chunkZ: any) => any;
|
|
4
3
|
export let superflat: typeof import("./worldGenerations/superflat");
|
|
5
4
|
export let all_the_blocks: typeof import("./worldGenerations/all_the_blocks");
|
|
6
5
|
export let nether: typeof import("./worldGenerations/nether");
|
|
6
|
+
export let noise: typeof import("./worldGenerations/noise");
|
package/dist/lib/generations.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
grass_field: require('./worldGenerations/grass_field'),
|
|
3
|
-
diamond_square: require('diamond-square'),
|
|
4
3
|
empty: require('./worldGenerations/empty'),
|
|
5
4
|
superflat: require('./worldGenerations/superflat'),
|
|
6
5
|
all_the_blocks: require('./worldGenerations/all_the_blocks'),
|
|
7
|
-
nether: require('./worldGenerations/nether')
|
|
6
|
+
nether: require('./worldGenerations/nether'),
|
|
7
|
+
noise: require('./worldGenerations/noise')
|
|
8
8
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The noise generator (minecraft-worldgen) only builds the 1.18+ overworld (384 blocks from y=-64) and throws for any other height range.
|
|
3
|
+
* Worlds of older versions have no generator then: their saved chunks load as they are and new chunks are empty.
|
|
4
|
+
*/
|
|
5
|
+
export declare const generatorForWorldHeight: (name: string, minY: number, worldHeight: number) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatorForWorldHeight = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The noise generator (minecraft-worldgen) only builds the 1.18+ overworld (384 blocks from y=-64) and throws for any other height range.
|
|
6
|
+
* Worlds of older versions have no generator then: their saved chunks load as they are and new chunks are empty.
|
|
7
|
+
*/
|
|
8
|
+
const generatorForWorldHeight = (name, minY, worldHeight) => {
|
|
9
|
+
return name === 'noise' && (minY !== -64 || worldHeight !== 384) ? 'empty' : name;
|
|
10
|
+
};
|
|
11
|
+
exports.generatorForWorldHeight = generatorForWorldHeight;
|
|
@@ -1751,3 +1751,5 @@ export declare const dimensionOverworld: {
|
|
|
1751
1751
|
};
|
|
1752
1752
|
};
|
|
1753
1753
|
};
|
|
1754
|
+
/** dimension type NBT (what 1.16.2 - 1.18.2 `respawn` / `login` carry in `dimension`) for the overworld, nether and end, derived from the overworld one */
|
|
1755
|
+
export declare function dimensionNbt(dimensionId: number): any;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dimensionOverworld = exports.getDimensionCodec = void 0;
|
|
4
|
+
exports.dimensionNbt = dimensionNbt;
|
|
4
5
|
const getDimensionCodec = (height, useNewFormat, version) => {
|
|
5
6
|
if (version.startsWith('1.19'))
|
|
6
7
|
return codecsOverride1_19_4;
|
|
@@ -736,9 +737,92 @@ const getDimensionCodec = (height, useNewFormat, version) => {
|
|
|
736
737
|
}
|
|
737
738
|
}
|
|
738
739
|
};
|
|
740
|
+
addEndAndNetherBiomes(newFormat, oldFormat);
|
|
739
741
|
return useNewFormat ? newFormat : oldFormat;
|
|
740
742
|
};
|
|
741
743
|
exports.getDimensionCodec = getDimensionCodec;
|
|
744
|
+
/**
|
|
745
|
+
* The static codecs above only describe the overworld and the nether (and four biomes). The End dimension type and the nether / end biomes are derived from
|
|
746
|
+
* the existing nether dimension type / the_end biome entries so the client accepts `respawn` into the End and the biome ids the world generators emit.
|
|
747
|
+
*/
|
|
748
|
+
function addEndAndNetherBiomes(newFormat, oldFormat) {
|
|
749
|
+
const clone = (v) => JSON.parse(JSON.stringify(v));
|
|
750
|
+
// ---- 1.16.1 style dimension list (flat typed fields)
|
|
751
|
+
const oldList = oldFormat.value.dimension.value.value;
|
|
752
|
+
const oldNether = oldList.find(e => e.name?.value === 'minecraft:the_nether');
|
|
753
|
+
if (oldNether && !oldList.some(e => e.name?.value === 'minecraft:the_end')) {
|
|
754
|
+
const e = clone(oldNether);
|
|
755
|
+
const set = (k, type, value) => { e[k] = { type, value }; };
|
|
756
|
+
set('name', 'string', 'minecraft:the_end');
|
|
757
|
+
set('infiniburn', 'string', 'minecraft:infiniburn_end');
|
|
758
|
+
set('ultrawarm', 'byte', 0);
|
|
759
|
+
set('logical_height', 'int', 256);
|
|
760
|
+
set('natural', 'byte', 0);
|
|
761
|
+
set('bed_works', 'byte', 0);
|
|
762
|
+
set('fixed_time', 'long', [0, 6000]);
|
|
763
|
+
set('shrunk', 'byte', 0);
|
|
764
|
+
set('piglin_safe', 'byte', 0);
|
|
765
|
+
set('has_skylight', 'byte', 0);
|
|
766
|
+
set('has_ceiling', 'byte', 0);
|
|
767
|
+
set('ambient_light', 'float', 0);
|
|
768
|
+
set('has_raids', 'byte', 1);
|
|
769
|
+
set('respawn_anchor_works', 'byte', 0);
|
|
770
|
+
oldList.push(e);
|
|
771
|
+
}
|
|
772
|
+
// ---- 1.16.2 - 1.18.2 registry style
|
|
773
|
+
const types = newFormat.value['minecraft:dimension_type'].value.value.value.value;
|
|
774
|
+
const nether = types.find(e => e.name.value === 'minecraft:the_nether');
|
|
775
|
+
if (nether && !types.some(e => e.name.value === 'minecraft:the_end')) {
|
|
776
|
+
const e = clone(nether);
|
|
777
|
+
e.name.value = 'minecraft:the_end';
|
|
778
|
+
e.id.value = Math.max(...types.map(t => t.id.value)) + 1;
|
|
779
|
+
const v = e.element.value;
|
|
780
|
+
const set = (k, type, value) => { v[k] = { type, value }; };
|
|
781
|
+
set('piglin_safe', 'byte', 0);
|
|
782
|
+
set('natural', 'byte', 0);
|
|
783
|
+
set('ambient_light', 'float', 0);
|
|
784
|
+
set('infiniburn', 'string', '#minecraft:infiniburn_end');
|
|
785
|
+
set('respawn_anchor_works', 'byte', 0);
|
|
786
|
+
set('has_skylight', 'byte', 0);
|
|
787
|
+
set('bed_works', 'byte', 0);
|
|
788
|
+
set('effects', 'string', 'minecraft:the_end');
|
|
789
|
+
set('fixed_time', 'long', [0, 6000]);
|
|
790
|
+
set('has_raids', 'byte', 1);
|
|
791
|
+
set('logical_height', 'int', 256);
|
|
792
|
+
set('coordinate_scale', 'double', 1);
|
|
793
|
+
set('min_y', 'int', 0);
|
|
794
|
+
set('has_ceiling', 'byte', 0);
|
|
795
|
+
set('ultrawarm', 'byte', 0);
|
|
796
|
+
set('height', 'int', 256);
|
|
797
|
+
types.push(e);
|
|
798
|
+
}
|
|
799
|
+
// ---- biomes (vanilla 1.18.2 ids)
|
|
800
|
+
const biomes = newFormat.value['minecraft:worldgen/biome'].value.value.value.value;
|
|
801
|
+
const theEnd = biomes.find(b => b.name.value === 'minecraft:the_end');
|
|
802
|
+
const extra = [
|
|
803
|
+
// name, id, category, fog_color, sky_color
|
|
804
|
+
['nether_wastes', 51, 'nether', 3344392, 3344392], ['soul_sand_valley', 52, 'nether', 1787717, 1787717], ['crimson_forest', 53, 'nether', 3343107, 3343107],
|
|
805
|
+
['warped_forest', 54, 'nether', 1705242, 1705242], ['basalt_deltas', 55, 'nether', 6840176, 6840176],
|
|
806
|
+
['end_highlands', 57, 'the_end', 10518688, 0], ['end_midlands', 58, 'the_end', 10518688, 0], ['small_end_islands', 59, 'the_end', 10518688, 0], ['end_barrens', 60, 'the_end', 10518688, 0]
|
|
807
|
+
];
|
|
808
|
+
if (theEnd) {
|
|
809
|
+
for (const [name, id, category, fog, sky] of extra) {
|
|
810
|
+
if (biomes.some(b => b.name.value === 'minecraft:' + name))
|
|
811
|
+
continue;
|
|
812
|
+
const e = clone(theEnd);
|
|
813
|
+
e.name.value = 'minecraft:' + name;
|
|
814
|
+
e.id.value = id;
|
|
815
|
+
e.element.value.category.value = category;
|
|
816
|
+
e.element.value.effects.value.fog_color.value = fog;
|
|
817
|
+
e.element.value.effects.value.sky_color.value = sky;
|
|
818
|
+
if (category === 'nether') {
|
|
819
|
+
e.element.value.temperature.value = 2;
|
|
820
|
+
e.element.value.downfall.value = 0;
|
|
821
|
+
}
|
|
822
|
+
biomes.push(e);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
742
826
|
const codecsOverride1_19_4 = {
|
|
743
827
|
"type": "compound",
|
|
744
828
|
"name": "",
|
|
@@ -7278,3 +7362,40 @@ exports.dimensionOverworld = {
|
|
|
7278
7362
|
}
|
|
7279
7363
|
}
|
|
7280
7364
|
};
|
|
7365
|
+
/** dimension type NBT (what 1.16.2 - 1.18.2 `respawn` / `login` carry in `dimension`) for the overworld, nether and end, derived from the overworld one */
|
|
7366
|
+
function dimensionNbt(dimensionId) {
|
|
7367
|
+
const clone = JSON.parse(JSON.stringify(exports.dimensionOverworld));
|
|
7368
|
+
if (dimensionId === 0)
|
|
7369
|
+
return clone;
|
|
7370
|
+
const v = clone.value;
|
|
7371
|
+
const set = (k, type, value) => { v[k] = { type, value }; };
|
|
7372
|
+
set('min_y', 'int', 0);
|
|
7373
|
+
set('height', 'int', 256);
|
|
7374
|
+
set('piglin_safe', 'byte', dimensionId === -1 ? 1 : 0);
|
|
7375
|
+
set('natural', 'byte', 0);
|
|
7376
|
+
set('bed_works', 'byte', 0);
|
|
7377
|
+
set('has_raids', 'byte', dimensionId === 1 ? 1 : 0);
|
|
7378
|
+
set('has_skylight', 'byte', 0);
|
|
7379
|
+
set('has_ceiling', 'byte', dimensionId === -1 ? 1 : 0);
|
|
7380
|
+
if (dimensionId === -1) {
|
|
7381
|
+
set('infiniburn', 'string', '#minecraft:infiniburn_nether');
|
|
7382
|
+
set('effects', 'string', 'minecraft:the_nether');
|
|
7383
|
+
set('ultrawarm', 'byte', 1);
|
|
7384
|
+
set('logical_height', 'int', 128);
|
|
7385
|
+
set('coordinate_scale', 'double', 8);
|
|
7386
|
+
set('ambient_light', 'float', 0.1);
|
|
7387
|
+
set('respawn_anchor_works', 'byte', 1);
|
|
7388
|
+
set('fixed_time', 'long', [0, 18000]);
|
|
7389
|
+
}
|
|
7390
|
+
else {
|
|
7391
|
+
set('infiniburn', 'string', '#minecraft:infiniburn_end');
|
|
7392
|
+
set('effects', 'string', 'minecraft:the_end');
|
|
7393
|
+
set('ultrawarm', 'byte', 0);
|
|
7394
|
+
set('logical_height', 'int', 256);
|
|
7395
|
+
set('coordinate_scale', 'double', 1);
|
|
7396
|
+
set('ambient_light', 'float', 0);
|
|
7397
|
+
set('respawn_anchor_works', 'byte', 0);
|
|
7398
|
+
set('fixed_time', 'long', [0, 6000]);
|
|
7399
|
+
}
|
|
7400
|
+
return clone;
|
|
7401
|
+
}
|
|
@@ -40,6 +40,9 @@ const entity = function (entity, serv) {
|
|
|
40
40
|
entity.addEffect = (effectId, opt = {}) => {
|
|
41
41
|
const amp = typeof opt.amplifier === 'undefined' ? 0 : opt.amplifier;
|
|
42
42
|
if (!entity.effects[effectId] || opt.override || amp < entity.effects[effectId].amplifier) {
|
|
43
|
+
const previousEffect = entity.effects[effectId];
|
|
44
|
+
if (previousEffect?.timeout)
|
|
45
|
+
clearTimeout(previousEffect.timeout);
|
|
43
46
|
entity.effects[effectId] = {
|
|
44
47
|
amplifier: opt.amplifier || 0,
|
|
45
48
|
duration: opt.duration || 30 * 20,
|
|
@@ -46,6 +46,7 @@ module.exports = {
|
|
|
46
46
|
'pluginsFolder': require('./pluginsFolder'),
|
|
47
47
|
'portal': require('./portal'),
|
|
48
48
|
'pvp': require('./pvp'),
|
|
49
|
+
'recipes': require('./recipes'),
|
|
49
50
|
'redstone': require('./redstone'),
|
|
50
51
|
'resourcePack': require('./resourcePack'),
|
|
51
52
|
'respawn': require('./respawn'),
|
|
@@ -65,6 +66,7 @@ module.exports = {
|
|
|
65
66
|
'utils': require('./utils'),
|
|
66
67
|
'warps': require('./warps'),
|
|
67
68
|
'weather': require('./weather'),
|
|
68
|
-
'world': require('./world')
|
|
69
|
+
'world': require('./world'),
|
|
70
|
+
'worldManager': require('./worldManager')
|
|
69
71
|
}
|
|
70
72
|
}
|
|
@@ -227,8 +227,9 @@ const player = async function (player, serv, settings) {
|
|
|
227
227
|
Object.keys(playerData.player).forEach(k => { player[k] = playerData.player[k]; });
|
|
228
228
|
await player.findSpawnPoint();
|
|
229
229
|
// Set world based on saved dimension data, fallback to overworld
|
|
230
|
-
const
|
|
231
|
-
|
|
230
|
+
const rawDimension = playerData?.player?.dimension;
|
|
231
|
+
const savedDimension = typeof rawDimension === 'number' ? (rawDimension === -1 ? 'nether' : rawDimension === 1 ? 'end' : 'overworld') : String(rawDimension ?? 'overworld').replace(/^(minecraft|flyingsquid):/, '');
|
|
232
|
+
player.world = (savedDimension === 'the_nether' || savedDimension === 'nether') ? serv.netherworld : (savedDimension === 'the_end' || savedDimension === 'end') ? serv.endworld : (serv.worlds[savedDimension] ?? serv.overworld);
|
|
232
233
|
if (!player.disconnected) {
|
|
233
234
|
// it's possible player gets kicked during login process ; don't add them to the server
|
|
234
235
|
serv.players.push(player);
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export declare const parseTitleMessage: (message: string) => any;
|
|
2
|
+
export declare const parseTitleTimes: (value: string) => {
|
|
3
|
+
fadeIn: number;
|
|
4
|
+
stay: number;
|
|
5
|
+
fadeOut: number;
|
|
6
|
+
};
|
|
1
7
|
export declare const server: (serv: Server, { version }: Options) => void;
|
|
2
8
|
declare global {
|
|
3
9
|
interface Server {
|
|
@@ -3,10 +3,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.server = void 0;
|
|
6
|
+
exports.server = exports.parseTitleTimes = exports.parseTitleMessage = void 0;
|
|
7
7
|
const user_error_1 = __importDefault(require("../user_error"));
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const prismarine_item_1 = __importDefault(require("prismarine-item"));
|
|
10
|
+
const parseTitleMessage = (message) => {
|
|
11
|
+
const trimmed = message.trim();
|
|
12
|
+
if (!trimmed)
|
|
13
|
+
throw new user_error_1.default('Title text is required');
|
|
14
|
+
if (!trimmed.startsWith('{') && !trimmed.startsWith('['))
|
|
15
|
+
return message;
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(trimmed);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new user_error_1.default('Title text must be valid JSON');
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.parseTitleMessage = parseTitleMessage;
|
|
24
|
+
const parseTitleTimes = (value) => {
|
|
25
|
+
const parts = value.trim().split(/\s+/);
|
|
26
|
+
if (parts.length !== 3)
|
|
27
|
+
throw new user_error_1.default('Expected fadeIn, stay, and fadeOut');
|
|
28
|
+
if (parts.some(part => !/^\d+$/.test(part)))
|
|
29
|
+
throw new user_error_1.default('Times must be numbers');
|
|
30
|
+
const times = parts.map(part => parseInt(part, 10));
|
|
31
|
+
return {
|
|
32
|
+
fadeIn: times[0],
|
|
33
|
+
stay: times[1],
|
|
34
|
+
fadeOut: times[2]
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.parseTitleTimes = parseTitleTimes;
|
|
10
38
|
const server = function (serv, { version }) {
|
|
11
39
|
const mcData = serv.mcData;
|
|
12
40
|
const Item = (0, prismarine_item_1.default)(version);
|
|
@@ -247,7 +275,7 @@ const server = function (serv, { version }) {
|
|
|
247
275
|
serv.commands.add({
|
|
248
276
|
base: 'title',
|
|
249
277
|
info: 'Show a title, subtitle, or action bar.',
|
|
250
|
-
usage: '/title <targets> (title|subtitle|actionbar|times|clear|reset) <message>',
|
|
278
|
+
usage: '/title <targets> (title|subtitle|actionbar|times|clear|reset) <message|times>',
|
|
251
279
|
tab: ['selector', 'text'],
|
|
252
280
|
op: true,
|
|
253
281
|
parse(str) {
|
|
@@ -257,45 +285,43 @@ const server = function (serv, { version }) {
|
|
|
257
285
|
return { target: match[1], mode: match[2], rest: match[3] ?? '' };
|
|
258
286
|
},
|
|
259
287
|
action({ target, mode, rest }, ctx) {
|
|
260
|
-
if (!ctx.player)
|
|
261
|
-
return;
|
|
262
288
|
const players = serv.getPlayers(target, ctx.player);
|
|
263
289
|
if (players.length < 1)
|
|
264
290
|
throw new user_error_1.default('Player not found');
|
|
265
291
|
const action = mode.toLowerCase();
|
|
266
292
|
if (action === 'clear') {
|
|
293
|
+
if (rest.trim())
|
|
294
|
+
throw new user_error_1.default('Clear does not accept extra arguments');
|
|
267
295
|
players.forEach(player => serv.clearTitle(player));
|
|
268
296
|
return 'Title cleared';
|
|
269
297
|
}
|
|
270
298
|
if (action === 'reset') {
|
|
299
|
+
if (rest.trim())
|
|
300
|
+
throw new user_error_1.default('Reset does not accept extra arguments');
|
|
271
301
|
players.forEach(player => serv.resetTitle(player));
|
|
272
302
|
return 'Title reset';
|
|
273
303
|
}
|
|
274
304
|
if (action === 'times') {
|
|
275
|
-
const
|
|
276
|
-
const fadeIn = parseInt(fadeInRaw, 10);
|
|
277
|
-
const stay = parseInt(stayRaw, 10);
|
|
278
|
-
const fadeOut = parseInt(fadeOutRaw, 10);
|
|
279
|
-
if ([fadeIn, stay, fadeOut].some(Number.isNaN))
|
|
280
|
-
throw new user_error_1.default('Times must be numbers');
|
|
305
|
+
const { fadeIn, stay, fadeOut } = (0, exports.parseTitleTimes)(rest);
|
|
281
306
|
players.forEach(player => serv.setTitleTimes(player, fadeIn, stay, fadeOut));
|
|
282
307
|
return 'Title times updated';
|
|
283
308
|
}
|
|
284
|
-
if (!
|
|
285
|
-
throw new user_error_1.default('
|
|
309
|
+
if (!['title', 'subtitle', 'actionbar'].includes(action)) {
|
|
310
|
+
throw new user_error_1.default('Unknown title mode');
|
|
311
|
+
}
|
|
312
|
+
const message = (0, exports.parseTitleMessage)(rest);
|
|
286
313
|
if (action === 'title') {
|
|
287
|
-
players.forEach(player => serv.
|
|
314
|
+
players.forEach(player => serv.sendTitleText(player, message));
|
|
288
315
|
return 'Title sent';
|
|
289
316
|
}
|
|
290
317
|
if (action === 'subtitle') {
|
|
291
|
-
players.forEach(player => serv.
|
|
318
|
+
players.forEach(player => serv.sendSubtitle(player, message));
|
|
292
319
|
return 'Subtitle sent';
|
|
293
320
|
}
|
|
294
321
|
if (action === 'actionbar') {
|
|
295
|
-
players.forEach(player => serv.sendActionBar(player,
|
|
322
|
+
players.forEach(player => serv.sendActionBar(player, message));
|
|
296
323
|
return 'Action bar sent';
|
|
297
324
|
}
|
|
298
|
-
throw new user_error_1.default('Unknown title mode');
|
|
299
325
|
}
|
|
300
326
|
});
|
|
301
327
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const user_error_1 = __importDefault(require("../user_error"));
|
|
8
|
+
const players_1 = require("./players");
|
|
9
|
+
(0, vitest_1.test)('parseTitleMessage accepts vanilla JSON text components', () => {
|
|
10
|
+
(0, vitest_1.expect)((0, players_1.parseTitleMessage)('{"text":"Hello","color":"gold"}')).toEqual({
|
|
11
|
+
text: 'Hello',
|
|
12
|
+
color: 'gold'
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
(0, vitest_1.test)('parseTitleMessage preserves plain text messages', () => {
|
|
16
|
+
(0, vitest_1.expect)((0, players_1.parseTitleMessage)('Hello world')).toEqual('Hello world');
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.test)('parseTitleMessage rejects invalid JSON components', () => {
|
|
19
|
+
(0, vitest_1.expect)(() => (0, players_1.parseTitleMessage)('{"text":')).toThrow(user_error_1.default);
|
|
20
|
+
});
|
|
21
|
+
(0, vitest_1.test)('parseTitleTimes validates three non-negative numbers', () => {
|
|
22
|
+
(0, vitest_1.expect)((0, players_1.parseTitleTimes)('10 70 20')).toEqual({
|
|
23
|
+
fadeIn: 10,
|
|
24
|
+
stay: 70,
|
|
25
|
+
fadeOut: 20
|
|
26
|
+
});
|
|
27
|
+
(0, vitest_1.expect)(() => (0, players_1.parseTitleTimes)('10 70')).toThrow(user_error_1.default);
|
|
28
|
+
(0, vitest_1.expect)(() => (0, players_1.parseTitleTimes)('-1 70 20')).toThrow(user_error_1.default);
|
|
29
|
+
(0, vitest_1.expect)(() => (0, players_1.parseTitleTimes)('1x 70 20')).toThrow(user_error_1.default);
|
|
30
|
+
});
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
1
2
|
export declare const player: (player: Player, serv: Server, { version }: Options) => void;
|
|
2
3
|
export declare const server: (serv: Server, { version }: Options) => void;
|
|
3
4
|
declare global {
|
|
5
|
+
interface Server {
|
|
6
|
+
/** nearest registered portal of `world` within `radius` blocks of (x, z) - a new nether portal is built when there is none; returns the standing position */
|
|
7
|
+
netherPortalNear: (world: any, x: number, z: number, radius: number) => Promise<Vec3>;
|
|
8
|
+
}
|
|
4
9
|
}
|
|
@@ -68,6 +68,185 @@ const server = function (serv, { version }) {
|
|
|
68
68
|
return { id: fireType, data: 0 };
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
|
+
// ---------------------------------------------------------------------------------------------- travelling
|
|
72
|
+
const Block = require('prismarine-block')(require('prismarine-registry')(version));
|
|
73
|
+
const netherPortalName = serv.supportFeature('theFlattening') ? 'nether_portal' : 'portal';
|
|
74
|
+
const solidType = (type) => type !== 0 && !['water', 'lava', 'bubble_column', 'kelp', 'seagrass', 'tall_seagrass'].includes(mcData.blocks[type]?.name);
|
|
75
|
+
const MAX_Y = (world) => (world['min_y'] ?? 0) + (world['height'] ?? 256) - 1;
|
|
76
|
+
/** first standable position near the column: above the first solid block with two free blocks over it (nether: searched from the middle of the world) */
|
|
77
|
+
async function findStandY(world, x, z) {
|
|
78
|
+
const min = world['min_y'] ?? 0;
|
|
79
|
+
const max = MAX_Y(world);
|
|
80
|
+
const free = async (y) => (await world.getBlockType(new vec3_1.Vec3(x, y, z))) === 0;
|
|
81
|
+
const ok = async (y) => solidType(await world.getBlockType(new vec3_1.Vec3(x, y - 1, z))) && await free(y) && await free(y + 1) && await free(y + 2);
|
|
82
|
+
if (world.environment === 'nether') {
|
|
83
|
+
for (let y = 70; y <= max - 8; y++)
|
|
84
|
+
if (await ok(y))
|
|
85
|
+
return y;
|
|
86
|
+
for (let y = 69; y >= min + 8; y--)
|
|
87
|
+
if (await ok(y))
|
|
88
|
+
return y;
|
|
89
|
+
return 70;
|
|
90
|
+
}
|
|
91
|
+
for (let y = max - 3; y > min + 1; y--)
|
|
92
|
+
if (await ok(y))
|
|
93
|
+
return y;
|
|
94
|
+
return 80;
|
|
95
|
+
}
|
|
96
|
+
/** a 4x5 obsidian frame (plane x) with portal blocks inside, a platform below and free space around; returns the portal record */
|
|
97
|
+
async function buildNetherPortal(world, x, y, z) {
|
|
98
|
+
const bottom = [];
|
|
99
|
+
const left = [];
|
|
100
|
+
const right = [];
|
|
101
|
+
const top = [];
|
|
102
|
+
const air = [];
|
|
103
|
+
const obsidian = mcData.blocksByName.obsidian.id;
|
|
104
|
+
for (let dx = -1; dx <= 2; dx++)
|
|
105
|
+
for (let dz = -1; dz <= 1; dz++)
|
|
106
|
+
for (let dy = -1; dy <= 4; dy++) {
|
|
107
|
+
const pos = new vec3_1.Vec3(x + dx, y + dy, z + dz);
|
|
108
|
+
const onFrame = dz === 0 && (dx === -1 || dx === 2 || dy === -1 || dy === 3);
|
|
109
|
+
if (dy === -1 && dz !== 0)
|
|
110
|
+
await serv.setBlockType(world, pos, obsidian);
|
|
111
|
+
else if (onFrame && dy <= 3) {
|
|
112
|
+
await serv.setBlockType(world, pos, obsidian);
|
|
113
|
+
if (dy === -1 && dx >= 0 && dx <= 1)
|
|
114
|
+
bottom.push(pos);
|
|
115
|
+
else if (dy === 3 && dx >= 0 && dx <= 1)
|
|
116
|
+
top.push(pos);
|
|
117
|
+
else if (dx === -1 && dy >= 0 && dy <= 2)
|
|
118
|
+
left.push(pos);
|
|
119
|
+
else if (dx === 2 && dy >= 0 && dy <= 2)
|
|
120
|
+
right.push(pos);
|
|
121
|
+
}
|
|
122
|
+
else if (dz === 0 && dx >= 0 && dx <= 1 && dy >= 0 && dy <= 2) {
|
|
123
|
+
await serv.setBlock(world, pos, portalX);
|
|
124
|
+
air.push(pos);
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
await serv.setBlockType(world, pos, 0);
|
|
128
|
+
}
|
|
129
|
+
const portal = { bottom, left, right, top, air };
|
|
130
|
+
world.portals.push(portal);
|
|
131
|
+
return portal;
|
|
132
|
+
}
|
|
133
|
+
/** nearest registered portal of `world` around (x, z), or a new one at the column's standable height */
|
|
134
|
+
async function portalNear(world, x, z, radius) {
|
|
135
|
+
let best;
|
|
136
|
+
let bestD = Infinity;
|
|
137
|
+
for (const portal of world.portals ?? []) {
|
|
138
|
+
const air = portal.air;
|
|
139
|
+
if (!air?.length)
|
|
140
|
+
continue;
|
|
141
|
+
// standing spot: centre of the portal's free blocks at their lowest level
|
|
142
|
+
const y = Math.min(...air.map(a => a.y));
|
|
143
|
+
const c = new vec3_1.Vec3(air.reduce((a, p) => a + p.x, 0) / air.length + 0.5, y, air.reduce((a, p) => a + p.z, 0) / air.length + 0.5);
|
|
144
|
+
const d = Math.hypot(c.x - x, c.z - z);
|
|
145
|
+
if (d <= radius && d < bestD) {
|
|
146
|
+
best = c;
|
|
147
|
+
bestD = d;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (best)
|
|
151
|
+
return best;
|
|
152
|
+
await world.getColumn(x >> 4, z >> 4);
|
|
153
|
+
const y = await findStandY(world, Math.floor(x), Math.floor(z));
|
|
154
|
+
await buildNetherPortal(world, Math.floor(x), y, Math.floor(z));
|
|
155
|
+
return new vec3_1.Vec3(Math.floor(x) + 1, y, Math.floor(z) + 0.5);
|
|
156
|
+
}
|
|
157
|
+
serv.netherPortalNear = portalNear;
|
|
158
|
+
const portalState = new WeakMap();
|
|
159
|
+
const endPortalType = mcData.blocksByName.end_portal?.id;
|
|
160
|
+
const netherPortalType = mcData.blocksByName[netherPortalName]?.id;
|
|
161
|
+
async function checkPlayer(player) {
|
|
162
|
+
const st = portalState.get(player) ?? { ticks: 0, locked: false, busy: false };
|
|
163
|
+
portalState.set(player, st);
|
|
164
|
+
if (st.busy || !player.world)
|
|
165
|
+
return;
|
|
166
|
+
st.busy = true;
|
|
167
|
+
try {
|
|
168
|
+
const feet = new vec3_1.Vec3(Math.floor(player.position.x), Math.floor(player.position.y), Math.floor(player.position.z));
|
|
169
|
+
const here = await player.world.getBlockType(feet);
|
|
170
|
+
const inNether = here === netherPortalType || (await player.world.getBlockType(feet.offset(0, 1, 0))) === netherPortalType;
|
|
171
|
+
const inEnd = endPortalType !== undefined && here === endPortalType;
|
|
172
|
+
if (!inNether && !inEnd) {
|
|
173
|
+
st.ticks = 0;
|
|
174
|
+
st.locked = false;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (st.locked)
|
|
178
|
+
return;
|
|
179
|
+
const world = player.world;
|
|
180
|
+
if (inEnd) {
|
|
181
|
+
st.locked = true;
|
|
182
|
+
if (world.environment === 'end')
|
|
183
|
+
await player.changeWorld(serv.overworld, { dimension: serv.overworld.dimensionId });
|
|
184
|
+
else
|
|
185
|
+
await player.changeWorld(serv.endworld, { dimension: serv.endworld.dimensionId, position: new vec3_1.Vec3(100.5, 49, 0.5) });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
st.ticks += 4;
|
|
189
|
+
if (st.ticks < (player.gameMode === 1 ? 4 : 80))
|
|
190
|
+
return;
|
|
191
|
+
st.locked = true;
|
|
192
|
+
st.ticks = 0;
|
|
193
|
+
const toNether = world.environment === 'normal';
|
|
194
|
+
const dest = toNether ? serv.netherworld : serv.overworld;
|
|
195
|
+
if (!dest || dest === world || world.environment === 'end')
|
|
196
|
+
return;
|
|
197
|
+
const f = toNether ? 1 / 8 : 8;
|
|
198
|
+
const pos = await portalNear(dest, player.position.x * f, player.position.z * f, toNether ? 128 : 16);
|
|
199
|
+
await player.changeWorld(dest, { dimension: dest.dimensionId, position: pos });
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
serv.warn('portal travel failed: ' + e.message);
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
st.busy = false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
serv.on('tick', (_delta, count) => {
|
|
209
|
+
if (count % 4 !== 0)
|
|
210
|
+
return;
|
|
211
|
+
for (const p of serv.players)
|
|
212
|
+
void checkPlayer(p);
|
|
213
|
+
});
|
|
214
|
+
// an eye of ender in an end portal frame; the twelfth eye opens the portal
|
|
215
|
+
if (mcData.blocksByName.end_portal_frame && serv.supportFeature('theFlattening')) {
|
|
216
|
+
const frame = mcData.blocksByName.end_portal_frame;
|
|
217
|
+
const ringOffsets = [];
|
|
218
|
+
for (let i = -1; i <= 1; i++)
|
|
219
|
+
ringOffsets.push([i, -2], [i, 2], [-2, i], [2, i]);
|
|
220
|
+
serv.onBlockInteraction('end_portal_frame', async ({ block, player }) => {
|
|
221
|
+
if (player.heldItem?.name !== 'ender_eye')
|
|
222
|
+
return false;
|
|
223
|
+
const props = block.getProperties?.() ?? {};
|
|
224
|
+
if (String(props.eye) === 'true')
|
|
225
|
+
return false;
|
|
226
|
+
const world = player.world;
|
|
227
|
+
await serv.setBlock(world, block.position, Block.fromProperties('end_portal_frame', { ...props, eye: true }, 0).stateId);
|
|
228
|
+
// look for a complete ring of eyes around any centre within reach and fill its 3x3 interior
|
|
229
|
+
for (let cx = block.position.x - 3; cx <= block.position.x + 3; cx++) {
|
|
230
|
+
for (let cz = block.position.z - 3; cz <= block.position.z + 3; cz++) {
|
|
231
|
+
let complete = true;
|
|
232
|
+
for (const [dx, dz] of ringOffsets) {
|
|
233
|
+
const b = await world.getBlock(new vec3_1.Vec3(cx + dx, block.position.y, cz + dz));
|
|
234
|
+
if (b.type !== frame.id || String(b.getProperties?.().eye) !== 'true') {
|
|
235
|
+
complete = false;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (!complete)
|
|
240
|
+
continue;
|
|
241
|
+
for (let dx = -1; dx <= 1; dx++)
|
|
242
|
+
for (let dz = -1; dz <= 1; dz++)
|
|
243
|
+
await serv.setBlockType(world, new vec3_1.Vec3(cx + dx, block.position.y, cz + dz), mcData.blocksByName.end_portal.id);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return true;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
71
250
|
serv.commands.add({
|
|
72
251
|
base: 'portal',
|
|
73
252
|
info: 'Create a portal frame',
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RecipeSpec } from 'minecraft-worldgen/dist/recipe/types';
|
|
2
|
+
export declare const server: (serv: Server, options: Options) => void;
|
|
3
|
+
export declare const player: (player: Player, serv: Server) => void;
|
|
4
|
+
declare global {
|
|
5
|
+
interface Server {
|
|
6
|
+
recipes: {
|
|
7
|
+
apply: (name: string, spec: RecipeSpec, also?: Player) => Promise<string>;
|
|
8
|
+
specs: Record<string, RecipeSpec>;
|
|
9
|
+
state: (name: string) => any;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|