Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Box3JS-NeoForge-1.21.1/docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand All @@ -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` 命令参考 |

Expand Down
5 changes: 1 addition & 4 deletions Box3JS-NeoForge-1.21.1/docs/api/README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
Original file line number Diff line number Diff line change
@@ -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!");
Loading