From 8be8d8f17092e73e98fdb19a02fe8b12da816224 Mon Sep 17 00:00:00 2001 From: viyrs <2991883280@qq.com> Date: Fri, 8 May 2026 18:51:13 +0800 Subject: [PATCH] =?UTF-8?q?docs(api):=20=E6=9B=B4=E6=96=B0=20API=20?= =?UTF-8?q?=E6=96=87=E6=A1=A3=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20Box3=20=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将中英文文档中 `db` API 的标识从 ⬆ MC 改为 ✅ Box3 - 移除 `console`、`require(id)` 和 `sleep(ms)` 函数的重复条目 - 修复表格格式中的轻微间距问题 refactor(template): 优化 app.ts 模板,改进代码风格 - 将函数声明替换为箭头函数,保持风格一致 - 使用模板字符串替代字符串拼接 - 添加描述性注释,说明每项功能的作用 - 将变量声明从 'var' 更新为 'const'/'let' - 将消息中的项目名称占位符从 'PROJECT_NAME' 改为 'b' --- Box3JS-NeoForge-1.21.1/docs/api/README.md | 7 +-- Box3JS-NeoForge-1.21.1/docs/api/README_en.md | 5 +- .../assets/box3js/template/src/app.ts | 59 ++++++++++--------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/Box3JS-NeoForge-1.21.1/docs/api/README.md b/Box3JS-NeoForge-1.21.1/docs/api/README.md index b775624..98fc96c 100644 --- a/Box3JS-NeoForge-1.21.1/docs/api/README.md +++ b/Box3JS-NeoForge-1.21.1/docs/api/README.md @@ -29,10 +29,7 @@ console.log("脚本已加载"); | `player` | ✅ Box3 | 玩家包装(通过 `entity.player` 获取),见 [player.md](player.md) | | `voxels` | ✅ Box3 | 方块操作,见 [voxels.md](voxels.md) | | `storage` | ✅ Box3 | 数据持久化,见 [storage.md](storage.md) | -| `db` | ⬆ MC | SQLite 数据库,见 [database.md](database.md) | -| `console` | ⬆ MC | `console.log/debug/warn/error/assert/clear` | -| `require(id)` | ⬆ MC | CommonJS 模块导入,见下方模块说明 | -| `sleep(ms)` | ⬆ MC | 阻塞线程指定毫秒(运行时会将值限制为最多 10ms) | +| `db` | ✅ Box3 | SQLite 数据库,见 [database.md](database.md) | | `GameVector3` | ✅ Box3 | 三维向量,见 [math.md](math.md) | | `GameBounds3` | ✅ Box3 | 包围盒,见 [math.md](math.md) | | `GameRGBColor` | ✅ Box3 | RGB 颜色,见 [math.md](math.md) | @@ -55,7 +52,7 @@ console.log("脚本已加载"); | [player.md](player.md) | 背包、消息、飞行、游戏模式、传送、命令 | | [voxels.md](voxels.md) | 方块读写、区域填充、刷怪笼 | | [storage.md](storage.md) | 数据持久化存储 | -| [database.md](database.md) | SQLite 数据库 | +| [database.md](database.md) | SQLite 数据库 | | [math.md](math.md) | Vector3、Bounds3、Color、Quaternion | | [commands.md](commands.md) | `/box3script` 命令参考 | diff --git a/Box3JS-NeoForge-1.21.1/docs/api/README_en.md b/Box3JS-NeoForge-1.21.1/docs/api/README_en.md index 1129400..6dd7b9a 100644 --- a/Box3JS-NeoForge-1.21.1/docs/api/README_en.md +++ b/Box3JS-NeoForge-1.21.1/docs/api/README_en.md @@ -29,10 +29,7 @@ console.log("Script loaded"); | `player` | ✅ Box3 | Player wrapper (via `entity.player`), see [player.md](player.md) | | `voxels` | ✅ Box3 | Block operations, see [voxels.md](voxels.md) | | `storage` | ✅ Box3 | Data persistence, see [storage.md](storage.md) | -| `db` | ⬆ MC | SQLite database, see [database_en.md](database_en.md) | -| `console` | ⬆ MC | `console.log/debug/warn/error/assert/clear` | -| `require(id)` | ⬆ MC | CommonJS module import, see module section below | -| `sleep(ms)` | ⬆ MC | Block the thread for the given milliseconds (runtime clamps to at most 10ms) | +| `db` | ✅ Box3 | SQLite database, see [database_en.md](database_en.md) | | `GameVector3` | ✅ Box3 | 3D vector, see [math.md](math.md) | | `GameBounds3` | ✅ Box3 | Bounding box, see [math.md](math.md) | | `GameRGBColor` | ✅ Box3 | RGB color, see [math.md](math.md) | diff --git a/Box3JS-NeoForge-1.21.1/src/main/resources/assets/box3js/template/src/app.ts b/Box3JS-NeoForge-1.21.1/src/main/resources/assets/box3js/template/src/app.ts index 040a2c9..5f576cf 100644 --- a/Box3JS-NeoForge-1.21.1/src/main/resources/assets/box3js/template/src/app.ts +++ b/Box3JS-NeoForge-1.21.1/src/main/resources/assets/box3js/template/src/app.ts @@ -1,38 +1,41 @@ -// ═══════════════════════════════════════════════════ -// PROJECT_NAME -// ═══════════════════════════════════════════════════ +// Welcome players when they join the server. +world.onPlayerJoin((entity: GamePlayerEntity) => { + const p = entity.player; -// 玩家加入时欢迎 -world.onPlayerJoin(function (entity: GameEntity) { - var p = entity.player; - if (!p) return; - world.say("§e" + p.name + " §7进入了服务器"); - p.directMessage("§6欢迎来到 §ePROJECT_NAME §6!"); - p.directMessage("§7输入 §e!hello §7打个招呼吧"); + world.say(`§e${p.name} §7joined the server`); + p.directMessage("§6Welcome to §eb §6!"); + p.directMessage("§7Type §e!hello §7to say hi"); }); -// 聊天命令 -world.onChat(function (entity: GameEntity, message: string, _tick: number) { - var p = entity.player; - if (!p) return; +// Handle chat commands sent by players. +world.onChat((entity: GamePlayerEntity, message: string, _tick: number) => { + const p = entity.player; - if (message === "!hello") { - world.say("§e" + p.name + "§7: Hello World!"); - } + // Respond to a simple hello command. + if (message === "!hello") { + world.say(`§e${p.name}§7: Hello World!`); + } }); -// 每 5 秒公告一次 -var announceTicks = 0; +// Broadcast a periodic status message every 5 seconds (100 ticks). +let announceTicks = 0; world.onTick(function () { - announceTicks++; - if (announceTicks >= 100) { - announceTicks = 0; - var players = world.querySelectorAll("*"); - for (var i = 0; i < players.length; i++) { - var p = players[i].player; - if (p) p.actionBar("§a⚡ PROJECT_NAME 运行中 §7| §f" + players.length + " §7人在线"); - } + announceTicks++; + + if (announceTicks >= 100) { + announceTicks = 0; + + // Count online entities and show runtime status in each player's action bar. + const players = world.querySelectorAll("*"); + for (let i = 0; i < players.length; i++) { + const p = players[i].player; + if (p) { + p.actionBar( + `§a⚡ b is running §7| §f${String(players.length)} §7online`, + ); + } } + } }); -console.log("[PROJECT_NAME] loaded — Hello World!"); +console.log("[b] loaded - Hello World!");