yeow-api 0.2.103 → 0.2.105

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeow-api",
3
- "version": "0.2.103",
3
+ "version": "0.2.105",
4
4
  "description": "Yeow API",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/assets.ts CHANGED
@@ -43,4 +43,16 @@ export function extractSync(path: string, dest?: string): string {
43
43
  return (_sendAssets({ t: 'extract', p }) as { path: string }).path;
44
44
  }
45
45
 
46
- export const assets = { read, readSync, readBase64, readBase64Sync, extract, extractSync };
46
+ export async function extractDir(path: string, dest?: string): Promise<string> {
47
+ const p: Record<string, unknown> = { path };
48
+ if (dest) p.dest = dest;
49
+ const r = await _sendAssetsAsync({ t: 'extractDir', p }) as { path: string };
50
+ return r.path;
51
+ }
52
+ export function extractDirSync(path: string, dest?: string): string {
53
+ const p: Record<string, unknown> = { path };
54
+ if (dest) p.dest = dest;
55
+ return (_sendAssets({ t: 'extractDir', p }) as { path: string }).path;
56
+ }
57
+
58
+ export const assets = { read, readSync, readBase64, readBase64Sync, extract, extractSync, extractDir, extractDirSync };
package/src/chunk.ts CHANGED
@@ -66,12 +66,14 @@ export class ChunkSnapshot {
66
66
 
67
67
  /**
68
68
  * 顶部方块快照(2D,256 元素):每列最高非空气方块的类型索引,顺序 z 外层 → x 内层。
69
+ * 请求时带 withHeight 可同时获得 heightMap(每列最高方块的世界高度,同布局)。
69
70
  * 索引仅当前运行时有效,不可持久化。
70
71
  */
71
72
  export class ChunkTopSnapshot {
72
73
  constructor(
73
74
  readonly data: Uint16Array,
74
75
  readonly blocks: string[],
76
+ readonly height?: Uint16Array,
75
77
  ) {}
76
78
 
77
79
  getTop(x: number, z: number): string {
@@ -84,12 +86,26 @@ export class ChunkTopSnapshot {
84
86
  return this.data[z * 16 + x];
85
87
  }
86
88
 
87
- static async fromRaw(raw: { data: string }): Promise<ChunkTopSnapshot> {
88
- return new ChunkTopSnapshot(decodeShortArray(raw.data), await ensureBlocks());
89
+ /** 列最高方块的世界高度(需 withHeight 请求;未请求时返回 null)。 */
90
+ getTopHeight(x: number, z: number): number | null {
91
+ if (!this.height || x < 0 || x > 15 || z < 0 || z > 15) return null;
92
+ return this.height[z * 16 + x];
89
93
  }
90
94
 
91
- static fromRawSync(raw: { data: string }): ChunkTopSnapshot {
92
- return new ChunkTopSnapshot(decodeShortArray(raw.data), ensureBlocksSync());
95
+ static async fromRaw(raw: { data: string; height?: string }): Promise<ChunkTopSnapshot> {
96
+ return new ChunkTopSnapshot(
97
+ decodeShortArray(raw.data),
98
+ await ensureBlocks(),
99
+ raw.height ? decodeShortArray(raw.height) : undefined,
100
+ );
101
+ }
102
+
103
+ static fromRawSync(raw: { data: string; height?: string }): ChunkTopSnapshot {
104
+ return new ChunkTopSnapshot(
105
+ decodeShortArray(raw.data),
106
+ ensureBlocksSync(),
107
+ raw.height ? decodeShortArray(raw.height) : undefined,
108
+ );
93
109
  }
94
110
  }
95
111
 
@@ -112,11 +128,16 @@ export class Chunk {
112
128
  return ChunkSnapshot.fromRawSync(call<{ data: string; minY: number; height: number }>('chunk.getSnapshot', { world: this.world, x: this.x, z: this.z }));
113
129
  }
114
130
 
115
- /** 顶部方块快照(256 元素,每列最高非空气方块,z 外层 → x 内层)。 */
116
- getTopSnapshot(): Promise<ChunkTopSnapshot> {
117
- return post<{ data: string }>('chunk.getTopSnapshot', { world: this.world, x: this.x, z: this.z }).then(ChunkTopSnapshot.fromRaw);
131
+ /** 顶部方块快照(256 元素,每列最高非空气方块,z 外层 → x 内层)。
132
+ * withHeight=true 时同时返回 heightMap(每列最高方块的世界高度)。 */
133
+ getTopSnapshot(withHeight?: boolean): Promise<ChunkTopSnapshot> {
134
+ const params: Record<string, unknown> = { world: this.world, x: this.x, z: this.z };
135
+ if (withHeight) params.withHeight = true;
136
+ return post<{ data: string; height?: string }>('chunk.getTopSnapshot', params).then(ChunkTopSnapshot.fromRaw);
118
137
  }
119
- getTopSnapshotSync(): ChunkTopSnapshot {
120
- return ChunkTopSnapshot.fromRawSync(call<{ data: string }>('chunk.getTopSnapshot', { world: this.world, x: this.x, z: this.z }));
138
+ getTopSnapshotSync(withHeight?: boolean): ChunkTopSnapshot {
139
+ const params: Record<string, unknown> = { world: this.world, x: this.x, z: this.z };
140
+ if (withHeight) params.withHeight = true;
141
+ return ChunkTopSnapshot.fromRawSync(call<{ data: string; height?: string }>('chunk.getTopSnapshot', params));
121
142
  }
122
143
  }
package/src/fs.ts CHANGED
@@ -106,14 +106,22 @@ function _makeFs(level: FsLevel) {
106
106
  return _sendFs({ t: t('systemPaths') }) as { home: string; desktop: string; temp: string };
107
107
  }
108
108
 
109
+ /** 服务器根目录(Java 进程工作目录)的绝对路径。 */
110
+ async function getServerPath(): Promise<string> {
111
+ return (await _sendFsAsync({ t: t('getServerPath') }) as { path: string }).path;
112
+ }
113
+ function getServerPathSync(): string {
114
+ return (_sendFs({ t: t('getServerPath') }) as { path: string }).path;
115
+ }
116
+
109
117
  return {
110
118
  readFile, readFileSync, readFileBase64, readFileBase64Sync,
111
119
  writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
112
120
  appendFile, appendFileSync,
113
121
  exists, existsSync, isDirectory, isDirectorySync,
114
122
  deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
115
- // systemPaths outer 级提供(fs.outer.systemPaths
116
- ...(level === 'outer' ? { systemPaths, systemPathsSync } : {}),
123
+ // outer 专属能力(systemPaths / getServerPath
124
+ ...(level === 'outer' ? { systemPaths, systemPathsSync, getServerPath, getServerPathSync } : {}),
117
125
  };
118
126
  }
119
127
 
package/src/global.d.ts CHANGED
@@ -12,6 +12,33 @@ declare global {
12
12
  function _getCurrentCbStack(): { stack: string; outer: unknown } | null;
13
13
  function _attachCbStack(err: unknown): void;
14
14
 
15
+ // ── init.js 注入的标准环境(lib 为 ESNext,不含 DOM——自行声明)──
16
+ interface YeowConsole {
17
+ log(...args: any[]): void;
18
+ info(...args: any[]): void;
19
+ warn(...args: any[]): void;
20
+ error(...args: any[]): void;
21
+ }
22
+ var console: YeowConsole;
23
+
24
+ interface YeowResponse {
25
+ ok: boolean;
26
+ status: number;
27
+ statusText: string;
28
+ headers: { get(name: string): string | undefined };
29
+ text(): Promise<string>;
30
+ json(): Promise<any>;
31
+ }
32
+ function fetch(
33
+ url: string,
34
+ init?: { method?: string; headers?: Record<string, string>; body?: string | null }
35
+ ): Promise<YeowResponse>;
36
+
37
+ function setTimeout(handler: (...args: any[]) => void, timeout?: number, ...args: any[]): string;
38
+ function clearTimeout(id: string): void;
39
+ function setInterval(handler: (...args: any[]) => void, timeout?: number, ...args: any[]): string;
40
+ function clearInterval(id: string): void;
41
+
15
42
  var __plugin:
16
43
  | {
17
44
  name: string;
package/src/index.ts CHANGED
@@ -44,7 +44,8 @@ export {
44
44
  } from './fs.js';
45
45
  export { assets, read as assetsRead, readSync as assetsReadSync,
46
46
  readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
47
- extract as assetsExtract, extractSync as assetsExtractSync } from './assets.js';
47
+ extract as assetsExtract, extractSync as assetsExtractSync,
48
+ extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
48
49
  export { path } from './path.js';
49
50
  export { listen, respond, close, request } from './http.js';
50
51
  export { logError } from './log-error.js';