yeow-api 0.2.42 → 0.2.44

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,7 +1,7 @@
1
1
  {
2
2
  "name": "yeow-api",
3
- "version": "0.2.42",
4
- "description": "Yeow API �?TypeScript OOP wrappers over the task protocol",
3
+ "version": "0.2.44",
4
+ "description": "Yeow API",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "types": "./src/index.ts",
package/src/block.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { call, post } from './task.js';
2
2
  import { Location } from './location.js';
3
+ import type { ItemStack } from './item.js';
3
4
 
4
5
  export class Block {
5
6
  constructor(
@@ -19,4 +20,14 @@ export class Block {
19
20
  isLiquidSync(): boolean { return call<boolean>('block.isLiquid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
20
21
  isEmpty(): Promise<boolean> { return post<boolean>('block.isEmpty', { world: this.world, x: this.x, y: this.y, z: this.z }); }
21
22
  isEmptySync(): boolean { return call<boolean>('block.isEmpty', { world: this.world, x: this.x, y: this.y, z: this.z }); }
23
+ breakNaturally(tool?: ItemStack): Promise<boolean> {
24
+ const p: Record<string, unknown> = { world: this.world, x: this.x, y: this.y, z: this.z };
25
+ if (tool) p.item = tool;
26
+ return post<boolean>('block.breakNaturally', p);
27
+ }
28
+ breakNaturallySync(tool?: ItemStack): boolean {
29
+ const p: Record<string, unknown> = { world: this.world, x: this.x, y: this.y, z: this.z };
30
+ if (tool) p.item = tool;
31
+ return call<boolean>('block.breakNaturally', p);
32
+ }
22
33
  }
package/src/task.ts CHANGED
@@ -6,11 +6,17 @@ export function post<T = unknown>(
6
6
  return new Promise((resolve, reject) => {
7
7
  const cbId = _registerCallback((result: any) => {
8
8
  if (result?.err) {
9
- const e = new Error(result.err);
9
+ const msg = result.type ? `[${result.type}] ${result.err}` : result.err;
10
+ const e = new Error(msg);
10
11
  if ($dev && typeof _getCurrentCbStack === 'function') {
11
12
  const s = _getCurrentCbStack();
12
- if (s) e.stack += '\n --- cb registered at ---\n' + s;
13
+ if (s) e.stack += ' --- cb registered at ---\n' + s;
13
14
  }
15
+ if (result.stack) {
16
+ e.stack += '\n --- Java stack ---\n' + result.stack;
17
+ }
18
+ (e as any).javaType = result.type || null;
19
+ (e as any).taskType = result.task || null;
14
20
  reject(e);
15
21
  } else resolve(result as T);
16
22
  });