yeow-api 0.2.38 → 0.2.40
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 +1 -1
- package/src/advancement.ts +26 -0
- package/src/bossbar.ts +59 -0
- package/src/entity.ts +46 -3
- package/src/event.ts +23 -0
- package/src/fs.ts +26 -1
- package/src/gui.ts +33 -0
- package/src/index.ts +38 -3
- package/src/instance-id.ts +30 -0
- package/src/inventory.ts +3 -6
- package/src/item.ts +13 -0
- package/src/location.ts +2 -9
- package/src/particle.ts +38 -0
- package/src/pdc.ts +37 -0
- package/src/player.ts +79 -18
- package/src/potion.ts +23 -0
- package/src/recipe.ts +66 -0
- package/src/scoreboard.ts +115 -0
- package/src/sound.ts +13 -0
- package/src/task.ts +6 -18
- package/src/world.ts +40 -19
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
|
|
3
|
+
export interface AdvancementProgress {
|
|
4
|
+
awardedCriteria: string[];
|
|
5
|
+
remainingCriteria: string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function grant(uuid: string, key: string): Promise<boolean> {
|
|
9
|
+
return post<boolean>('advancement.grant', { uuid, key });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function revoke(uuid: string, key: string): Promise<boolean> {
|
|
13
|
+
return post<boolean>('advancement.revoke', { uuid, key });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getProgress(uuid: string, key: string): Promise<AdvancementProgress | null> {
|
|
17
|
+
return post<AdvancementProgress | null>('advancement.getProgress', { uuid, key });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function awardCriteria(uuid: string, key: string, criteria: string): Promise<boolean> {
|
|
21
|
+
return post<boolean>('advancement.awardCriteria', { uuid, key, criteria });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function revokeCriteria(uuid: string, key: string, criteria: string): Promise<boolean> {
|
|
25
|
+
return post<boolean>('advancement.revokeCriteria', { uuid, key, criteria });
|
|
26
|
+
}
|
package/src/bossbar.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
import { BossBarHandle } from './instance-id.js';
|
|
3
|
+
|
|
4
|
+
export interface BossBarOptions {
|
|
5
|
+
color?: string;
|
|
6
|
+
style?: string;
|
|
7
|
+
progress?: number;
|
|
8
|
+
visible?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function createBossBar(title: string, options?: BossBarOptions): Promise<BossBarHandle> {
|
|
12
|
+
const h = new BossBarHandle();
|
|
13
|
+
await post('bossbar.create', { id: h.toString(), title, ...options });
|
|
14
|
+
return h;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function destroy(id: BossBarHandle): Promise<void> {
|
|
18
|
+
return post('bossbar.destroy', { id: id.toString() });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function setTitle(id: BossBarHandle, title: string): Promise<void> {
|
|
22
|
+
return post('bossbar.setTitle', { id: id.toString(), title });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function setProgress(id: BossBarHandle, progress: number): Promise<void> {
|
|
26
|
+
return post('bossbar.setProgress', { id: id.toString(), progress });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function setColor(id: BossBarHandle, color: string): Promise<void> {
|
|
30
|
+
return post('bossbar.setColor', { id: id.toString(), color });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function setStyle(id: BossBarHandle, style: string): Promise<void> {
|
|
34
|
+
return post('bossbar.setStyle', { id: id.toString(), style });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function setVisible(id: BossBarHandle, visible: boolean): Promise<void> {
|
|
38
|
+
return post('bossbar.setVisible', { id: id.toString(), visible });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function addPlayer(id: BossBarHandle, uuid: string): Promise<void> {
|
|
42
|
+
return post('bossbar.addPlayer', { id: id.toString(), uuid });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function removePlayer(id: BossBarHandle, uuid: string): Promise<void> {
|
|
46
|
+
return post('bossbar.removePlayer', { id: id.toString(), uuid });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function removeAll(id: BossBarHandle): Promise<void> {
|
|
50
|
+
return post('bossbar.removeAll', { id: id.toString() });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function addFlag(id: BossBarHandle, flag: string): Promise<void> {
|
|
54
|
+
return post('bossbar.addFlag', { id: id.toString(), flag });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function removeFlag(id: BossBarHandle, flag: string): Promise<void> {
|
|
58
|
+
return post('bossbar.removeFlag', { id: id.toString(), flag });
|
|
59
|
+
}
|
package/src/entity.ts
CHANGED
|
@@ -1,34 +1,71 @@
|
|
|
1
|
-
import { call, post
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import { Location, LocationData } from './location.js';
|
|
3
3
|
|
|
4
4
|
export class Entity {
|
|
5
|
+
static get(uuid: string): Promise<Entity | null> {
|
|
6
|
+
return post<{ uuid: string }>('entity.get', { uuid }).then((d) => (d ? new Entity(d.uuid) : null));
|
|
7
|
+
}
|
|
8
|
+
static getSync(uuid: string): Entity | null {
|
|
9
|
+
const d = call<{ uuid: string }>('entity.get', { uuid });
|
|
10
|
+
return d ? new Entity(d.uuid) : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
constructor(public readonly uuid: string) {}
|
|
6
14
|
|
|
7
15
|
get type(): string { return call<string>('entity.getType', { uuid: this.uuid }); }
|
|
16
|
+
getType(): Promise<string> { return post<string>('entity.getType', { uuid: this.uuid }); }
|
|
17
|
+
|
|
8
18
|
get name(): string { return call<string>('entity.getName', { uuid: this.uuid }); }
|
|
19
|
+
getName(): Promise<string> { return post<string>('entity.getName', { uuid: this.uuid }); }
|
|
20
|
+
|
|
9
21
|
get customName(): string | null { return call<string | null>('entity.getCustomName', { uuid: this.uuid }); }
|
|
10
22
|
set customName(v: string | null) { call('entity.setCustomName', { uuid: this.uuid, value: v }); }
|
|
23
|
+
getCustomName(): Promise<string | null> { return post<string | null>('entity.getCustomName', { uuid: this.uuid }); }
|
|
24
|
+
setCustomName(v: string | null): Promise<void> { return post('entity.setCustomName', { uuid: this.uuid, value: v }); }
|
|
25
|
+
|
|
11
26
|
setCustomNameVisible(v: boolean): Promise<void> {
|
|
12
27
|
return post('entity.setCustomNameVisible', { uuid: this.uuid, value: v });
|
|
13
28
|
}
|
|
14
29
|
setCustomNameVisibleSync(v: boolean): void {
|
|
15
30
|
call('entity.setCustomNameVisible', { uuid: this.uuid, value: v });
|
|
16
31
|
}
|
|
32
|
+
|
|
17
33
|
get world(): string | null { return call<string | null>('entity.getWorld', { uuid: this.uuid }); }
|
|
34
|
+
getWorld(): Promise<string | null> { return post<string | null>('entity.getWorld', { uuid: this.uuid }); }
|
|
35
|
+
|
|
18
36
|
get location(): Location | null {
|
|
19
|
-
const r = call<
|
|
20
|
-
return r ? Location.from(
|
|
37
|
+
const r = call<LocationData>('entity.getLocation', { uuid: this.uuid });
|
|
38
|
+
return r ? Location.from(r) : null;
|
|
39
|
+
}
|
|
40
|
+
getLocation(): Promise<Location | null> {
|
|
41
|
+
return post<LocationData>('entity.getLocation', { uuid: this.uuid }).then((r) => (r ? Location.from(r) : null));
|
|
21
42
|
}
|
|
43
|
+
|
|
22
44
|
get isGlowing(): boolean { return call<boolean>('entity.isGlowing', { uuid: this.uuid }); }
|
|
23
45
|
set isGlowing(v: boolean) { call('entity.setGlowing', { uuid: this.uuid, value: v }); }
|
|
46
|
+
isGlowingAsync(): Promise<boolean> { return post<boolean>('entity.isGlowing', { uuid: this.uuid }); }
|
|
47
|
+
setGlowing(v: boolean): Promise<void> { return post('entity.setGlowing', { uuid: this.uuid, value: v }); }
|
|
48
|
+
|
|
24
49
|
get isInvulnerable(): boolean { return call<boolean>('entity.isInvulnerable', { uuid: this.uuid }); }
|
|
25
50
|
set isInvulnerable(v: boolean) { call('entity.setInvulnerable', { uuid: this.uuid, value: v }); }
|
|
51
|
+
isInvulnerableAsync(): Promise<boolean> { return post<boolean>('entity.isInvulnerable', { uuid: this.uuid }); }
|
|
52
|
+
setInvulnerable(v: boolean): Promise<void> { return post('entity.setInvulnerable', { uuid: this.uuid, value: v }); }
|
|
53
|
+
|
|
26
54
|
get isSilent(): boolean { return call<boolean>('entity.isSilent', { uuid: this.uuid }); }
|
|
27
55
|
set isSilent(v: boolean) { call('entity.setSilent', { uuid: this.uuid, value: v }); }
|
|
56
|
+
isSilentAsync(): Promise<boolean> { return post<boolean>('entity.isSilent', { uuid: this.uuid }); }
|
|
57
|
+
setSilent(v: boolean): Promise<void> { return post('entity.setSilent', { uuid: this.uuid, value: v }); }
|
|
58
|
+
|
|
28
59
|
get hasGravity(): boolean { return call<boolean>('entity.hasGravity', { uuid: this.uuid }); }
|
|
29
60
|
set hasGravity(v: boolean) { call('entity.setGravity', { uuid: this.uuid, value: v }); }
|
|
61
|
+
hasGravityAsync(): Promise<boolean> { return post<boolean>('entity.hasGravity', { uuid: this.uuid }); }
|
|
62
|
+
setGravity(v: boolean): Promise<void> { return post('entity.setGravity', { uuid: this.uuid, value: v }); }
|
|
63
|
+
|
|
30
64
|
get passengers(): string[] { return call<string[]>('entity.getPassengers', { uuid: this.uuid }); }
|
|
65
|
+
getPassengers(): Promise<string[]> { return post<string[]>('entity.getPassengers', { uuid: this.uuid }); }
|
|
66
|
+
|
|
31
67
|
get vehicle(): string | null { return call<string | null>('entity.getVehicle', { uuid: this.uuid }); }
|
|
68
|
+
getVehicle(): Promise<string | null> { return post<string | null>('entity.getVehicle', { uuid: this.uuid }); }
|
|
32
69
|
|
|
33
70
|
remove(): Promise<void> { return post('entity.remove', { uuid: this.uuid }); }
|
|
34
71
|
removeSync(): void { call('entity.remove', { uuid: this.uuid }); }
|
|
@@ -39,6 +76,12 @@ export class Entity {
|
|
|
39
76
|
export class LivingEntity extends Entity {
|
|
40
77
|
get health(): number { return call<number>('entity.getHealth', { uuid: this.uuid }); }
|
|
41
78
|
set health(v: number) { call('entity.setHealth', { uuid: this.uuid, value: v }); }
|
|
79
|
+
getHealth(): Promise<number> { return post<number>('entity.getHealth', { uuid: this.uuid }); }
|
|
80
|
+
setHealth(v: number): Promise<void> { return post('entity.setHealth', { uuid: this.uuid, value: v }); }
|
|
81
|
+
|
|
42
82
|
get maxHealth(): number { return call<number>('entity.getMaxHealth', { uuid: this.uuid }); }
|
|
83
|
+
getMaxHealth(): Promise<number> { return post<number>('entity.getMaxHealth', { uuid: this.uuid }); }
|
|
84
|
+
|
|
43
85
|
get isDead(): boolean { return call<boolean>('entity.isDead', { uuid: this.uuid }); }
|
|
86
|
+
isDeadAsync(): Promise<boolean> { return post<boolean>('entity.isDead', { uuid: this.uuid }); }
|
|
44
87
|
}
|
package/src/event.ts
CHANGED
|
@@ -192,6 +192,27 @@ export interface ServerCommandEvent {
|
|
|
192
192
|
command: string;
|
|
193
193
|
sender: string;
|
|
194
194
|
}
|
|
195
|
+
export interface InventoryClickEvent {
|
|
196
|
+
player: Player;
|
|
197
|
+
slot: number;
|
|
198
|
+
hotbarKey: number;
|
|
199
|
+
action: string;
|
|
200
|
+
inventoryType: string;
|
|
201
|
+
isLeftClick: boolean;
|
|
202
|
+
isRightClick: boolean;
|
|
203
|
+
isShiftClick: boolean;
|
|
204
|
+
clickedItem: ItemData | null;
|
|
205
|
+
cursorItem: ItemData | null;
|
|
206
|
+
}
|
|
207
|
+
interface ItemData {
|
|
208
|
+
type: string;
|
|
209
|
+
amount: number;
|
|
210
|
+
}
|
|
211
|
+
export interface PlayerResourcePackStatusEvent {
|
|
212
|
+
player: Player;
|
|
213
|
+
status: string;
|
|
214
|
+
hash: string;
|
|
215
|
+
}
|
|
195
216
|
|
|
196
217
|
type EventMap = {
|
|
197
218
|
playerJoin: PlayerJoinEvent;
|
|
@@ -230,6 +251,8 @@ type EventMap = {
|
|
|
230
251
|
serverCommand: ServerCommandEvent;
|
|
231
252
|
playerTeleport: PlayerTeleportEvent;
|
|
232
253
|
playerItemConsume: PlayerItemConsumeEvent;
|
|
254
|
+
inventoryClick: InventoryClickEvent;
|
|
255
|
+
playerResourcePackStatus: PlayerResourcePackStatusEvent;
|
|
233
256
|
};
|
|
234
257
|
|
|
235
258
|
type RawEvent = Record<string, unknown> & { _cancellable?: boolean };
|
package/src/fs.ts
CHANGED
|
@@ -49,6 +49,16 @@ export function writeFileBase64Sync(path: string, data: string): void {
|
|
|
49
49
|
_sendFs({ t: 'writeBase64', p: { path, data } });
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export function appendFile(path: string, data: string): Promise<void> {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
try { _sendFs({ t: 'appendFile', p: { path, data } }); resolve(); }
|
|
55
|
+
catch (e) { reject(e); }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export function appendFileSync(path: string, data: string): void {
|
|
59
|
+
_sendFs({ t: 'appendFile', p: { path, data } });
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
export function exists(path: string): Promise<boolean> {
|
|
53
63
|
return new Promise((resolve, reject) => {
|
|
54
64
|
try {
|
|
@@ -62,6 +72,19 @@ export function existsSync(path: string): boolean {
|
|
|
62
72
|
return r === true || String(r) === 'true';
|
|
63
73
|
}
|
|
64
74
|
|
|
75
|
+
export function isDirectory(path: string): Promise<boolean> {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
try {
|
|
78
|
+
const r = _sendFs({ t: 'isDirectory', p: { path } });
|
|
79
|
+
resolve(r === true || String(r) === 'true');
|
|
80
|
+
} catch (e) { reject(e); }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function isDirectorySync(path: string): boolean {
|
|
84
|
+
const r = _sendFs({ t: 'isDirectory', p: { path } });
|
|
85
|
+
return r === true || String(r) === 'true';
|
|
86
|
+
}
|
|
87
|
+
|
|
65
88
|
export function deleteFile(path: string): Promise<boolean> {
|
|
66
89
|
return new Promise((resolve, reject) => {
|
|
67
90
|
try {
|
|
@@ -100,5 +123,7 @@ export function listSync(path: string): string[] {
|
|
|
100
123
|
export const fs = {
|
|
101
124
|
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
102
125
|
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
103
|
-
|
|
126
|
+
appendFile, appendFileSync,
|
|
127
|
+
exists, existsSync, isDirectory, isDirectorySync,
|
|
128
|
+
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
104
129
|
};
|
package/src/gui.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
import { GUIHandle } from './instance-id.js';
|
|
3
|
+
import type { ItemStack } from './item.js';
|
|
4
|
+
|
|
5
|
+
export async function createGUI(size: number, title: string): Promise<GUIHandle> {
|
|
6
|
+
const h = new GUIHandle();
|
|
7
|
+
await post('gui.create', { id: h.toString(), size, title });
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function destroy(id: GUIHandle): Promise<void> {
|
|
12
|
+
return post('gui.destroy', { id: id.toString() });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function open(id: GUIHandle, uuid: string): Promise<void> {
|
|
16
|
+
return post('gui.open', { id: id.toString(), uuid });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function close(id: GUIHandle): Promise<void> {
|
|
20
|
+
return post('gui.close', { id: id.toString() });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function setItem(id: GUIHandle, slot: number, item: ItemStack): Promise<void> {
|
|
24
|
+
return post('gui.setItem', { id: id.toString(), slot, item });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function fill(id: GUIHandle, item: ItemStack): Promise<void> {
|
|
28
|
+
return post('gui.fill', { id: id.toString(), item });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function clear(id: GUIHandle): Promise<void> {
|
|
32
|
+
return post('gui.clear', { id: id.toString() });
|
|
33
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="global.d.ts" />
|
|
2
2
|
|
|
3
|
-
export { call
|
|
3
|
+
export { call } from './task.js';
|
|
4
4
|
export { Location } from './location.js';
|
|
5
5
|
export { Player } from './player.js';
|
|
6
6
|
export { World } from './world.js';
|
|
@@ -20,8 +20,9 @@ export type {
|
|
|
20
20
|
EntityRegainHealthEvent, EntityTargetEvent,
|
|
21
21
|
ProjectileLaunchEvent, ProjectileHitEvent,
|
|
22
22
|
BlockBreakEvent, BlockPlaceEvent, BlockFadeEvent, BlockGrowEvent, BlockSpreadEvent, BlockExplodeEvent,
|
|
23
|
-
InventoryOpenEvent, InventoryCloseEvent,
|
|
23
|
+
InventoryOpenEvent, InventoryCloseEvent, InventoryClickEvent,
|
|
24
24
|
ServerPingEvent, ServerCommandEvent,
|
|
25
|
+
PlayerResourcePackStatusEvent,
|
|
25
26
|
} from './event.js';
|
|
26
27
|
export { onInit, onLoad, onUnload } from './lifecycle.js';
|
|
27
28
|
export {
|
|
@@ -33,7 +34,9 @@ export {
|
|
|
33
34
|
fs,
|
|
34
35
|
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
35
36
|
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
36
|
-
|
|
37
|
+
appendFile, appendFileSync,
|
|
38
|
+
exists, existsSync, isDirectory, isDirectorySync,
|
|
39
|
+
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
37
40
|
} from './fs.js';
|
|
38
41
|
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
39
42
|
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
@@ -41,3 +44,35 @@ export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
|
41
44
|
export { path } from './path.js';
|
|
42
45
|
export { listen, respond, close, request } from './http.js';
|
|
43
46
|
export { logError } from './log-error.js';
|
|
47
|
+
export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
|
|
48
|
+
export type { ItemStack } from './item.js';
|
|
49
|
+
export type { PotionEffect } from './potion.js';
|
|
50
|
+
export { addPotionEffect, removePotionEffect, clearPotionEffects, getActivePotionEffects } from './potion.js';
|
|
51
|
+
export { playSound, stopSound, stopAllSounds } from './sound.js';
|
|
52
|
+
export type { ParticleOptions } from './particle.js';
|
|
53
|
+
export { spawnParticle } from './particle.js';
|
|
54
|
+
export { get as pdcGet, set as pdcSet, has as pdcHas, remove as pdcRemove, keys as pdcKeys,
|
|
55
|
+
getBlock as pdcGetBlock, setBlock as pdcSetBlock, hasBlock as pdcHasBlock, removeBlock as pdcRemoveBlock } from './pdc.js';
|
|
56
|
+
export { createBossBar, destroy as destroyBossBar,
|
|
57
|
+
setTitle as setBossBarTitle, setProgress as setBossBarProgress,
|
|
58
|
+
setColor as setBossBarColor, setStyle as setBossBarStyle,
|
|
59
|
+
setVisible as setBossBarVisible, addPlayer as addBossBarPlayer,
|
|
60
|
+
removePlayer as removeBossBarPlayer, removeAll as removeAllBossBarPlayers,
|
|
61
|
+
addFlag as addBossBarFlag, removeFlag as removeBossBarFlag } from './bossbar.js';
|
|
62
|
+
export type { BossBarOptions } from './bossbar.js';
|
|
63
|
+
export { createGUI, destroy as destroyGUI, open as openGUI,
|
|
64
|
+
close as closeGUI, setItem as setGUIItem, fill as fillGUI, clear as clearGUI } from './gui.js';
|
|
65
|
+
export type { AdvancementProgress } from './advancement.js';
|
|
66
|
+
export { grant as grantAdvancement, revoke as revokeAdvancement,
|
|
67
|
+
getProgress as getAdvancementProgress, awardCriteria, revokeCriteria } from './advancement.js';
|
|
68
|
+
export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForItem } from './recipe.js';
|
|
69
|
+
export type {
|
|
70
|
+
ObjectiveInfo, TeamInfo,
|
|
71
|
+
} from './scoreboard.js';
|
|
72
|
+
export { createObjective, deleteObjective, getObjectives,
|
|
73
|
+
setObjectiveDisplay, getScore, setScore, resetScore,
|
|
74
|
+
createTeam, deleteTeam, getTeam, getTeams,
|
|
75
|
+
setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
|
|
76
|
+
setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
|
|
77
|
+
teamAddEntry, teamRemoveEntry, teamGetEntries,
|
|
78
|
+
setPlayerBoard } from './scoreboard.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
let _seq = 0;
|
|
2
|
+
const _gcQueue: string[] = [];
|
|
3
|
+
const _gcReg = typeof FinalizationRegistry !== 'undefined'
|
|
4
|
+
? new FinalizationRegistry<string>((raw: string) => { _gcQueue.push(raw); })
|
|
5
|
+
: null;
|
|
6
|
+
(globalThis as any).__yeowGcQueue = _gcQueue;
|
|
7
|
+
|
|
8
|
+
export class InstanceId {
|
|
9
|
+
readonly _raw: string;
|
|
10
|
+
readonly _managed: boolean;
|
|
11
|
+
|
|
12
|
+
constructor(prefix: string) {
|
|
13
|
+
this._raw = prefix + '_' + (++_seq);
|
|
14
|
+
this._managed = true;
|
|
15
|
+
_gcReg?.register(this, this._raw);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static adopt(raw: string): InstanceId {
|
|
19
|
+
const id = Object.create(InstanceId.prototype) as InstanceId;
|
|
20
|
+
(id as any)._raw = raw;
|
|
21
|
+
(id as any)._managed = false;
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString(): string { return this._raw; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class GUIHandle extends InstanceId { constructor() { super('gui'); } }
|
|
29
|
+
export class BossBarHandle extends InstanceId { constructor() { super('boss'); } }
|
|
30
|
+
export class InventoryHandle extends InstanceId { constructor() { super('inv'); } }
|
package/src/inventory.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { call, post
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
|
|
3
3
|
interface ItemData {
|
|
4
4
|
type: string;
|
|
@@ -9,13 +9,10 @@ export class Inventory {
|
|
|
9
9
|
constructor(private readonly uuid: string) {}
|
|
10
10
|
|
|
11
11
|
getItem(slot: number): Promise<ItemData | null> {
|
|
12
|
-
return post<
|
|
13
|
-
r ? { type: val(r, 'type'), amount: val(r, 'amount') } : null
|
|
14
|
-
);
|
|
12
|
+
return post<ItemData | null>('inventory.getItem', { uuid: this.uuid, slot });
|
|
15
13
|
}
|
|
16
14
|
getItemSync(slot: number): ItemData | null {
|
|
17
|
-
|
|
18
|
-
return r ? { type: val(r, 'type'), amount: val(r, 'amount') } : null;
|
|
15
|
+
return call<ItemData | null>('inventory.getItem', { uuid: this.uuid, slot });
|
|
19
16
|
}
|
|
20
17
|
setItem(slot: number, itemType: string, amount?: number): Promise<void> {
|
|
21
18
|
return post('inventory.setItem', { uuid: this.uuid, slot, itemType, amount });
|
package/src/item.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ItemStack {
|
|
2
|
+
type: string;
|
|
3
|
+
amount: number;
|
|
4
|
+
meta?: {
|
|
5
|
+
displayName?: string;
|
|
6
|
+
lore?: string[];
|
|
7
|
+
customModelData?: number;
|
|
8
|
+
unbreakable?: boolean;
|
|
9
|
+
hideTooltip?: boolean;
|
|
10
|
+
enchantments?: Record<string, number>;
|
|
11
|
+
itemFlags?: string[];
|
|
12
|
+
};
|
|
13
|
+
}
|
package/src/location.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { val } from './task.js';
|
|
2
|
-
|
|
3
1
|
export interface LocationData {
|
|
4
2
|
x: number;
|
|
5
3
|
y: number;
|
|
@@ -19,13 +17,8 @@ export class Location {
|
|
|
19
17
|
public readonly world?: string,
|
|
20
18
|
) {}
|
|
21
19
|
|
|
22
|
-
static from(
|
|
23
|
-
|
|
24
|
-
static from(a: any, b?: any, c?: any, d?: any, e?: any, f?: any): Location {
|
|
25
|
-
if (typeof a === 'object' && a !== null) {
|
|
26
|
-
return new Location(val(a, 'x'), val(a, 'y'), val(a, 'z'), val(a, 'yaw') ?? 0, val(a, 'pitch') ?? 0, val(a, 'world'));
|
|
27
|
-
}
|
|
28
|
-
return new Location(a, b, c, d ?? 0, e ?? 0, f);
|
|
20
|
+
static from(raw: LocationData): Location {
|
|
21
|
+
return new Location(raw.x, raw.y, raw.z, raw.yaw ?? 0, raw.pitch ?? 0, raw.world);
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
toObject(): LocationData {
|
package/src/particle.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
import type { ItemStack } from './item.js';
|
|
3
|
+
|
|
4
|
+
export interface ParticleOptions {
|
|
5
|
+
particle: string;
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
world: string;
|
|
10
|
+
count?: number;
|
|
11
|
+
offsetX?: number;
|
|
12
|
+
offsetY?: number;
|
|
13
|
+
offsetZ?: number;
|
|
14
|
+
speed?: number;
|
|
15
|
+
force?: boolean;
|
|
16
|
+
color?: { r: number; g: number; b: number; size?: number };
|
|
17
|
+
blockType?: string;
|
|
18
|
+
item?: ItemStack;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function spawnParticle(options: ParticleOptions): Promise<void> {
|
|
22
|
+
return post('world.spawnParticle', {
|
|
23
|
+
world: options.world,
|
|
24
|
+
particle: options.particle,
|
|
25
|
+
x: options.x,
|
|
26
|
+
y: options.y,
|
|
27
|
+
z: options.z,
|
|
28
|
+
count: options.count,
|
|
29
|
+
offsetX: options.offsetX,
|
|
30
|
+
offsetY: options.offsetY,
|
|
31
|
+
offsetZ: options.offsetZ,
|
|
32
|
+
speed: options.speed,
|
|
33
|
+
force: options.force,
|
|
34
|
+
color: options.color,
|
|
35
|
+
blockType: options.blockType,
|
|
36
|
+
item: options.item,
|
|
37
|
+
});
|
|
38
|
+
}
|
package/src/pdc.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
|
|
3
|
+
export function get(uuid: string, key: string): Promise<string | null> {
|
|
4
|
+
return post<string | null>('pdc.get', { uuid, key });
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function set(uuid: string, key: string, value: string): Promise<boolean> {
|
|
8
|
+
return post<boolean>('pdc.set', { uuid, key, value });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function has(uuid: string, key: string): Promise<boolean> {
|
|
12
|
+
return post<boolean>('pdc.has', { uuid, key });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function remove(uuid: string, key: string): Promise<boolean> {
|
|
16
|
+
return post<boolean>('pdc.remove', { uuid, key });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function keys(uuid: string): Promise<string[]> {
|
|
20
|
+
return post<string[]>('pdc.keys', { uuid });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getBlock(world: string, x: number, y: number, z: number, key: string): Promise<string | null> {
|
|
24
|
+
return post<string | null>('pdc.get', { world, x, y, z, key });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function setBlock(world: string, x: number, y: number, z: number, key: string, value: string): Promise<boolean> {
|
|
28
|
+
return post<boolean>('pdc.set', { world, x, y, z, key, value });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function hasBlock(world: string, x: number, y: number, z: number, key: string): Promise<boolean> {
|
|
32
|
+
return post<boolean>('pdc.has', { world, x, y, z, key });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function removeBlock(world: string, x: number, y: number, z: number, key: string): Promise<boolean> {
|
|
36
|
+
return post<boolean>('pdc.remove', { world, x, y, z, key });
|
|
37
|
+
}
|
package/src/player.ts
CHANGED
|
@@ -1,46 +1,102 @@
|
|
|
1
|
-
import { call, post
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import { Location, LocationData } from './location.js';
|
|
3
3
|
|
|
4
|
+
interface PlayerData {
|
|
5
|
+
uuid: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export class Player {
|
|
5
10
|
static get(identifier: string): Promise<Player | null> {
|
|
6
|
-
return post<
|
|
7
|
-
if (!d) return null;
|
|
8
|
-
const uuid = val(d, 'uuid');
|
|
9
|
-
const name = val(d, 'name');
|
|
10
|
-
return uuid ? new Player(uuid, name) : null;
|
|
11
|
-
});
|
|
11
|
+
return post<PlayerData>('player.get', { identifier }).then((d) => (d ? new Player(d.uuid, d.name) : null));
|
|
12
12
|
}
|
|
13
13
|
static getSync(identifier: string): Player | null {
|
|
14
|
-
const d = call<
|
|
15
|
-
|
|
16
|
-
return new Player(val(d, 'uuid'), val(d, 'name'));
|
|
14
|
+
const d = call<PlayerData>('player.get', { identifier });
|
|
15
|
+
return d ? new Player(d.uuid, d.name) : null;
|
|
17
16
|
}
|
|
18
17
|
static getAll(): Promise<Player[]> {
|
|
19
|
-
return post<
|
|
20
|
-
(list || []).map((r: any) => new Player(val(r, 'uuid'), val(r, 'name')))
|
|
21
|
-
);
|
|
18
|
+
return post<PlayerData[]>('player.getAll', {}).then((list) => list.map((r) => new Player(r.uuid, r.name)));
|
|
22
19
|
}
|
|
23
20
|
static getAllSync(): Player[] {
|
|
24
|
-
return
|
|
25
|
-
new Player(val(r, 'uuid'), val(r, 'name'))
|
|
26
|
-
);
|
|
21
|
+
return call<PlayerData[]>('player.getAll', {}).map((r) => new Player(r.uuid, r.name));
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
constructor(public readonly uuid: string, private _name?: string) {}
|
|
30
25
|
|
|
31
26
|
get name(): string { return this._name ?? ''; }
|
|
27
|
+
|
|
32
28
|
get ping(): number { return call<number>('player.getPing', { uuid: this.uuid }); }
|
|
29
|
+
getPing(): Promise<number> { return post<number>('player.getPing', { uuid: this.uuid }); }
|
|
30
|
+
|
|
33
31
|
get gamemode(): string { return call<string>('player.getGamemode', { uuid: this.uuid }); }
|
|
34
32
|
set gamemode(v: string) { call('player.setGamemode', { uuid: this.uuid, value: v }); }
|
|
33
|
+
getGamemode(): Promise<string> { return post<string>('player.getGamemode', { uuid: this.uuid }); }
|
|
34
|
+
setGamemode(v: string): Promise<void> { return post('player.setGamemode', { uuid: this.uuid, value: v }); }
|
|
35
|
+
|
|
36
|
+
get health(): number { return call<number>('player.getHealth', { uuid: this.uuid }); }
|
|
37
|
+
set health(v: number) { call('player.setHealth', { uuid: this.uuid, value: v }); }
|
|
38
|
+
getHealth(): Promise<number> { return post<number>('player.getHealth', { uuid: this.uuid }); }
|
|
39
|
+
setHealth(v: number): Promise<void> { return post('player.setHealth', { uuid: this.uuid, value: v }); }
|
|
40
|
+
|
|
41
|
+
get food(): number { return call<number>('player.getFood', { uuid: this.uuid }); }
|
|
42
|
+
set food(v: number) { call('player.setFood', { uuid: this.uuid, value: v }); }
|
|
43
|
+
getFood(): Promise<number> { return post<number>('player.getFood', { uuid: this.uuid }); }
|
|
44
|
+
setFood(v: number): Promise<void> { return post('player.setFood', { uuid: this.uuid, value: v }); }
|
|
45
|
+
|
|
46
|
+
get exp(): number { return call<number>('player.getExp', { uuid: this.uuid }); }
|
|
47
|
+
set exp(v: number) { call('player.setExp', { uuid: this.uuid, value: v }); }
|
|
48
|
+
getExp(): Promise<number> { return post<number>('player.getExp', { uuid: this.uuid }); }
|
|
49
|
+
setExp(v: number): Promise<void> { return post('player.setExp', { uuid: this.uuid, value: v }); }
|
|
50
|
+
|
|
51
|
+
get level(): number { return call<number>('player.getLevel', { uuid: this.uuid }); }
|
|
52
|
+
set level(v: number) { call('player.setLevel', { uuid: this.uuid, value: v }); }
|
|
53
|
+
getLevel(): Promise<number> { return post<number>('player.getLevel', { uuid: this.uuid }); }
|
|
54
|
+
setLevel(v: number): Promise<void> { return post('player.setLevel', { uuid: this.uuid, value: v }); }
|
|
55
|
+
|
|
56
|
+
get isOp(): boolean { return call<boolean>('player.isOp', { uuid: this.uuid }); }
|
|
57
|
+
isOpAsync(): Promise<boolean> { return post<boolean>('player.isOp', { uuid: this.uuid }); }
|
|
58
|
+
|
|
59
|
+
get isFlying(): boolean { return call<boolean>('player.isFlying', { uuid: this.uuid }); }
|
|
60
|
+
set isFlying(v: boolean) { call('player.setFlying', { uuid: this.uuid, value: v }); }
|
|
61
|
+
isFlyingAsync(): Promise<boolean> { return post<boolean>('player.isFlying', { uuid: this.uuid }); }
|
|
62
|
+
setFlying(v: boolean): Promise<void> { return post('player.setFlying', { uuid: this.uuid, value: v }); }
|
|
63
|
+
|
|
64
|
+
get allowFlight(): boolean { return call<boolean>('player.getAllowFlight', { uuid: this.uuid }); }
|
|
65
|
+
set allowFlight(v: boolean) { call('player.setAllowFlight', { uuid: this.uuid, value: v }); }
|
|
66
|
+
getAllowFlight(): Promise<boolean> { return post<boolean>('player.getAllowFlight', { uuid: this.uuid }); }
|
|
67
|
+
setAllowFlight(v: boolean): Promise<void> { return post('player.setAllowFlight', { uuid: this.uuid, value: v }); }
|
|
68
|
+
|
|
69
|
+
get walkSpeed(): number { return call<number>('player.getWalkSpeed', { uuid: this.uuid }); }
|
|
70
|
+
set walkSpeed(v: number) { call('player.setWalkSpeed', { uuid: this.uuid, value: v }); }
|
|
71
|
+
getWalkSpeed(): Promise<number> { return post<number>('player.getWalkSpeed', { uuid: this.uuid }); }
|
|
72
|
+
setWalkSpeed(v: number): Promise<void> { return post('player.setWalkSpeed', { uuid: this.uuid, value: v }); }
|
|
73
|
+
|
|
74
|
+
get flySpeed(): number { return call<number>('player.getFlySpeed', { uuid: this.uuid }); }
|
|
75
|
+
set flySpeed(v: number) { call('player.setFlySpeed', { uuid: this.uuid, value: v }); }
|
|
76
|
+
getFlySpeed(): Promise<number> { return post<number>('player.getFlySpeed', { uuid: this.uuid }); }
|
|
77
|
+
setFlySpeed(v: number): Promise<void> { return post('player.setFlySpeed', { uuid: this.uuid, value: v }); }
|
|
78
|
+
|
|
35
79
|
get world(): string { return call<string>('player.getWorld', { uuid: this.uuid }); }
|
|
80
|
+
getWorld(): Promise<string> { return post<string>('player.getWorld', { uuid: this.uuid }); }
|
|
81
|
+
|
|
36
82
|
get location(): Location | null {
|
|
37
|
-
const r = call<
|
|
38
|
-
return r ? Location.from(
|
|
83
|
+
const r = call<LocationData>('player.getLocation', { uuid: this.uuid });
|
|
84
|
+
return r ? Location.from(r) : null;
|
|
39
85
|
}
|
|
86
|
+
getLocation(): Promise<Location | null> {
|
|
87
|
+
return post<LocationData>('player.getLocation', { uuid: this.uuid }).then((r) => (r ? Location.from(r) : null));
|
|
88
|
+
}
|
|
89
|
+
|
|
40
90
|
get displayName(): string { return call<string>('player.getDisplayName', { uuid: this.uuid }); }
|
|
41
91
|
set displayName(v: string | null) { call('player.setDisplayName', { uuid: this.uuid, value: v }); }
|
|
92
|
+
getDisplayName(): Promise<string> { return post<string>('player.getDisplayName', { uuid: this.uuid }); }
|
|
93
|
+
setDisplayName(v: string | null): Promise<void> { return post('player.setDisplayName', { uuid: this.uuid, value: v }); }
|
|
94
|
+
|
|
42
95
|
get saturation(): number { return call<number>('player.getSaturation', { uuid: this.uuid }); }
|
|
96
|
+
getSaturation(): Promise<number> { return post<number>('player.getSaturation', { uuid: this.uuid }); }
|
|
97
|
+
|
|
43
98
|
get totalExperience(): number { return call<number>('player.getTotalExperience', { uuid: this.uuid }); }
|
|
99
|
+
getTotalExperience(): Promise<number> { return post<number>('player.getTotalExperience', { uuid: this.uuid }); }
|
|
44
100
|
|
|
45
101
|
sendMessage(msg: string): Promise<void> { return post('player.sendMessage', { uuid: this.uuid, message: msg }); }
|
|
46
102
|
sendMessageSync(msg: string): void { call('player.sendMessage', { uuid: this.uuid, message: msg }); }
|
|
@@ -68,4 +124,9 @@ export class Player {
|
|
|
68
124
|
}
|
|
69
125
|
teleport(loc: Location): Promise<void> { return post('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
|
|
70
126
|
teleportSync(loc: Location): void { call('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
|
|
127
|
+
sendActionBar(message: string): Promise<void> { return post('player.sendActionBar', { uuid: this.uuid, message }); }
|
|
128
|
+
sendActionBarSync(message: string): void { call('player.sendActionBar', { uuid: this.uuid, message }); }
|
|
129
|
+
sendResourcePack(url: string, hash?: string, prompt?: string, force?: boolean): Promise<void> {
|
|
130
|
+
return post('player.sendResourcePack', { uuid: this.uuid, url, hash, prompt, force });
|
|
131
|
+
}
|
|
71
132
|
}
|
package/src/potion.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
|
|
3
|
+
export interface PotionEffect {
|
|
4
|
+
type: string;
|
|
5
|
+
duration: number;
|
|
6
|
+
amplifier: number;
|
|
7
|
+
ambient?: boolean;
|
|
8
|
+
particles?: boolean;
|
|
9
|
+
icon?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function addPotionEffect(uuid: string, effect: PotionEffect): Promise<void> {
|
|
13
|
+
return post('entity.addPotionEffect', { uuid, ...effect });
|
|
14
|
+
}
|
|
15
|
+
export function removePotionEffect(uuid: string, type: string): Promise<void> {
|
|
16
|
+
return post('entity.removePotionEffect', { uuid, type });
|
|
17
|
+
}
|
|
18
|
+
export function clearPotionEffects(uuid: string): Promise<void> {
|
|
19
|
+
return post('entity.clearPotionEffects', { uuid });
|
|
20
|
+
}
|
|
21
|
+
export function getActivePotionEffects(uuid: string): Promise<PotionEffect[]> {
|
|
22
|
+
return post<PotionEffect[]>('entity.getActivePotionEffects', { uuid });
|
|
23
|
+
}
|
package/src/recipe.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
import type { ItemStack } from './item.js';
|
|
3
|
+
|
|
4
|
+
type RecipeDefinition = ShapedRecipe | ShapelessRecipe | FurnaceRecipe | BlastRecipe | SmokerRecipe | CampfireRecipe;
|
|
5
|
+
|
|
6
|
+
interface ShapedRecipe {
|
|
7
|
+
type: 'shaped';
|
|
8
|
+
key: string;
|
|
9
|
+
result: ItemStack;
|
|
10
|
+
shape: string[];
|
|
11
|
+
ingredients: Record<string, string>;
|
|
12
|
+
group?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ShapelessRecipe {
|
|
16
|
+
type: 'shapeless';
|
|
17
|
+
key: string;
|
|
18
|
+
result: ItemStack;
|
|
19
|
+
ingredients: (string | ItemStack)[];
|
|
20
|
+
group?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface FurnaceRecipe {
|
|
24
|
+
type: 'furnace';
|
|
25
|
+
key: string;
|
|
26
|
+
input: string;
|
|
27
|
+
result: ItemStack;
|
|
28
|
+
experience?: number;
|
|
29
|
+
cookingTime?: number;
|
|
30
|
+
}
|
|
31
|
+
interface BlastRecipe {
|
|
32
|
+
type: 'blast';
|
|
33
|
+
key: string;
|
|
34
|
+
input: string;
|
|
35
|
+
result: ItemStack;
|
|
36
|
+
experience?: number;
|
|
37
|
+
cookingTime?: number;
|
|
38
|
+
}
|
|
39
|
+
interface SmokerRecipe {
|
|
40
|
+
type: 'smoker';
|
|
41
|
+
key: string;
|
|
42
|
+
input: string;
|
|
43
|
+
result: ItemStack;
|
|
44
|
+
experience?: number;
|
|
45
|
+
cookingTime?: number;
|
|
46
|
+
}
|
|
47
|
+
interface CampfireRecipe {
|
|
48
|
+
type: 'campfire';
|
|
49
|
+
key: string;
|
|
50
|
+
input: string;
|
|
51
|
+
result: ItemStack;
|
|
52
|
+
experience?: number;
|
|
53
|
+
cookingTime?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function add(recipe: RecipeDefinition): Promise<boolean> {
|
|
57
|
+
return post<boolean>('recipe.add', recipe as Record<string, unknown>);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function remove(key: string): Promise<void> {
|
|
61
|
+
return post('recipe.remove', { key });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getForItem(item: ItemStack): Promise<string[]> {
|
|
65
|
+
return post<string[]>('recipe.getForItem', { item });
|
|
66
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
|
|
3
|
+
export interface ObjectiveInfo {
|
|
4
|
+
name: string;
|
|
5
|
+
criteria: string;
|
|
6
|
+
displaySlot: string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TeamInfo {
|
|
10
|
+
name: string;
|
|
11
|
+
displayName: string;
|
|
12
|
+
prefix: string;
|
|
13
|
+
suffix: string;
|
|
14
|
+
color: string;
|
|
15
|
+
allowFriendlyFire: boolean;
|
|
16
|
+
canSeeFriendlyInvisibles: boolean;
|
|
17
|
+
entries: string[];
|
|
18
|
+
options: {
|
|
19
|
+
nameTagVisibility: string;
|
|
20
|
+
deathMessageVisibility: string;
|
|
21
|
+
collisionRule: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ── Objectives ──
|
|
26
|
+
|
|
27
|
+
export function createObjective(name: string, criteria: string, displayName: string): Promise<ObjectiveInfo> {
|
|
28
|
+
return post<ObjectiveInfo>('scoreboard.createObjective', { name, criteria, displayName });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function deleteObjective(name: string): Promise<void> {
|
|
32
|
+
return post('scoreboard.deleteObjective', { name });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getObjectives(): Promise<ObjectiveInfo[]> {
|
|
36
|
+
return post<ObjectiveInfo[]>('scoreboard.getObjectives', {});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function setObjectiveDisplay(name: string, slot: string | null): Promise<boolean> {
|
|
40
|
+
return post<boolean>('scoreboard.setObjectiveDisplay', { name, slot });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getScore(objective: string, entry: string): Promise<number | null> {
|
|
44
|
+
return post<number | null>('scoreboard.getScore', { objective, entry });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function setScore(objective: string, entry: string, value: number): Promise<void> {
|
|
48
|
+
return post('scoreboard.setScore', { objective, entry, value });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function resetScore(objective: string, entry: string): Promise<void> {
|
|
52
|
+
return post('scoreboard.resetScore', { objective, entry });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── Teams ──
|
|
56
|
+
|
|
57
|
+
export function createTeam(name: string): Promise<void> {
|
|
58
|
+
return post('scoreboard.createTeam', { name });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function deleteTeam(name: string): Promise<void> {
|
|
62
|
+
return post('scoreboard.deleteTeam', { name });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getTeam(name: string): Promise<TeamInfo | null> {
|
|
66
|
+
return post<TeamInfo | null>('scoreboard.getTeam', { name });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getTeams(): Promise<TeamInfo[]> {
|
|
70
|
+
return post<TeamInfo[]>('scoreboard.getTeams', {});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function setTeamDisplayName(name: string, displayName: string): Promise<void> {
|
|
74
|
+
return post('scoreboard.setTeamDisplayName', { name, displayName });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function setTeamPrefix(name: string, prefix: string): Promise<void> {
|
|
78
|
+
return post('scoreboard.setTeamPrefix', { name, prefix });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function setTeamSuffix(name: string, suffix: string): Promise<void> {
|
|
82
|
+
return post('scoreboard.setTeamSuffix', { name, suffix });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function setTeamColor(name: string, color: string): Promise<void> {
|
|
86
|
+
return post('scoreboard.setTeamColor', { name, color });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function setTeamFriendlyFire(name: string, allow: boolean): Promise<void> {
|
|
90
|
+
return post('scoreboard.setTeamFriendlyFire', { name, allow });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function setTeamSeeInvisible(name: string, canSee: boolean): Promise<void> {
|
|
94
|
+
return post('scoreboard.setTeamSeeInvisible', { name, canSee });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function setTeamOption(name: string, option: string, value: string): Promise<void> {
|
|
98
|
+
return post('scoreboard.setTeamOption', { name, option, value });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function teamAddEntry(name: string, entry: string): Promise<void> {
|
|
102
|
+
return post('scoreboard.teamAddEntry', { name, entry });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function teamRemoveEntry(name: string, entry: string): Promise<void> {
|
|
106
|
+
return post('scoreboard.teamRemoveEntry', { name, entry });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function teamGetEntries(name: string): Promise<string[]> {
|
|
110
|
+
return post<string[]>('scoreboard.teamGetEntries', { name });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function setPlayerBoard(uuid: string): Promise<void> {
|
|
114
|
+
return post('scoreboard.setPlayerBoard', { uuid });
|
|
115
|
+
}
|
package/src/sound.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { post } from './task.js';
|
|
2
|
+
|
|
3
|
+
export function playSound(world: string, sound: string, x: number, y: number, z: number, volume?: number, pitch?: number): Promise<void> {
|
|
4
|
+
return post('world.playSound', { world, sound, x, y, z, volume, pitch });
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function stopSound(uuid: string, sound: string): Promise<void> {
|
|
8
|
+
return post('player.stopSound', { uuid, sound });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function stopAllSounds(uuid: string): Promise<void> {
|
|
12
|
+
return post('player.stopAllSounds', { uuid });
|
|
13
|
+
}
|
package/src/task.ts
CHANGED
|
@@ -6,16 +6,12 @@ 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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (s) e.stack += '\n --- cb registered at ---\n' + s;
|
|
14
|
-
}
|
|
15
|
-
reject(e);
|
|
16
|
-
} else {
|
|
17
|
-
reject(new Error(result.err));
|
|
9
|
+
const e = new Error(result.err);
|
|
10
|
+
if ($dev && typeof _getCurrentCbStack === 'function') {
|
|
11
|
+
const s = _getCurrentCbStack();
|
|
12
|
+
if (s) e.stack += '\n --- cb registered at ---\n' + s;
|
|
18
13
|
}
|
|
14
|
+
reject(e);
|
|
19
15
|
} else resolve(result as T);
|
|
20
16
|
});
|
|
21
17
|
const pld: Record<string, unknown> = { type, params, cb: cbId };
|
|
@@ -33,14 +29,6 @@ export function call<T = unknown>(
|
|
|
33
29
|
if (priority) pld.priority = priority;
|
|
34
30
|
const r = $send('task', pld);
|
|
35
31
|
if (r == null) return undefined as T;
|
|
36
|
-
if ((r as any)?.err)
|
|
37
|
-
if ($dev) throw new Error((r as any).err);
|
|
38
|
-
throw new Error(String((r as any).err));
|
|
39
|
-
}
|
|
32
|
+
if ((r as any)?.err) throw new Error((r as any).err);
|
|
40
33
|
return r as T;
|
|
41
34
|
}
|
|
42
|
-
|
|
43
|
-
/** Extract value from a buffer result (Map-like with get()) or a plain JSON object. */
|
|
44
|
-
export function val(obj: any, key: string): any {
|
|
45
|
-
return obj && typeof obj.get === 'function' ? obj.get(key) : obj?.[key];
|
|
46
|
-
}
|
package/src/world.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { call, post
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import { Location, LocationData } from './location.js';
|
|
3
3
|
import { Block } from './block.js';
|
|
4
4
|
|
|
5
|
+
interface WorldData {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
export class World {
|
|
6
10
|
static get(name: string): Promise<World | null> {
|
|
7
|
-
return post<
|
|
11
|
+
return post<WorldData>('world.get', { name }).then((d) => (d ? new World(d.name) : null));
|
|
8
12
|
}
|
|
9
13
|
static getSync(name: string): World | null {
|
|
10
|
-
const d = call<
|
|
11
|
-
return d ? new World(
|
|
14
|
+
const d = call<WorldData>('world.get', { name });
|
|
15
|
+
return d ? new World(d.name) : null;
|
|
12
16
|
}
|
|
13
17
|
static getAll(): Promise<World[]> {
|
|
14
|
-
return post<
|
|
15
|
-
(list || []).map((r: any) => new World(val(r, 'name')))
|
|
16
|
-
);
|
|
18
|
+
return post<WorldData[]>('world.getAll', {}).then((list) => list.map((r) => new World(r.name)));
|
|
17
19
|
}
|
|
18
20
|
static getAllSync(): World[] {
|
|
19
|
-
return
|
|
21
|
+
return call<WorldData[]>('world.getAll', {}).map((r) => new World(r.name));
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
constructor(public readonly name: string) {}
|
|
@@ -30,8 +32,8 @@ export class World {
|
|
|
30
32
|
get difficulty(): string { return call<string>('world.getDifficulty', { world: this.name }); }
|
|
31
33
|
set difficulty(v: string) { call('world.setDifficulty', { world: this.name, value: v }); }
|
|
32
34
|
get spawnLocation(): Location | null {
|
|
33
|
-
const r = call<
|
|
34
|
-
return r ? new Location(
|
|
35
|
+
const r = call<LocationData>('world.getSpawnLocation', { world: this.name });
|
|
36
|
+
return r ? new Location(r.x, r.y, r.z, r.yaw, r.pitch) : null;
|
|
35
37
|
}
|
|
36
38
|
set spawnLocation(v: Location) { call('world.setSpawnLocation', { world: this.name, ...v.toObject() }); }
|
|
37
39
|
|
|
@@ -60,13 +62,12 @@ export class World {
|
|
|
60
62
|
return call<string>('world.getBiome', { world: this.name, x, y, z });
|
|
61
63
|
}
|
|
62
64
|
getBlock(x: number, y: number, z: number): Promise<Block | null> {
|
|
63
|
-
return post<
|
|
64
|
-
r ? new Block(this.name,
|
|
65
|
-
);
|
|
65
|
+
return post<{ x: number; y: number; z: number; type: string }>('world.getBlock', { world: this.name, x, y, z })
|
|
66
|
+
.then((r) => (r ? new Block(this.name, r.x, r.y, r.z, r.type) : null));
|
|
66
67
|
}
|
|
67
68
|
getBlockSync(x: number, y: number, z: number): Block | null {
|
|
68
|
-
const r = call<
|
|
69
|
-
return r ? new Block(this.name,
|
|
69
|
+
const r = call<{ x: number; y: number; z: number; type: string }>('world.getBlock', { world: this.name, x, y, z });
|
|
70
|
+
return r ? new Block(this.name, r.x, r.y, r.z, r.type) : null;
|
|
70
71
|
}
|
|
71
72
|
setBlock(x: number, y: number, z: number, blockType: string): Promise<void> {
|
|
72
73
|
return post('world.setBlock', { world: this.name, x, y, z, blockType });
|
|
@@ -74,10 +75,18 @@ export class World {
|
|
|
74
75
|
setBlockSync(x: number, y: number, z: number, blockType: string): void {
|
|
75
76
|
call('world.setBlock', { world: this.name, x, y, z, blockType });
|
|
76
77
|
}
|
|
77
|
-
getEntities(): Promise<string[]> {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
getEntities(): Promise<string[]> {
|
|
79
|
+
return post<string[]>('world.getEntities', { world: this.name });
|
|
80
|
+
}
|
|
81
|
+
getEntitiesSync(): string[] {
|
|
82
|
+
return call<string[]>('world.getEntities', { world: this.name });
|
|
83
|
+
}
|
|
84
|
+
getPlayers(): Promise<string[]> {
|
|
85
|
+
return post<string[]>('world.getPlayers', { world: this.name });
|
|
86
|
+
}
|
|
87
|
+
getPlayersSync(): string[] {
|
|
88
|
+
return call<string[]>('world.getPlayers', { world: this.name });
|
|
89
|
+
}
|
|
81
90
|
getNearbyEntities(x: number, y: number, z: number, radius: number): Promise<string[]> {
|
|
82
91
|
return post<string[]>('world.getNearbyEntities', { world: this.name, x, y, z, radius });
|
|
83
92
|
}
|
|
@@ -108,4 +117,16 @@ export class World {
|
|
|
108
117
|
createExplosionSync(x: number, y: number, z: number, power?: number, fire?: boolean, breaks?: boolean): void {
|
|
109
118
|
call('world.createExplosion', { world: this.name, x, y, z, power, setFire: fire, breakBlocks: breaks });
|
|
110
119
|
}
|
|
120
|
+
spawnEntity(type: string, x: number, y: number, z: number): Promise<string | null> {
|
|
121
|
+
return post<string | null>('world.spawnEntity', { world: this.name, type, x, y, z });
|
|
122
|
+
}
|
|
123
|
+
spawnEntitySync(type: string, x: number, y: number, z: number): string | null {
|
|
124
|
+
return call<string | null>('world.spawnEntity', { world: this.name, type, x, y, z });
|
|
125
|
+
}
|
|
126
|
+
playSound(sound: string, x: number, y: number, z: number, volume?: number, pitch?: number): Promise<void> {
|
|
127
|
+
return post('world.playSound', { world: this.name, sound, x, y, z, volume, pitch });
|
|
128
|
+
}
|
|
129
|
+
playSoundSync(sound: string, x: number, y: number, z: number, volume?: number, pitch?: number): void {
|
|
130
|
+
call('world.playSound', { world: this.name, sound, x, y, z, volume, pitch });
|
|
131
|
+
}
|
|
111
132
|
}
|