@zardoy/flying-squid 0.0.138 → 0.0.140
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/dist/lib/blockArgument.d.ts +46 -0
- package/dist/lib/blockArgument.js +126 -0
- package/dist/lib/blockArgument.test.d.ts +1 -0
- package/dist/lib/blockArgument.test.js +65 -0
- package/dist/lib/command.js +3 -0
- package/dist/lib/commandArgs.d.ts +5 -0
- package/dist/lib/commandArgs.js +28 -0
- package/dist/lib/containers/gameData.d.ts +2 -0
- package/dist/lib/containers/gameData.js +18 -0
- package/dist/lib/modules/blocks.js +114 -49
- package/dist/lib/modules/blocks.test.d.ts +1 -0
- package/dist/lib/modules/blocks.test.js +91 -0
- package/dist/lib/modules/commands.js +8 -0
- package/dist/lib/modules/containers.js +1 -0
- package/dist/lib/modules/daycycle.js +1 -1
- package/dist/lib/modules/endFight.js +1 -0
- package/dist/lib/modules/experience.js +1 -0
- package/dist/lib/modules/gamerules.js +1 -0
- package/dist/lib/modules/moderation.js +8 -0
- package/dist/lib/modules/particle.js +1 -0
- package/dist/lib/modules/physics.js +1 -0
- package/dist/lib/modules/players.js +4 -1
- package/dist/lib/modules/portal.js +1 -0
- package/dist/lib/modules/pvp.js +1 -1
- package/dist/lib/modules/recipes.js +1 -0
- package/dist/lib/modules/settings.js +17 -0
- package/dist/lib/modules/sound.js +2 -0
- package/dist/lib/modules/spawn.js +2 -0
- package/dist/lib/modules/tabComplete.d.ts +26 -6
- package/dist/lib/modules/tabComplete.js +123 -110
- package/dist/lib/modules/tabComplete.test.d.ts +1 -0
- package/dist/lib/modules/tabComplete.test.js +76 -0
- package/dist/lib/modules/tp.js +1 -0
- package/dist/lib/modules/warps.js +2 -0
- package/dist/lib/modules/weather.js +1 -0
- package/dist/lib/modules/world.d.ts +5 -0
- package/dist/lib/modules/world.js +4 -0
- package/dist/lib/modules/worldManager.js +2 -0
- package/dist/lib/spawnSearch.d.ts +20 -0
- package/dist/lib/spawnSearch.js +67 -0
- package/dist/lib/worldGenerations/noise.d.ts +4 -0
- package/dist/lib/worldGenerations/noise.js +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,76 @@
|
|
|
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 events_1 = require("events");
|
|
8
|
+
const minecraft_data_1 = __importDefault(require("minecraft-data"));
|
|
9
|
+
const command_1 = __importDefault(require("../command"));
|
|
10
|
+
const tabComplete_1 = require("./tabComplete");
|
|
11
|
+
const VERSION = '1.20.1';
|
|
12
|
+
function setup({ op = true } = {}) {
|
|
13
|
+
const commands = new command_1.default({});
|
|
14
|
+
commands.add({ base: 'setblock', info: '', usage: '', op: true, tab: ['blockX', 'blockY', 'blockZ', 'block', 'setblockMode'], action: () => { } });
|
|
15
|
+
commands.add({ base: 'teleport', aliases: ['/tp'], info: '', usage: '', op: true, tab: ['playerOrX', 'tpArg1', 'tpArg2', 'blockZ'], action: () => { } });
|
|
16
|
+
commands.add({ base: 'mv', info: '', usage: '', op: true, tab: ['mvAction', 'mvTarget', 'mvEnvironment'], action: () => { } });
|
|
17
|
+
commands.add({ base: 'version', info: '', usage: '', tab: [], action: () => { } });
|
|
18
|
+
commands.add({ base: 'gamemode', aliases: ['/gm'], info: '', usage: '', op: true, tab: ['gamemode', 'player'], action: () => { } });
|
|
19
|
+
const client = new events_1.EventEmitter();
|
|
20
|
+
const written = [];
|
|
21
|
+
client.write = (name, data) => written.push({ name, data });
|
|
22
|
+
const player = { username: 'Steve', op, _client: client };
|
|
23
|
+
const serv = {
|
|
24
|
+
commands,
|
|
25
|
+
mcData: (0, minecraft_data_1.default)(VERSION),
|
|
26
|
+
players: [player],
|
|
27
|
+
worlds: { overworld: {}, nether: {}, flat: {} },
|
|
28
|
+
gamerules: {},
|
|
29
|
+
supportFeature: (f) => f === 'tabCompleteHasAToolTip'
|
|
30
|
+
};
|
|
31
|
+
(0, tabComplete_1.server)(serv);
|
|
32
|
+
(0, tabComplete_1.player)(player, serv);
|
|
33
|
+
const complete = (text, lookedAtBlock = null) => {
|
|
34
|
+
written.length = 0;
|
|
35
|
+
client.emit('tab_complete', { text, lookedAtBlock });
|
|
36
|
+
(0, vitest_1.expect)(written, `one answer for "${text}"`).toHaveLength(1);
|
|
37
|
+
return written[0].data.matches.map((m) => m.match ?? m);
|
|
38
|
+
};
|
|
39
|
+
return { complete };
|
|
40
|
+
}
|
|
41
|
+
(0, vitest_1.test)('command names include aliases and hide op commands from non ops', () => {
|
|
42
|
+
const { complete } = setup();
|
|
43
|
+
(0, vitest_1.expect)(complete('/t')).toEqual(vitest_1.expect.arrayContaining(['/teleport', '/tp']));
|
|
44
|
+
(0, vitest_1.expect)(complete('/g')).toEqual(vitest_1.expect.arrayContaining(['/gamemode', '/gm']));
|
|
45
|
+
(0, vitest_1.expect)(setup({ op: false }).complete('/')).toEqual(['/version']);
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.test)('every argument gets an answer, even with nothing to suggest (no client timeout)', () => {
|
|
48
|
+
const { complete } = setup();
|
|
49
|
+
(0, vitest_1.expect)(complete('/version ')).toEqual([]);
|
|
50
|
+
(0, vitest_1.expect)(complete('/setblock 1 2 3 stone replace extra ')).toEqual([]);
|
|
51
|
+
(0, vitest_1.expect)(complete('/nosuchcommand ')).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
(0, vitest_1.test)('setblock: coordinates, block names, block states, mode', () => {
|
|
54
|
+
const { complete } = setup();
|
|
55
|
+
(0, vitest_1.expect)(complete('/setblock ', { x: 5, y: 64, z: -3 })).toEqual(['5', '~']);
|
|
56
|
+
(0, vitest_1.expect)(complete('/setblock 5 ', { x: 5, y: 64, z: -3 })).toEqual(['64', '~']);
|
|
57
|
+
(0, vitest_1.expect)(complete('/setblock 5 64 -3 lad')).toEqual(['ladder']);
|
|
58
|
+
(0, vitest_1.expect)(complete('/setblock 5 64 -3 ladder[')).toEqual(['ladder[facing=', 'ladder[waterlogged=']);
|
|
59
|
+
(0, vitest_1.expect)(complete('/setblock 5 64 -3 ladder[facing=w')).toEqual(['ladder[facing=west,', 'ladder[facing=west]']);
|
|
60
|
+
(0, vitest_1.expect)(complete('/setblock 5 64 -3 ladder[facing=west] ')).toEqual(['replace', 'keep', 'destroy']);
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.test)('aliases complete like their command (/tp, /gm)', () => {
|
|
63
|
+
const { complete } = setup();
|
|
64
|
+
(0, vitest_1.expect)(complete('/tp ')).toEqual(['Steve', '~']);
|
|
65
|
+
(0, vitest_1.expect)(complete('/tp Steve ')).toEqual(['Steve', '~']);
|
|
66
|
+
(0, vitest_1.expect)(complete('/tp 1 ')).toEqual(['~']);
|
|
67
|
+
(0, vitest_1.expect)(complete('/gm ')).toEqual(['survival', 'creative', 'adventure', 'spectator']);
|
|
68
|
+
(0, vitest_1.expect)(complete('/gm creative ')).toEqual(['Steve']);
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.test)('/mv: action, then worlds or environments', () => {
|
|
71
|
+
const { complete } = setup();
|
|
72
|
+
(0, vitest_1.expect)(complete('/mv ')).toEqual(['create', 'list', 'info', 'who', 'tp', 'remove']);
|
|
73
|
+
(0, vitest_1.expect)(complete('/mv tp ')).toEqual(['overworld', 'nether', 'flat']);
|
|
74
|
+
(0, vitest_1.expect)(complete('/mv create ')).toEqual([]);
|
|
75
|
+
(0, vitest_1.expect)(complete('/mv create skyblock ')).toEqual(['normal', 'nether', 'end']);
|
|
76
|
+
});
|
package/dist/lib/modules/tp.js
CHANGED
|
@@ -12,6 +12,7 @@ const server = (serv) => {
|
|
|
12
12
|
aliases: ['/tp'],
|
|
13
13
|
info: 'to teleport a player',
|
|
14
14
|
usage: '/teleport [target player] <destination player or x> [y] [z]',
|
|
15
|
+
tab: ['playerOrX', 'tpArg1', 'tpArg2', 'blockZ'],
|
|
15
16
|
op: true,
|
|
16
17
|
parse(str) {
|
|
17
18
|
return str.match(/^(((.* )?~?-?\d* ~?-?\d* ~?-?\d*)|(.+ .+))$/) ? str.split(' ') : false;
|
|
@@ -104,6 +104,7 @@ const server = async function (serv, options) {
|
|
|
104
104
|
base: 'home',
|
|
105
105
|
info: 'Teleport to your home',
|
|
106
106
|
usage: '/home',
|
|
107
|
+
tab: [],
|
|
107
108
|
op: false, // todo
|
|
108
109
|
commandBlock: false,
|
|
109
110
|
async action({}, { player }) {
|
|
@@ -114,6 +115,7 @@ const server = async function (serv, options) {
|
|
|
114
115
|
base: 'sethome',
|
|
115
116
|
info: 'Set your home',
|
|
116
117
|
usage: '/sethome',
|
|
118
|
+
tab: [],
|
|
117
119
|
op: false, // todo
|
|
118
120
|
commandBlock: false,
|
|
119
121
|
async action({}, { player }) {
|
|
@@ -21,6 +21,11 @@ export interface WorldSpec {
|
|
|
21
21
|
export interface CustomWorld extends World {
|
|
22
22
|
/** block positions (x, z) of the strongholds of this world, `limit` = first rings only (noise generator, overworld) */
|
|
23
23
|
strongholds?: (limit?: number) => Promise<Array<[number, number]>>;
|
|
24
|
+
/** block x/z of the world spawn from the climate (noise generator, overworld; vanilla's spawn chunk) */
|
|
25
|
+
spawnPosition?: () => Promise<{
|
|
26
|
+
x: number;
|
|
27
|
+
z: number;
|
|
28
|
+
} | undefined>;
|
|
24
29
|
/** releases the chunk generator (worker side caches) */
|
|
25
30
|
disposeGenerator?: () => Promise<void>;
|
|
26
31
|
blockEntityData: Record<string, any>;
|
|
@@ -225,6 +225,7 @@ const server = async function (serv, options) {
|
|
|
225
225
|
serv.overworld.seed = serv.seed = generationOptions.seed;
|
|
226
226
|
serv.overworld.generatorName = generation.name;
|
|
227
227
|
serv.overworld.strongholds = originalGenerator.strongholds;
|
|
228
|
+
serv.overworld.spawnPosition = originalGenerator.spawnPosition;
|
|
228
229
|
patchWorld(serv.overworld);
|
|
229
230
|
dedupeGetColumn(serv.overworld);
|
|
230
231
|
// ---- world registry (Multiverse-style): any number of worlds; each has an environment (= client dimension type) and a generator
|
|
@@ -332,6 +333,7 @@ const server = async function (serv, options) {
|
|
|
332
333
|
world['min_y'] = opts.minY;
|
|
333
334
|
world.disposeGenerator = generator?.dispose;
|
|
334
335
|
world.strongholds = generator?.strongholds;
|
|
336
|
+
world.spawnPosition = generator?.spawnPosition;
|
|
335
337
|
world['height'] = opts.worldHeight;
|
|
336
338
|
dedupeGetColumn(world);
|
|
337
339
|
world.seed = worldSeed;
|
|
@@ -491,6 +493,7 @@ const server = async function (serv, options) {
|
|
|
491
493
|
base: 'changeworld',
|
|
492
494
|
info: 'to change world',
|
|
493
495
|
usage: '/changeworld <world> (overworld | nether | end | any world created with /mv create)',
|
|
496
|
+
tab: ['world'],
|
|
494
497
|
onlyPlayer: true,
|
|
495
498
|
op: true,
|
|
496
499
|
action(name, ctx) {
|
|
@@ -504,6 +507,7 @@ const server = async function (serv, options) {
|
|
|
504
507
|
base: 'seed',
|
|
505
508
|
info: 'Get world\'s seed',
|
|
506
509
|
usage: '/seed',
|
|
510
|
+
tab: [],
|
|
507
511
|
action(data, ctx) {
|
|
508
512
|
const world = ctx.player?.world ?? serv.overworld;
|
|
509
513
|
// todo need concept of command output
|
|
@@ -95,6 +95,7 @@ const server = function (serv) {
|
|
|
95
95
|
base: 'mv',
|
|
96
96
|
info: 'Multiverse-style world management',
|
|
97
97
|
usage: '/mv <create|list|info|who|tp|remove> ...',
|
|
98
|
+
tab: ['mvAction', 'mvTarget', 'mvEnvironment'],
|
|
98
99
|
op: true,
|
|
99
100
|
parse: (str) => tokenize(str),
|
|
100
101
|
async action(tokens, ctx) {
|
|
@@ -110,6 +111,7 @@ const server = function (serv) {
|
|
|
110
111
|
base: 'mv' + sub,
|
|
111
112
|
info: `/mv ${sub}`,
|
|
112
113
|
usage: `/mv${sub} ...`,
|
|
114
|
+
tab: sub === 'create' ? ['text', 'worldEnvironment'] : sub === 'list' ? [] : ['world'],
|
|
113
115
|
op: true,
|
|
114
116
|
parse: (str) => tokenize(str),
|
|
115
117
|
action: async (tokens, ctx) => await actions[sub](tokens, ctx)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
2
|
+
type ColumnBlock = {
|
|
3
|
+
name: string;
|
|
4
|
+
boundingBox?: string;
|
|
5
|
+
shapes?: number[][];
|
|
6
|
+
getProperties?: () => Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type SpawnColumn = {
|
|
9
|
+
getBlock: (pos: Vec3) => ColumnBlock;
|
|
10
|
+
};
|
|
11
|
+
/** getLevelRespawnPos for a dimension without a ceiling: the feet position above the column's top full block, null when the top is a fluid */
|
|
12
|
+
export declare function respawnPosInColumn(column: SpawnColumn, x: number, z: number, minY: number, maxY: number): Vec3 | null;
|
|
13
|
+
/** chunk offsets of vanilla's spawn search spiral: (0, 0) first, then outwards, within -5..5 */
|
|
14
|
+
export declare function spawnChunkSpiral(): Array<[number, number]>;
|
|
15
|
+
/** first valid surface spawn around the block position `origin` (x, z), null when no column in 11 x 11 chunks has a dry top */
|
|
16
|
+
export declare function findSurfaceSpawn(getColumn: (chunkX: number, chunkZ: number) => Promise<SpawnColumn>, origin: {
|
|
17
|
+
x: number;
|
|
18
|
+
z: number;
|
|
19
|
+
}, minY: number, maxY: number): Promise<Vec3 | null>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.respawnPosInColumn = respawnPosInColumn;
|
|
4
|
+
exports.spawnChunkSpiral = spawnChunkSpiral;
|
|
5
|
+
exports.findSurfaceSpawn = findSurfaceSpawn;
|
|
6
|
+
const vec3_1 = require("vec3");
|
|
7
|
+
/**
|
|
8
|
+
* World spawn on the surface like vanilla (MinecraftServer.setInitialSpawn + PlayerSpawnFinder.getSpawnPosInChunk / getLevelRespawnPos):
|
|
9
|
+
* search the spawn chunk and then the chunks around it (spiral, 11 x 11 chunks) for the first column whose top is dry, and spawn on its
|
|
10
|
+
* top-most block with a full top face. Starting from the top of the column means never a cave; a column topped by water is skipped.
|
|
11
|
+
*/
|
|
12
|
+
/** blocks that hold a fluid (vanilla: a non-empty FluidState) */
|
|
13
|
+
const FLUID_BLOCKS = new Set(['water', 'lava', 'bubble_column', 'kelp', 'kelp_plant', 'seagrass', 'tall_seagrass']);
|
|
14
|
+
const hasFluid = (block) => FLUID_BLOCKS.has(block.name) || block.getProperties?.().waterlogged === true;
|
|
15
|
+
/** Block.isFaceFull(collisionShape, UP): one collision box covers the whole top face */
|
|
16
|
+
const hasFullTopFace = (block) => block.boundingBox === 'block' && (block.shapes ?? []).some(([x0, , z0, x1, y1, z1]) => x0 <= 0 && z0 <= 0 && x1 >= 1 && z1 >= 1 && y1 >= 1);
|
|
17
|
+
/** getLevelRespawnPos for a dimension without a ceiling: the feet position above the column's top full block, null when the top is a fluid */
|
|
18
|
+
function respawnPosInColumn(column, x, z, minY, maxY) {
|
|
19
|
+
const local = new vec3_1.Vec3(x & 15, 0, z & 15);
|
|
20
|
+
for (let y = maxY - 1; y >= minY; y--) {
|
|
21
|
+
local.y = y;
|
|
22
|
+
const block = column.getBlock(local);
|
|
23
|
+
if (hasFluid(block))
|
|
24
|
+
return null;
|
|
25
|
+
if (hasFullTopFace(block))
|
|
26
|
+
return new vec3_1.Vec3(x, y + 1, z);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** chunk offsets of vanilla's spawn search spiral: (0, 0) first, then outwards, within -5..5 */
|
|
31
|
+
function spawnChunkSpiral() {
|
|
32
|
+
const out = [];
|
|
33
|
+
let x = 0;
|
|
34
|
+
let z = 0;
|
|
35
|
+
let dx = 0;
|
|
36
|
+
let dz = -1;
|
|
37
|
+
for (let i = 0; i < 121; i++) {
|
|
38
|
+
if (x >= -5 && x <= 5 && z >= -5 && z <= 5)
|
|
39
|
+
out.push([x, z]);
|
|
40
|
+
if (x === z || (x < 0 && x === -z) || (x > 0 && x === 1 - z)) {
|
|
41
|
+
const t = dx;
|
|
42
|
+
dx = -dz;
|
|
43
|
+
dz = t;
|
|
44
|
+
}
|
|
45
|
+
x += dx;
|
|
46
|
+
z += dz;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** first valid surface spawn around the block position `origin` (x, z), null when no column in 11 x 11 chunks has a dry top */
|
|
51
|
+
async function findSurfaceSpawn(getColumn, origin, minY, maxY) {
|
|
52
|
+
const ocx = Math.floor(origin.x / 16);
|
|
53
|
+
const ocz = Math.floor(origin.z / 16);
|
|
54
|
+
for (const [dx, dz] of spawnChunkSpiral()) {
|
|
55
|
+
const column = await getColumn(ocx + dx, ocz + dz);
|
|
56
|
+
const x0 = (ocx + dx) * 16;
|
|
57
|
+
const z0 = (ocz + dz) * 16;
|
|
58
|
+
for (let x = x0; x < x0 + 16; x++) {
|
|
59
|
+
for (let z = z0; z < z0 + 16; z++) {
|
|
60
|
+
const pos = respawnPosInColumn(column, x, z, minY, maxY);
|
|
61
|
+
if (pos)
|
|
62
|
+
return pos;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
declare function generation(options?: any): {
|
|
19
19
|
(chunkX: number, chunkZ: number): Promise<any>;
|
|
20
20
|
strongholds(limit?: number): Promise<Array<[number, number]>>;
|
|
21
|
+
spawnPosition(): Promise<{
|
|
22
|
+
x: number;
|
|
23
|
+
z: number;
|
|
24
|
+
} | undefined>;
|
|
21
25
|
dispose(): Promise<void>;
|
|
22
26
|
};
|
|
23
27
|
export = generation;
|
|
@@ -301,6 +301,13 @@ function generation(options = {}) {
|
|
|
301
301
|
/** releases the worker generator (and the pool when it was the last user) */
|
|
302
302
|
/** block positions (x, z) of the strongholds (eyes of ender point to them); `limit`: only the first rings (nearest the origin first) */
|
|
303
303
|
generateChunk.strongholds = async (limit) => (dimension === 'overworld' ? (await getSource()).strongholds(limit) : []);
|
|
304
|
+
/** block x/z of the world spawn from the climate (vanilla's spawn chunk); undefined outside the overworld or with an older minecraft-worldgen */
|
|
305
|
+
generateChunk.spawnPosition = async () => {
|
|
306
|
+
if (dimension !== 'overworld')
|
|
307
|
+
return undefined;
|
|
308
|
+
const source = await getSource();
|
|
309
|
+
return typeof source.spawnPosition === 'function' ? source.spawnPosition() : undefined;
|
|
310
|
+
};
|
|
304
311
|
generateChunk.dispose = async () => { if (sourceP) {
|
|
305
312
|
const p = sourceP;
|
|
306
313
|
sourceP = undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zardoy/flying-squid",
|
|
3
3
|
"description": "A minecraft server written in TS",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.140",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"bin": "dist/app.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"flatmap": "^0.0.3",
|
|
29
29
|
"long": "^5.1.0",
|
|
30
30
|
"mc-bridge": "^0.1.1",
|
|
31
|
-
"minecraft-worldgen": "^0.1.
|
|
31
|
+
"minecraft-worldgen": "^0.1.7",
|
|
32
32
|
"minecraft-data": "^3.95.0",
|
|
33
33
|
"minecraft-protocol": "^1.60.1",
|
|
34
34
|
"mkdirp": "^2.1.3",
|