@zardoy/flying-squid 0.0.119 → 0.0.121

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.
@@ -46,42 +46,6 @@ const server = function (serv, { version }) {
46
46
  setTimeout(() => { throw err; }, 0);
47
47
  }
48
48
  };
49
- serv.commands.add({
50
- base: 'title',
51
- info: 'show title',
52
- op: true,
53
- usage: '/title <targets> (title|subtitle|actionBar) <title>',
54
- parse(str) {
55
- const match = str.match(/([A-Za-z0-9]+( [A-Za-z0-9]+)+) ^(title|subtitle|actionBar)$ \{[^}]*\}/i);
56
- if (!match)
57
- return false;
58
- const players = str.split(/^(title|subtitle|actionBar)$/)[0];
59
- const level = str.match(/^(title|subtitle|actionBar)$/);
60
- const text = str.split(/^(title|subtitle|actionBar)$/)[-1];
61
- if (!players || !level || !text)
62
- return false;
63
- return { playersNamesAndTargetValues: players, level: level[0], text: text };
64
- },
65
- action(data, ctx) {
66
- const selectorString = ctx.player ? ctx.player.selectorString : serv.selectorString;
67
- const isPlayer = (entity) => entity.type === 'player';
68
- const players = selectorString(data.playersNamesAndTargetValues).filter(isPlayer);
69
- switch (data.level) {
70
- case 'title':
71
- serv._writeArray("Title", { "set_title_text": data.text }, players);
72
- break;
73
- case 'subtitle':
74
- serv._writeArray("Title", { "set_title_subtitle": data.text }, players);
75
- break;
76
- case 'actionBar':
77
- serv._writeArray("Title", { "action_bar": data.text }, players);
78
- break;
79
- default:
80
- return "Something went wrong. Try again.";
81
- }
82
- return "Title or action bar should appear";
83
- }
84
- });
85
49
  serv.commands.add({
86
50
  base: 'ping',
87
51
  info: 'to pong!',
@@ -263,10 +263,14 @@ const server = function (serv, { version }) {
263
263
  if (players.length < 1)
264
264
  throw new user_error_1.default('Player not found');
265
265
  const action = mode.toLowerCase();
266
- if (action === 'clear' || action === 'reset') {
266
+ if (action === 'clear') {
267
267
  players.forEach(player => serv.clearTitle(player));
268
268
  return 'Title cleared';
269
269
  }
270
+ if (action === 'reset') {
271
+ players.forEach(player => serv.resetTitle(player));
272
+ return 'Title reset';
273
+ }
270
274
  if (action === 'times') {
271
275
  const [fadeInRaw, stayRaw, fadeOutRaw] = rest.split(/\s+/);
272
276
  const fadeIn = parseInt(fadeInRaw, 10);
@@ -287,7 +291,7 @@ const server = function (serv, { version }) {
287
291
  players.forEach(player => serv.sendTitle(player, '', rest));
288
292
  return 'Subtitle sent';
289
293
  }
290
- if (action === 'actionbar' || action === 'actionBar') {
294
+ if (action === 'actionbar') {
291
295
  players.forEach(player => serv.sendActionBar(player, rest));
292
296
  return 'Action bar sent';
293
297
  }
@@ -5,5 +5,6 @@ declare global {
5
5
  setTitleTimes: (player: Player, fadeIn?: number, stay?: number, fadeOut?: number) => void;
6
6
  sendActionBar: (player: Player, message: string) => void;
7
7
  clearTitle: (player: Player) => void;
8
+ resetTitle: (player: Player) => void;
8
9
  }
9
10
  }
@@ -24,19 +24,21 @@ const server = function (serv, options) {
24
24
  });
25
25
  }
26
26
  else {
27
- // Pre-1.17 uses single title packet
27
+ player._client.write('title', {
28
+ action: 3,
29
+ fadeIn,
30
+ stay,
31
+ fadeOut
32
+ });
28
33
  if (title) {
29
34
  player._client.write('title', {
30
- action: 0, // Set title
31
- text: JSON.stringify({ text: title }),
32
- fadeIn,
33
- stay,
34
- fadeOut
35
+ action: 0,
36
+ text: JSON.stringify({ text: title })
35
37
  });
36
38
  }
37
39
  if (subtitle) {
38
40
  player._client.write('title', {
39
- action: 1, // Set subtitle
41
+ action: 1,
40
42
  text: JSON.stringify({ text: subtitle })
41
43
  });
42
44
  }
@@ -52,7 +54,7 @@ const server = function (serv, options) {
52
54
  }
53
55
  else {
54
56
  player._client.write('title', {
55
- action: 2, // Set times
57
+ action: 3,
56
58
  fadeIn,
57
59
  stay,
58
60
  fadeOut
@@ -75,6 +77,18 @@ const server = function (serv, options) {
75
77
  }
76
78
  };
77
79
  serv.clearTitle = (player) => {
80
+ if (supportsNewTitle) {
81
+ player._client.write('clear_titles', {
82
+ reset: false
83
+ });
84
+ }
85
+ else {
86
+ player._client.write('title', {
87
+ action: 4
88
+ });
89
+ }
90
+ };
91
+ serv.resetTitle = (player) => {
78
92
  if (supportsNewTitle) {
79
93
  player._client.write('clear_titles', {
80
94
  reset: true
@@ -82,7 +96,7 @@ const server = function (serv, options) {
82
96
  }
83
97
  else {
84
98
  player._client.write('title', {
85
- action: 4 // Clear
99
+ action: 5
86
100
  });
87
101
  }
88
102
  };
@@ -46,6 +46,7 @@ const playerDat = __importStar(require("../playerDat"));
46
46
  const prismarine_world_1 = __importDefault(require("prismarine-world"));
47
47
  const prismarine_registry_1 = __importDefault(require("prismarine-registry"));
48
48
  const generations_1 = __importDefault(require("../generations"));
49
+ const template_1 = require("../worldGenerations/template");
49
50
  const vec3_1 = require("vec3");
50
51
  const utils_1 = require("../../utils");
51
52
  const levelDat_1 = require("../../levelDat");
@@ -142,7 +143,8 @@ const server = async function (serv, options) {
142
143
  ...generation.options,
143
144
  seed,
144
145
  version,
145
- getRenamedData: blockRenames_1.getRenamedData
146
+ getRenamedData: blockRenames_1.getRenamedData,
147
+ baseY: options.baseY
146
148
  };
147
149
  serv.emit('seed', generationOptions.seed);
148
150
  const patchWorld = (world) => {
@@ -150,7 +152,12 @@ const server = async function (serv, options) {
150
152
  world['height'] = generation.options.worldHeight;
151
153
  };
152
154
  const generationModule = generations_1.default[generation.name] ? generations_1.default[generation.name] : require(generation.name);
153
- const originalGenerator = generationModule(generationOptions);
155
+ const genOpts = generation.options;
156
+ const originalGenerator = typeof options.chunkTemplate === 'string'
157
+ ? (0, template_1.makeTemplateGenerator)(options.chunkTemplate, generationOptions, options.blockMap)
158
+ : typeof genOpts.chunkTemplate === 'string'
159
+ ? (0, template_1.makeTemplateGenerator)(genOpts.chunkTemplate, generationOptions, genOpts.blockMap)
160
+ : generationModule(generationOptions);
154
161
  serv.overworldOriginalGenerator = originalGenerator;
155
162
  serv.overworld = new World((chunkX, chunkZ) => {
156
163
  return serv.overworldGeneratorOverride ? serv.overworldGeneratorOverride(chunkX, chunkZ, generationOptions) : originalGenerator(chunkX, chunkZ, generationOptions);
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Default single-character → Minecraft block-name mapping used by the
3
+ * chunk-template generator. Users can override any entry (or add new ones)
4
+ * via `generation.options.blockMap`.
5
+ */
6
+ export declare const DEFAULT_BLOCK_MAP: Record<string, string>;
7
+ /**
8
+ * Parses a block-map override string into a `Record<string, string>`.
9
+ *
10
+ * Format: comma-separated `CHAR=block_name` pairs (whitespace around
11
+ * `=` and `,` is ignored).
12
+ *
13
+ * @example
14
+ * parseBlockMap("C=cobblestone, G=glass_pane, X=diamond_block")
15
+ * // → { C: 'cobblestone', G: 'glass_pane', X: 'diamond_block' }
16
+ */
17
+ export declare function parseBlockMap(s: string): Record<string, string>;
18
+ /**
19
+ * Expands a run-length-encoded row string.
20
+ * "3B" → "BBB", "7A" → "AAAAAAA", bare "C" → "C".
21
+ */
22
+ export declare function decodeRLE(s: string): string;
23
+ export interface LayerData {
24
+ /**
25
+ * 0-based floor index as written in the template (Y0, Y1, …).
26
+ * Absolute world Y = baseY + yIndex.
27
+ */
28
+ yIndex: number;
29
+ /** Fully decoded (RLE-expanded) row strings, one per Z offset */
30
+ rows: string[];
31
+ }
32
+ /**
33
+ * Parses a chunk-template string into an array of LayerData objects.
34
+ *
35
+ * Strict format:
36
+ * Y<n>: row0 | row1 | … | rowN-1 Y<n>: …
37
+ *
38
+ * - Layers are delimited by the next `Y<digits>:` token (no other separator).
39
+ * - `<n>` is a 0-based floor index; the chunk generator maps it to world Y
40
+ * via `baseY + n` (default baseY = 64).
41
+ * - Rows are separated by `|`. Leading/trailing whitespace around each row
42
+ * is stripped before RLE decoding.
43
+ * - Run-length encoding: `3C` → `CCC`, `7A` → `AAAAAAA`, bare `C` → `C`.
44
+ * - `A` (or a space) represents air and is never written to the chunk.
45
+ * - Width and depth are inferred from the decoded rows (no explicit header).
46
+ *
47
+ * @example
48
+ * "Y0: 16C | 16C Y1: C14AC | C14AC"
49
+ */
50
+ export declare function parseTemplate(templateStr: string): LayerData[];
51
+ /**
52
+ * Returns a `(chunkX, chunkZ) => Chunk` generator that paints the decoded
53
+ * template structure into the world starting at (0, Y, 0).
54
+ *
55
+ * Chunks that do not overlap the structure are still returned but contain
56
+ * only air + full sky-light (compatible with every generator contract).
57
+ *
58
+ * @param templateStr Encoded template string (see parseTemplate).
59
+ * @param options generationOptions forwarded from world.ts
60
+ * (must include `version`, and may include `minY` /
61
+ * `worldHeight`).
62
+ * @param userBlockMap Optional extra / override mappings on top of
63
+ * DEFAULT_BLOCK_MAP. char → Minecraft block name.
64
+ */
65
+ export declare function makeTemplateGenerator(templateStr: string, options: any, userBlockMap?: Record<string, string> | string): (chunkX: number, chunkZ: number) => any;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_BLOCK_MAP = void 0;
4
+ exports.parseBlockMap = parseBlockMap;
5
+ exports.decodeRLE = decodeRLE;
6
+ exports.parseTemplate = parseTemplate;
7
+ exports.makeTemplateGenerator = makeTemplateGenerator;
8
+ const vec3_1 = require("vec3");
9
+ /**
10
+ * Default single-character → Minecraft block-name mapping used by the
11
+ * chunk-template generator. Users can override any entry (or add new ones)
12
+ * via `generation.options.blockMap`.
13
+ */
14
+ exports.DEFAULT_BLOCK_MAP = {
15
+ // 'A' is always air (skip – never written to the chunk)
16
+ C: 'cobblestone',
17
+ M: 'mossy_cobblestone',
18
+ G: 'glass',
19
+ R: 'red_wool',
20
+ D: 'dark_oak_planks',
21
+ I: 'iron_block',
22
+ S: 'stone',
23
+ B: 'bricks',
24
+ W: 'oak_planks',
25
+ L: 'lapis_block',
26
+ O: 'obsidian',
27
+ P: 'oak_planks',
28
+ Y: 'gold_block',
29
+ N: 'netherrack',
30
+ T: 'stone_bricks',
31
+ F: 'oak_log',
32
+ E: 'emerald_block',
33
+ X: 'tnt',
34
+ Z: 'dirt',
35
+ H: 'sandstone',
36
+ J: 'glass_pane',
37
+ K: 'gravel',
38
+ Q: 'quartz_block',
39
+ U: 'sea_lantern',
40
+ V: 'stone_slab',
41
+ };
42
+ // ---------------------------------------------------------------------------
43
+ // Block-map parser
44
+ // ---------------------------------------------------------------------------
45
+ /**
46
+ * Parses a block-map override string into a `Record<string, string>`.
47
+ *
48
+ * Format: comma-separated `CHAR=block_name` pairs (whitespace around
49
+ * `=` and `,` is ignored).
50
+ *
51
+ * @example
52
+ * parseBlockMap("C=cobblestone, G=glass_pane, X=diamond_block")
53
+ * // → { C: 'cobblestone', G: 'glass_pane', X: 'diamond_block' }
54
+ */
55
+ function parseBlockMap(s) {
56
+ const result = {};
57
+ for (const entry of s.split(',')) {
58
+ const eq = entry.indexOf('=');
59
+ if (eq === -1)
60
+ continue;
61
+ const char = entry.slice(0, eq).trim();
62
+ const name = entry.slice(eq + 1).trim();
63
+ if (char && name)
64
+ result[char] = name;
65
+ }
66
+ return result;
67
+ }
68
+ // ---------------------------------------------------------------------------
69
+ // RLE decoder
70
+ // ---------------------------------------------------------------------------
71
+ /**
72
+ * Expands a run-length-encoded row string.
73
+ * "3B" → "BBB", "7A" → "AAAAAAA", bare "C" → "C".
74
+ */
75
+ function decodeRLE(s) {
76
+ let result = '';
77
+ let i = 0;
78
+ while (i < s.length) {
79
+ let numStr = '';
80
+ while (i < s.length && s[i] >= '0' && s[i] <= '9') {
81
+ numStr += s[i++];
82
+ }
83
+ if (i < s.length) {
84
+ result += s[i++].repeat(numStr ? parseInt(numStr, 10) : 1);
85
+ }
86
+ }
87
+ return result;
88
+ }
89
+ /**
90
+ * Parses a chunk-template string into an array of LayerData objects.
91
+ *
92
+ * Strict format:
93
+ * Y<n>: row0 | row1 | … | rowN-1 Y<n>: …
94
+ *
95
+ * - Layers are delimited by the next `Y<digits>:` token (no other separator).
96
+ * - `<n>` is a 0-based floor index; the chunk generator maps it to world Y
97
+ * via `baseY + n` (default baseY = 64).
98
+ * - Rows are separated by `|`. Leading/trailing whitespace around each row
99
+ * is stripped before RLE decoding.
100
+ * - Run-length encoding: `3C` → `CCC`, `7A` → `AAAAAAA`, bare `C` → `C`.
101
+ * - `A` (or a space) represents air and is never written to the chunk.
102
+ * - Width and depth are inferred from the decoded rows (no explicit header).
103
+ *
104
+ * @example
105
+ * "Y0: 16C | 16C Y1: C14AC | C14AC"
106
+ */
107
+ function parseTemplate(templateStr) {
108
+ const layers = [];
109
+ // Each match captures: [1] yIndex, [2] the rows blob up to the next Y<n>:
110
+ const re = /Y(\d+):\s*([\s\S]*?)(?=\s*Y\d+:|$)/g;
111
+ let m;
112
+ while ((m = re.exec(templateStr)) !== null) {
113
+ const yIndex = parseInt(m[1], 10);
114
+ const rows = m[2]
115
+ .split('|')
116
+ .map(r => decodeRLE(r.trim()))
117
+ .filter(r => r.length > 0);
118
+ if (rows.length === 0) {
119
+ console.warn(`[chunkTemplate] Y${yIndex}: no rows found, skipping`);
120
+ continue;
121
+ }
122
+ layers.push({ yIndex, rows });
123
+ }
124
+ return layers;
125
+ }
126
+ // ---------------------------------------------------------------------------
127
+ // Chunk generator factory
128
+ // ---------------------------------------------------------------------------
129
+ /**
130
+ * Returns a `(chunkX, chunkZ) => Chunk` generator that paints the decoded
131
+ * template structure into the world starting at (0, Y, 0).
132
+ *
133
+ * Chunks that do not overlap the structure are still returned but contain
134
+ * only air + full sky-light (compatible with every generator contract).
135
+ *
136
+ * @param templateStr Encoded template string (see parseTemplate).
137
+ * @param options generationOptions forwarded from world.ts
138
+ * (must include `version`, and may include `minY` /
139
+ * `worldHeight`).
140
+ * @param userBlockMap Optional extra / override mappings on top of
141
+ * DEFAULT_BLOCK_MAP. char → Minecraft block name.
142
+ */
143
+ function makeTemplateGenerator(templateStr, options, userBlockMap) {
144
+ /* eslint-disable @typescript-eslint/no-require-imports */
145
+ const Chunk = require('prismarine-chunk')(options.version);
146
+ const mcData = require('minecraft-data')(options.version);
147
+ /* eslint-enable @typescript-eslint/no-require-imports */
148
+ const minY = options.minY ?? 0;
149
+ const worldHeight = options.worldHeight ?? 256;
150
+ const baseY = options.baseY ?? 64;
151
+ const theFlattening = mcData.supportFeature('blockStateId');
152
+ // Merge user overrides on top of defaults
153
+ const resolvedMap = typeof userBlockMap === 'string' ? parseBlockMap(userBlockMap) : userBlockMap;
154
+ const blockMap = { ...exports.DEFAULT_BLOCK_MAP, ...resolvedMap };
155
+ // Resolve char → numeric block ID once at construction time
156
+ const charToId = {};
157
+ for (const [char, name] of Object.entries(blockMap)) {
158
+ if (char === 'A')
159
+ continue; // air is always a skip
160
+ const block = mcData.blocksByName[name];
161
+ if (block) {
162
+ charToId[char] = theFlattening ? block.minStateId : block.id;
163
+ }
164
+ else {
165
+ console.warn(`[chunkTemplate] Unknown block name for char '${char}': '${name}'`);
166
+ }
167
+ }
168
+ // Build a sparse "wx,wy,wz" → blockId map covering the whole structure.
169
+ // layer.yIndex is 0-based (Y0 = ground); world Y = baseY + yIndex.
170
+ const blockGrid = new Map();
171
+ for (const layer of parseTemplate(templateStr)) {
172
+ const wy = baseY + layer.yIndex;
173
+ for (let zi = 0; zi < layer.rows.length; zi++) {
174
+ const row = layer.rows[zi];
175
+ for (let xi = 0; xi < row.length; xi++) {
176
+ const char = row[xi];
177
+ if (char === 'A' || char === ' ')
178
+ continue;
179
+ const id = charToId[char];
180
+ if (id !== undefined) {
181
+ blockGrid.set(`${xi},${wy},${zi}`, id);
182
+ }
183
+ else {
184
+ console.warn(`[chunkTemplate] No block mapping for char '${char}'`);
185
+ }
186
+ }
187
+ }
188
+ }
189
+ return (chunkX, chunkZ) => {
190
+ const chunk = new Chunk({ minY, worldHeight });
191
+ // Full sky-light (standard for surface/flat worlds)
192
+ for (let lx = 0; lx < 16; lx++) {
193
+ for (let lz = 0; lz < 16; lz++) {
194
+ for (let ly = minY; ly < minY + worldHeight; ly++) {
195
+ chunk.setSkyLight(new vec3_1.Vec3(lx, ly, lz), 15);
196
+ }
197
+ }
198
+ }
199
+ const wx0 = chunkX * 16;
200
+ const wz0 = chunkZ * 16;
201
+ for (const [key, id] of blockGrid) {
202
+ const parts = key.split(',');
203
+ const wx = parseInt(parts[0], 10);
204
+ const wy = parseInt(parts[1], 10);
205
+ const wz = parseInt(parts[2], 10);
206
+ const lx = wx - wx0;
207
+ const lz = wz - wz0;
208
+ if (lx < 0 || lx >= 16 || lz < 0 || lz >= 16)
209
+ continue;
210
+ if (wy < minY || wy >= minY + worldHeight)
211
+ continue;
212
+ const pos = new vec3_1.Vec3(lx, wy, lz);
213
+ if (theFlattening) {
214
+ chunk.setBlockStateId(pos, id);
215
+ }
216
+ else {
217
+ chunk.setBlockType(pos, id);
218
+ }
219
+ }
220
+ return chunk;
221
+ };
222
+ }
package/dist/modules.d.ts CHANGED
@@ -89,6 +89,47 @@ declare global {
89
89
  version?: string;
90
90
  };
91
91
  };
92
+ /**
93
+ * If provided, this encoded string completely replaces the normal chunk
94
+ * generator for the overworld. Every chunk is filled from the decoded
95
+ * structure; chunks outside the structure bounds are empty (air + sky
96
+ * light).
97
+ *
98
+ * Strict format:
99
+ * Y<n>: row0 | row1 | … | rowN-1 Y<n>: …
100
+ *
101
+ * - `<n>` is a 0-based floor index (Y0 = ground, Y1 = one block up, …).
102
+ * - Rows are separated by `|`; each row is one Z-slice of the floor.
103
+ * - Run-length encoding: `3C` → `CCC`, `7A` → `AAAAAAA`, bare `C` → `C`.
104
+ * - `A` (or a space) represents air and is never written.
105
+ * - Single characters map to block names via `blockMap` (see below).
106
+ * - Width and depth are inferred from the decoded row lengths.
107
+ *
108
+ * @example
109
+ * "Y0: 16C | 16C Y1: C14AC | C14AC"
110
+ */
111
+ chunkTemplate?: string;
112
+ /**
113
+ * World Y coordinate that `Y0` in `chunkTemplate` maps to.
114
+ * `Y<n>` → world Y `baseY + n`.
115
+ * @default 64
116
+ */
117
+ baseY?: number;
118
+ /**
119
+ * Override or extend the default single-character → Minecraft block-name
120
+ * mapping used by `chunkTemplate`.
121
+ *
122
+ * Accepts either an object or a comma-separated string of `CHAR=block_name`
123
+ * pairs: `"C=cobblestone, G=glass_pane, X=diamond_block"`.
124
+ *
125
+ * Default map includes: A=air, C=cobblestone, M=mossy_cobblestone,
126
+ * G=glass, R=red_wool, D=dark_oak_planks, I=iron_block, S=stone,
127
+ * B=bricks, W=oak_planks, T=stone_bricks, Y=gold_block, and more.
128
+ *
129
+ * @example "C=cobblestone, G=glass_pane, X=diamond_block"
130
+ * @example { X: 'diamond_block', Z: 'emerald_block' }
131
+ */
132
+ blockMap?: Record<string, string> | string;
92
133
  kickTimeout?: number;
93
134
  plugins?: Record<string, any>;
94
135
  modpe?: boolean;
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.119",
4
+ "version": "0.0.121",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": "dist/app.js",