yeow-api 0.2.106 → 0.2.108
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/block.ts +64 -14
- package/src/core.ts +92 -0
- package/src/http.ts +18 -2
- package/src/index.ts +14 -90
- package/src/material.ts +31 -1
- package/src/server.ts +4 -0
- package/src/world.ts +25 -10
package/package.json
CHANGED
package/src/block.ts
CHANGED
|
@@ -2,32 +2,82 @@ import { call, post } from './task.js';
|
|
|
2
2
|
import type { TaskOptions } from './task.js';
|
|
3
3
|
import { Location } from './location.js';
|
|
4
4
|
import type { ItemStack } from './item.js';
|
|
5
|
+
import { Material } from './material.js';
|
|
5
6
|
|
|
7
|
+
/** 方块状态(Minecraft 原版键值对枚举,值统一为字符串)。 */
|
|
8
|
+
export interface BlockState {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Block —— 方块数据描述符 + 可选的世界位置(location)。
|
|
14
|
+
* 对应 Minecraft 原版的方块概念:类型 + 方块状态(键值对枚举,如
|
|
15
|
+
* `facing`、`waterlogged`、`level` 等,值统一为字符串)。
|
|
16
|
+
*
|
|
17
|
+
* **静态数据语义**:`type` / `state` / `location` 均为**获取时刻的快照**,
|
|
18
|
+
* 之后世界变化不会自动更新;需要最新状态请重新调用 `world.getBlock`。
|
|
19
|
+
*
|
|
20
|
+
* 两种来源:
|
|
21
|
+
* - `Block.of(type, state?)` —— 纯数据描述符,无 location(用于放置/比较)
|
|
22
|
+
* - `world.getBlock(x, y, z)` —— 世界中的方块,带 location(yaw/pitch 忽略,为 0)
|
|
23
|
+
*/
|
|
6
24
|
export class Block {
|
|
7
25
|
constructor(
|
|
8
|
-
public readonly world: string,
|
|
9
|
-
public readonly x: number,
|
|
10
|
-
public readonly y: number,
|
|
11
|
-
public readonly z: number,
|
|
12
26
|
public readonly type: string,
|
|
27
|
+
public readonly state?: BlockState,
|
|
28
|
+
/** 世界位置(由 world.getBlock 返回时存在;yaw/pitch 恒为 0)。 */
|
|
29
|
+
public readonly location?: Location,
|
|
13
30
|
) {}
|
|
14
31
|
|
|
15
|
-
|
|
16
|
-
return new
|
|
32
|
+
static of(type: string, state?: BlockState): Block {
|
|
33
|
+
return new Block(type, state);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 派生一个带状态的新描述符(原对象不变)。 */
|
|
37
|
+
withState(state: BlockState): Block {
|
|
38
|
+
return new Block(this.type, { ...(this.state ?? {}), ...state }, this.location);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 是否与给定类型/状态相同(忽略空状态差异)。 */
|
|
42
|
+
matches(type: string, state?: BlockState): boolean {
|
|
43
|
+
if (this.type !== type) return false;
|
|
44
|
+
if (!state || Object.keys(state).length === 0) return true;
|
|
45
|
+
const s = this.state ?? {};
|
|
46
|
+
for (const [k, v] of Object.entries(state)) {
|
|
47
|
+
if (s[k] !== v) return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
17
50
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
51
|
+
|
|
52
|
+
// ── 材料级静态判断(基于类型,委托 Material;不依赖位置/状态)──
|
|
53
|
+
|
|
54
|
+
isSolid(options?: TaskOptions): Promise<boolean> { return Material.isSolid(this.type, options); }
|
|
55
|
+
isSolidSync(options?: TaskOptions): boolean { return Material.isSolidSync(this.type, options); }
|
|
56
|
+
isLiquid(options?: TaskOptions): Promise<boolean> { return Material.isLiquid(this.type, options); }
|
|
57
|
+
isLiquidSync(options?: TaskOptions): boolean { return Material.isLiquidSync(this.type, options); }
|
|
58
|
+
isAir(options?: TaskOptions): Promise<boolean> { return Material.isAir(this.type, options); }
|
|
59
|
+
isAirSync(options?: TaskOptions): boolean { return Material.isAirSync(this.type, options); }
|
|
60
|
+
|
|
61
|
+
// ── 世界操作(需要 location)──
|
|
62
|
+
|
|
63
|
+
private get pos(): { world: string; x: number; y: number; z: number } | null {
|
|
64
|
+
const l = this.location;
|
|
65
|
+
if (!l || l.world === undefined) return null;
|
|
66
|
+
return { world: l.world, x: l.x, y: l.y, z: l.z };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 按该方块的位置自然破坏并掉落物品(需要 location)。 */
|
|
24
70
|
breakNaturally(tool?: ItemStack, options?: TaskOptions): Promise<boolean> {
|
|
25
|
-
const
|
|
71
|
+
const pos = this.pos;
|
|
72
|
+
if (!pos) return Promise.reject(new Error('block has no location (create with world.getBlock)'));
|
|
73
|
+
const p: Record<string, unknown> = { ...pos };
|
|
26
74
|
if (tool) p.item = tool;
|
|
27
75
|
return post<boolean>('block.breakNaturally', p, options);
|
|
28
76
|
}
|
|
29
77
|
breakNaturallySync(tool?: ItemStack, options?: TaskOptions): boolean {
|
|
30
|
-
const
|
|
78
|
+
const pos = this.pos;
|
|
79
|
+
if (!pos) throw new Error('block has no location (create with world.getBlock)');
|
|
80
|
+
const p: Record<string, unknown> = { ...pos };
|
|
31
81
|
if (tool) p.item = tool;
|
|
32
82
|
return call<boolean>('block.breakNaturally', p, options);
|
|
33
83
|
}
|
package/src/core.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference path="global.d.ts" />
|
|
2
|
+
|
|
3
|
+
export { call } from './task.js';
|
|
4
|
+
export { Location } from './location.js';
|
|
5
|
+
export { Player } from './player.js';
|
|
6
|
+
export { World } from './world.js';
|
|
7
|
+
export { Chunk, ChunkSnapshot, ChunkTopSnapshot } from './chunk.js';
|
|
8
|
+
export type { ChunkData } from './chunk.js';
|
|
9
|
+
export { Entity, LivingEntity } from './entity.js';
|
|
10
|
+
export type { BoundingBox } from './entity.js';
|
|
11
|
+
export { Block } from './block.js';
|
|
12
|
+
export type { BlockState } from './block.js';
|
|
13
|
+
export { Inventory } from './inventory.js';
|
|
14
|
+
export { registerCommand } from './command.js';
|
|
15
|
+
export type { CommandOptions, CommandPayload, CommandSender, ManualCompleter } from './command.js';
|
|
16
|
+
export { eventOn, eventOff } from './event.js';
|
|
17
|
+
export type {
|
|
18
|
+
PlayerJoinEvent, PlayerQuitEvent, PlayerChatEvent, PlayerMoveEvent,
|
|
19
|
+
PlayerInteractEvent, PlayerCommandEvent, PlayerDeathEvent, PlayerRespawnEvent,
|
|
20
|
+
PlayerTeleportEvent, PlayerItemConsumeEvent,
|
|
21
|
+
PlayerAdvancementDoneEvent, PlayerToggleSneakEvent, PlayerToggleFlightEvent,
|
|
22
|
+
PlayerDropItemEvent, PlayerPickupItemEvent, PlayerBucketFillEvent, PlayerBucketEmptyEvent,
|
|
23
|
+
PlayerExpChangeEvent, PlayerLevelChangeEvent, PlayerGameModeChangeEvent, FoodLevelChangeEvent,
|
|
24
|
+
EntityDamageEvent, EntityDeathEvent, EntitySpawnEvent, EntityExplodeEvent,
|
|
25
|
+
EntityRegainHealthEvent, EntityTargetEvent,
|
|
26
|
+
ProjectileLaunchEvent, ProjectileHitEvent,
|
|
27
|
+
BlockBreakEvent, BlockPlaceEvent, BlockFadeEvent, BlockGrowEvent, BlockSpreadEvent, BlockExplodeEvent,
|
|
28
|
+
InventoryOpenEvent, InventoryCloseEvent, InventoryClickEvent,
|
|
29
|
+
ServerPingEvent, ServerCommandEvent,
|
|
30
|
+
PlayerResourcePackStatusEvent,
|
|
31
|
+
} from './event.js';
|
|
32
|
+
export { onInit, onLoad, onUnload } from './lifecycle.js';
|
|
33
|
+
export {
|
|
34
|
+
broadcast, broadcastSync, dispatchCommand, dispatchCommandSync,
|
|
35
|
+
setMotd, setMotdSync, setIcon, setIconSync,
|
|
36
|
+
getMotd, getMotdSync, getVersion, getVersionSync,
|
|
37
|
+
getTps, getTpsSync, getMaxPlayers, getMaxPlayersSync,
|
|
38
|
+
} from './server.js';
|
|
39
|
+
export type { TpsInfo } from './server.js';
|
|
40
|
+
export {
|
|
41
|
+
fs,
|
|
42
|
+
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
43
|
+
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
44
|
+
appendFile, appendFileSync,
|
|
45
|
+
exists, existsSync, isDirectory, isDirectorySync,
|
|
46
|
+
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
47
|
+
} from './fs.js';
|
|
48
|
+
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
49
|
+
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
50
|
+
extract as assetsExtract, extractSync as assetsExtractSync,
|
|
51
|
+
extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
|
|
52
|
+
export { path } from './path.js';
|
|
53
|
+
export { listen, respond, close, request, requestSync } from './http.js';
|
|
54
|
+
export { logError } from './log-error.js';
|
|
55
|
+
export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
|
|
56
|
+
export type { ItemStack } from './item.js';
|
|
57
|
+
export type { PotionEffect } from './potion.js';
|
|
58
|
+
export { addPotionEffect, removePotionEffect, clearPotionEffects, getActivePotionEffects } from './potion.js';
|
|
59
|
+
export { playSound, stopSound, stopAllSounds } from './sound.js';
|
|
60
|
+
export type { ParticleOptions } from './particle.js';
|
|
61
|
+
export { spawnParticle } from './particle.js';
|
|
62
|
+
export { get as pdcGet, set as pdcSet, has as pdcHas, remove as pdcRemove, keys as pdcKeys,
|
|
63
|
+
getBlock as pdcGetBlock, setBlock as pdcSetBlock, hasBlock as pdcHasBlock, removeBlock as pdcRemoveBlock } from './pdc.js';
|
|
64
|
+
export { createBossBar, destroy as destroyBossBar,
|
|
65
|
+
setTitle as setBossBarTitle, setProgress as setBossBarProgress,
|
|
66
|
+
setColor as setBossBarColor, setStyle as setBossBarStyle,
|
|
67
|
+
setVisible as setBossBarVisible, addPlayer as addBossBarPlayer,
|
|
68
|
+
removePlayer as removeBossBarPlayer, removeAll as removeAllBossBarPlayers,
|
|
69
|
+
addFlag as addBossBarFlag, removeFlag as removeBossBarFlag } from './bossbar.js';
|
|
70
|
+
export type { BossBarOptions } from './bossbar.js';
|
|
71
|
+
export { createGUI, destroy as destroyGUI, open as openGUI,
|
|
72
|
+
close as closeGUI, setItem as setGUIItem, fill as fillGUI, clear as clearGUI } from './gui.js';
|
|
73
|
+
export type { AdvancementProgress } from './advancement.js';
|
|
74
|
+
export { grant as grantAdvancement, revoke as revokeAdvancement,
|
|
75
|
+
getProgress as getAdvancementProgress, awardCriteria, revokeCriteria } from './advancement.js';
|
|
76
|
+
export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForItem } from './recipe.js';
|
|
77
|
+
export type {
|
|
78
|
+
ObjectiveInfo, TeamInfo,
|
|
79
|
+
} from './scoreboard.js';
|
|
80
|
+
export { createBoard as createScoreboard, deleteBoard as deleteScoreboard,
|
|
81
|
+
createObjective, deleteObjective, getObjectives,
|
|
82
|
+
setObjectiveDisplay, getScore, setScore, resetScore,
|
|
83
|
+
createTeam, deleteTeam, getTeam, getTeams,
|
|
84
|
+
setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
|
|
85
|
+
setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
|
|
86
|
+
teamAddEntry, teamRemoveEntry, teamGetEntries,
|
|
87
|
+
setPlayerBoard } from './scoreboard.js';
|
|
88
|
+
export { Material, getMaterials, getBlocks, getItems } from './material.js';
|
|
89
|
+
export type { MaterialInfo } from './material.js';
|
|
90
|
+
export { registerService, registerNativeService, request as serviceRequest, subscribe as serviceSubscribe, publish as servicePublish } from './service.js';
|
|
91
|
+
export type { ServiceResult, NativeServiceResult } from './service.js';
|
|
92
|
+
export { log, Logger } from './log.js';
|
package/src/http.ts
CHANGED
|
@@ -48,11 +48,27 @@ _registerCallback(() => {
|
|
|
48
48
|
_servers.clear();
|
|
49
49
|
}, { persistent: true });
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* 异步 HTTP 请求(不阻塞 JS 线程)——底层走 `http:requestAsync` 通道。
|
|
53
|
+
* 推荐用于事件处理器与高频场景。需要同步阻塞返回的用 `requestSync`。
|
|
54
|
+
*/
|
|
51
55
|
export function request(url: string, opts: Record<string, unknown> = {}): Promise<HttpResult> {
|
|
52
56
|
return new Promise((resolve, reject) => {
|
|
57
|
+
const cbId = _registerCallback((result: unknown) => {
|
|
58
|
+
if ((result as any)?.err) reject(new Error((result as any).err));
|
|
59
|
+
else resolve(result as HttpResult);
|
|
60
|
+
});
|
|
53
61
|
try {
|
|
54
|
-
|
|
55
|
-
resolve(result);
|
|
62
|
+
_sendHttp({ t: 'requestAsync', p: { url, ...opts, cb: String(cbId) } });
|
|
56
63
|
} catch (e) { reject(e); }
|
|
57
64
|
});
|
|
58
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 同步 HTTP 请求(**阻塞 JS 线程**直到响应返回)——底层走 `http:request` 通道。
|
|
69
|
+
* 阻塞期间 JS 线程无法处理事件/命令/回调(可能触发 event.timeout 告警);
|
|
70
|
+
* 仅适合低频、非事件上下文。事件处理器或高频场景请用 `request`(异步)或全局 `fetch`。
|
|
71
|
+
*/
|
|
72
|
+
export function requestSync(url: string, opts: Record<string, unknown> = {}): HttpResult {
|
|
73
|
+
return _sendHttp({ t: 'request', p: { url, ...opts } });
|
|
74
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,91 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Yeow API 入口。
|
|
3
|
+
*
|
|
4
|
+
* 全部具名导出来自 `core.ts`(与历史导出面完全一致);默认导出 `Yeow` 为
|
|
5
|
+
* 聚合全部具名导出的**大对象**——不推荐使用:默认导入会破坏 tree-shaking,
|
|
6
|
+
* 显著增大插件体积,仅适用于简化动态执行含任意逻辑的代码。请按需命名导入。
|
|
7
|
+
*/
|
|
8
|
+
export * from './core.js';
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export { Entity, LivingEntity } from './entity.js';
|
|
10
|
-
export type { BoundingBox } from './entity.js';
|
|
11
|
-
export { Block } from './block.js';
|
|
12
|
-
export { Inventory } from './inventory.js';
|
|
13
|
-
export { registerCommand } from './command.js';
|
|
14
|
-
export type { CommandOptions, CommandPayload, CommandSender, ManualCompleter } from './command.js';
|
|
15
|
-
export { eventOn, eventOff } from './event.js';
|
|
16
|
-
export type {
|
|
17
|
-
PlayerJoinEvent, PlayerQuitEvent, PlayerChatEvent, PlayerMoveEvent,
|
|
18
|
-
PlayerInteractEvent, PlayerCommandEvent, PlayerDeathEvent, PlayerRespawnEvent,
|
|
19
|
-
PlayerTeleportEvent, PlayerItemConsumeEvent,
|
|
20
|
-
PlayerAdvancementDoneEvent, PlayerToggleSneakEvent, PlayerToggleFlightEvent,
|
|
21
|
-
PlayerDropItemEvent, PlayerPickupItemEvent, PlayerBucketFillEvent, PlayerBucketEmptyEvent,
|
|
22
|
-
PlayerExpChangeEvent, PlayerLevelChangeEvent, PlayerGameModeChangeEvent, FoodLevelChangeEvent,
|
|
23
|
-
EntityDamageEvent, EntityDeathEvent, EntitySpawnEvent, EntityExplodeEvent,
|
|
24
|
-
EntityRegainHealthEvent, EntityTargetEvent,
|
|
25
|
-
ProjectileLaunchEvent, ProjectileHitEvent,
|
|
26
|
-
BlockBreakEvent, BlockPlaceEvent, BlockFadeEvent, BlockGrowEvent, BlockSpreadEvent, BlockExplodeEvent,
|
|
27
|
-
InventoryOpenEvent, InventoryCloseEvent, InventoryClickEvent,
|
|
28
|
-
ServerPingEvent, ServerCommandEvent,
|
|
29
|
-
PlayerResourcePackStatusEvent,
|
|
30
|
-
} from './event.js';
|
|
31
|
-
export { onInit, onLoad, onUnload } from './lifecycle.js';
|
|
32
|
-
export {
|
|
33
|
-
broadcast, broadcastSync, dispatchCommand, dispatchCommandSync,
|
|
34
|
-
setMotd, setMotdSync, setIcon, setIconSync,
|
|
35
|
-
getMotd, getMotdSync, getVersion, getVersionSync,
|
|
36
|
-
getTps, getTpsSync,
|
|
37
|
-
} from './server.js';
|
|
38
|
-
export type { TpsInfo } from './server.js';
|
|
39
|
-
export {
|
|
40
|
-
fs,
|
|
41
|
-
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
42
|
-
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
43
|
-
appendFile, appendFileSync,
|
|
44
|
-
exists, existsSync, isDirectory, isDirectorySync,
|
|
45
|
-
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
46
|
-
} from './fs.js';
|
|
47
|
-
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
48
|
-
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
49
|
-
extract as assetsExtract, extractSync as assetsExtractSync,
|
|
50
|
-
extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
|
|
51
|
-
export { path } from './path.js';
|
|
52
|
-
export { listen, respond, close, request } from './http.js';
|
|
53
|
-
export { logError } from './log-error.js';
|
|
54
|
-
export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
|
|
55
|
-
export type { ItemStack } from './item.js';
|
|
56
|
-
export type { PotionEffect } from './potion.js';
|
|
57
|
-
export { addPotionEffect, removePotionEffect, clearPotionEffects, getActivePotionEffects } from './potion.js';
|
|
58
|
-
export { playSound, stopSound, stopAllSounds } from './sound.js';
|
|
59
|
-
export type { ParticleOptions } from './particle.js';
|
|
60
|
-
export { spawnParticle } from './particle.js';
|
|
61
|
-
export { get as pdcGet, set as pdcSet, has as pdcHas, remove as pdcRemove, keys as pdcKeys,
|
|
62
|
-
getBlock as pdcGetBlock, setBlock as pdcSetBlock, hasBlock as pdcHasBlock, removeBlock as pdcRemoveBlock } from './pdc.js';
|
|
63
|
-
export { createBossBar, destroy as destroyBossBar,
|
|
64
|
-
setTitle as setBossBarTitle, setProgress as setBossBarProgress,
|
|
65
|
-
setColor as setBossBarColor, setStyle as setBossBarStyle,
|
|
66
|
-
setVisible as setBossBarVisible, addPlayer as addBossBarPlayer,
|
|
67
|
-
removePlayer as removeBossBarPlayer, removeAll as removeAllBossBarPlayers,
|
|
68
|
-
addFlag as addBossBarFlag, removeFlag as removeBossBarFlag } from './bossbar.js';
|
|
69
|
-
export type { BossBarOptions } from './bossbar.js';
|
|
70
|
-
export { createGUI, destroy as destroyGUI, open as openGUI,
|
|
71
|
-
close as closeGUI, setItem as setGUIItem, fill as fillGUI, clear as clearGUI } from './gui.js';
|
|
72
|
-
export type { AdvancementProgress } from './advancement.js';
|
|
73
|
-
export { grant as grantAdvancement, revoke as revokeAdvancement,
|
|
74
|
-
getProgress as getAdvancementProgress, awardCriteria, revokeCriteria } from './advancement.js';
|
|
75
|
-
export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForItem } from './recipe.js';
|
|
76
|
-
export type {
|
|
77
|
-
ObjectiveInfo, TeamInfo,
|
|
78
|
-
} from './scoreboard.js';
|
|
79
|
-
export { createBoard as createScoreboard, deleteBoard as deleteScoreboard,
|
|
80
|
-
createObjective, deleteObjective, getObjectives,
|
|
81
|
-
setObjectiveDisplay, getScore, setScore, resetScore,
|
|
82
|
-
createTeam, deleteTeam, getTeam, getTeams,
|
|
83
|
-
setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
|
|
84
|
-
setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
|
|
85
|
-
teamAddEntry, teamRemoveEntry, teamGetEntries,
|
|
86
|
-
setPlayerBoard } from './scoreboard.js';
|
|
87
|
-
export { getMaterials, getBlocks, getItems } from './material.js';
|
|
88
|
-
export type { MaterialInfo } from './material.js';
|
|
89
|
-
export { registerService, registerNativeService, request as serviceRequest, subscribe as serviceSubscribe, publish as servicePublish } from './service.js';
|
|
90
|
-
export type { ServiceResult, NativeServiceResult } from './service.js';
|
|
91
|
-
export { log, Logger } from './log.js';
|
|
10
|
+
import * as api from './core.js';
|
|
11
|
+
|
|
12
|
+
const Yeow = { ...api };
|
|
13
|
+
|
|
14
|
+
export default Yeow;
|
|
15
|
+
export { Yeow };
|
package/src/material.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { post } from './task.js';
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import type { TaskOptions } from './task.js';
|
|
3
3
|
|
|
4
4
|
export interface MaterialInfo {
|
|
@@ -34,3 +34,33 @@ export async function getItems(options?: TaskOptions): Promise<string[]> {
|
|
|
34
34
|
Object.freeze(_items);
|
|
35
35
|
return _items;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Material —— 材料级静态判断对象(不依赖坐标/状态)。
|
|
40
|
+
* 基于方块类型(material)判断其固有属性:固体/液体/空气。
|
|
41
|
+
*/
|
|
42
|
+
export const Material = {
|
|
43
|
+
/** 是否为固体方块(基于类型,状态不影响)。 */
|
|
44
|
+
isSolid(type: string, options?: TaskOptions): Promise<boolean> {
|
|
45
|
+
return post<boolean>('material.isSolid', { type }, options);
|
|
46
|
+
},
|
|
47
|
+
isSolidSync(type: string, options?: TaskOptions): boolean {
|
|
48
|
+
return call<boolean>('material.isSolid', { type }, options);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/** 是否为液体(水 / 熔岩)。 */
|
|
52
|
+
isLiquid(type: string, options?: TaskOptions): Promise<boolean> {
|
|
53
|
+
return post<boolean>('material.isLiquid', { type }, options);
|
|
54
|
+
},
|
|
55
|
+
isLiquidSync(type: string, options?: TaskOptions): boolean {
|
|
56
|
+
return call<boolean>('material.isLiquid', { type }, options);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/** 是否为空气(空方块)。 */
|
|
60
|
+
isAir(type: string, options?: TaskOptions): Promise<boolean> {
|
|
61
|
+
return post<boolean>('material.isAir', { type }, options);
|
|
62
|
+
},
|
|
63
|
+
isAirSync(type: string, options?: TaskOptions): boolean {
|
|
64
|
+
return call<boolean>('material.isAir', { type }, options);
|
|
65
|
+
},
|
|
66
|
+
};
|
package/src/server.ts
CHANGED
|
@@ -28,3 +28,7 @@ export interface TpsInfo {
|
|
|
28
28
|
*/
|
|
29
29
|
export function getTps(options?: TaskOptions): Promise<TpsInfo> { return post<TpsInfo>('server.getTps', {}, options); }
|
|
30
30
|
export function getTpsSync(options?: TaskOptions): TpsInfo { return call<TpsInfo>('server.getTps', {}, options); }
|
|
31
|
+
|
|
32
|
+
/** 服务器最大玩家数。 */
|
|
33
|
+
export function getMaxPlayers(options?: TaskOptions): Promise<number> { return post<number>('server.getMaxPlayers', {}, options); }
|
|
34
|
+
export function getMaxPlayersSync(options?: TaskOptions): number { return call<number>('server.getMaxPlayers', {}, options); }
|
package/src/world.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { call, post } from './task.js';
|
|
|
2
2
|
import type { TaskOptions } from './task.js';
|
|
3
3
|
import { Location, LocationData } from './location.js';
|
|
4
4
|
import { Block } from './block.js';
|
|
5
|
+
import type { BlockState } from './block.js';
|
|
5
6
|
import { Chunk, ChunkData } from './chunk.js';
|
|
6
7
|
|
|
7
8
|
interface WorldData {
|
|
@@ -100,18 +101,32 @@ export class World {
|
|
|
100
101
|
return call<string>('world.getBiome', { world: this.name, x, y, z }, options);
|
|
101
102
|
}
|
|
102
103
|
getBlock(x: number, y: number, z: number, options?: TaskOptions): Promise<Block | null> {
|
|
103
|
-
return post<{ x: number; y: number; z: number; type: string }>('world.getBlock', { world: this.name, x, y, z }, options)
|
|
104
|
-
.then((r) => (r ? new Block(
|
|
104
|
+
return post<{ world: string; x: number; y: number; z: number; type: string; state: BlockState }>('world.getBlock', { world: this.name, x, y, z }, options)
|
|
105
|
+
.then((r) => (r ? new Block(r.type, r.state, new Location(r.x, r.y, r.z, 0, 0, r.world)) : null));
|
|
105
106
|
}
|
|
106
107
|
getBlockSync(x: number, y: number, z: number, options?: TaskOptions): Block | null {
|
|
107
|
-
const r = call<{ x: number; y: number; z: number; type: string }>('world.getBlock', { world: this.name, x, y, z }, options);
|
|
108
|
-
return r ? new Block(
|
|
109
|
-
}
|
|
110
|
-
setBlock(x: number, y: number, z: number,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
const r = call<{ world: string; x: number; y: number; z: number; type: string; state: BlockState }>('world.getBlock', { world: this.name, x, y, z }, options);
|
|
109
|
+
return r ? new Block(r.type, r.state, new Location(r.x, r.y, r.z, 0, 0, r.world)) : null;
|
|
110
|
+
}
|
|
111
|
+
setBlock(x: number, y: number, z: number, block: Block | string, options?: TaskOptions): Promise<void> {
|
|
112
|
+
const p: Record<string, unknown> = { world: this.name, x, y, z };
|
|
113
|
+
if (typeof block === 'string') {
|
|
114
|
+
p.blockType = block;
|
|
115
|
+
} else {
|
|
116
|
+
p.blockType = block.type;
|
|
117
|
+
if (block.state && Object.keys(block.state).length > 0) p.state = block.state;
|
|
118
|
+
}
|
|
119
|
+
return post('world.setBlock', p, options);
|
|
120
|
+
}
|
|
121
|
+
setBlockSync(x: number, y: number, z: number, block: Block | string, options?: TaskOptions): void {
|
|
122
|
+
const p: Record<string, unknown> = { world: this.name, x, y, z };
|
|
123
|
+
if (typeof block === 'string') {
|
|
124
|
+
p.blockType = block;
|
|
125
|
+
} else {
|
|
126
|
+
p.blockType = block.type;
|
|
127
|
+
if (block.state && Object.keys(block.state).length > 0) p.state = block.state;
|
|
128
|
+
}
|
|
129
|
+
call('world.setBlock', p, options);
|
|
115
130
|
}
|
|
116
131
|
getEntities(options?: TaskOptions): Promise<string[]> {
|
|
117
132
|
return post<string[]>('world.getEntities', { world: this.name }, options);
|