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
310 changes: 172 additions & 138 deletions Box3JS-NeoForge-1.21.1/README.md

Large diffs are not rendered by default.

299 changes: 166 additions & 133 deletions Box3JS-NeoForge-1.21.1/README_en.md

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Box3JS-NeoForge-1.21.1/docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { defineConfig } from "vitepress";

const cnNav = [
{ text: "首页", link: "/" },
{ text: "文档", link: "/overview" },
{ text: "指南", link: "/guide/README" },
{ text: "教程", link: "/tutorial/README" },
{ text: "API", link: "/api/README" },
];

const enNav = [
{ text: "Home", link: "/en/" },
{ text: "Docs", link: "/en/overview" },
{ text: "Guide", link: "/en/guide/README" },
{ text: "Tutorials", link: "/en/tutorial/README" },
{ text: "API", link: "/en/api/README" },
Expand Down Expand Up @@ -96,6 +98,7 @@ const enSidebar = [
text: "Get Started",
collapsed: false,
items: [
{ text: "Documentation Index", link: "/en/overview" },
{ text: "Overview", link: "/en/guide/README" },
{ text: "Getting Started", link: "/en/guide/getting-started" },
{ text: "Recipes", link: "/en/guide/recipes" },
Expand Down Expand Up @@ -181,9 +184,8 @@ export default defineConfig({
description: "Minecraft 的 JavaScript/TypeScript 脚本引擎",
lastUpdated: true,
cleanUrls: true,
ignoreDeadLinks: true,
ignoreDeadLinks: false,
base: "/box3js-mc/",
head: [["link", { rel: "icon", href: "/favicon.ico" }]],
locales: {
root: {
label: "简体中文",
Expand All @@ -206,7 +208,7 @@ export default defineConfig({
next: "下一页",
},
footer: {
message: "基于 MIT 许可证发布",
message: "基于 Apache License 2.0 发布",
},
},
},
Expand All @@ -231,7 +233,7 @@ export default defineConfig({
next: "Next page",
},
footer: {
message: "Released under the MIT License.",
message: "Released under the Apache License 2.0.",
},
},
},
Expand Down
46 changes: 46 additions & 0 deletions Box3JS-NeoForge-1.21.1/docs/api/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,52 @@ client.setFogEndDistance(50);
client.resetFog();
```

## 相机控制 (Camera Control)

### client.setCameraTarget(entityUuid)

将相机切换到目标实体的视角(旁观模式效果)。

```js
// 切换到指定实体的视角
client.setCameraTarget("550e8400-e29b-41d4-a716-446655440000");
```

### client.resetCamera()

重置相机到本地玩家视角。

```js
client.resetCamera();
```

## 方块查询 (Block Query)

### client.getBlockState(x, y, z)

在客户端查询指定坐标的方块状态(从渲染区块缓存读取)。空气或未加载区块返回 `null`。

```js
var block = client.getBlockState(0, 100, 0);
if (block) {
console.log("方块 ID: " + block.id);
}
```

## 渲染回调 (Render Callback)

### client.onRender(callback)

注册每 Render 帧回调(仅在 HUD 渲染阶段触发)。回调接收 `partialTick`(0–1,帧间插值因子)。

返回 `GameEventHandlerToken`,调用 `.cancel()` 取消。

```js
var token = client.onRender(function (partialTick) {
// 使用 partialTick 进行平滑自定义渲染
});
```

## 客户端完整示例

```js
Expand Down
52 changes: 52 additions & 0 deletions Box3JS-NeoForge-1.21.1/docs/api/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ zombie.hp = 100;

对实体造成 `amount` 点伤害(通用伤害类型,触发伤害事件)。

### entity.hurt(amount, source)

对实体造成伤害并指定伤害来源实体(用于击杀追踪)。`source` 为另一个 `GameEntity`。

### entity.heal(amount)

治疗实体 `amount` 点生命值(不超过 maxHp)。
Expand Down Expand Up @@ -325,6 +329,19 @@ entity.navigateTo(10, 100, 10, 1.0);
entity.navigateTo(target.position, 1.0);
```

### entity.teleportTo(x, y, z)

将实体传送到指定坐标。

### entity.teleportTo(pos)

⬆ GameVector3 重载。

```js
entity.teleportTo(0, 100, 0);
entity.teleportTo(new GameVector3(10, 100, 20));
```

### entity.lookAt(x, y, z)

实体面朝目标坐标。
Expand All @@ -338,6 +355,19 @@ entity.lookAt(0, 100, -10);
entity.lookAt(target.position);
```

## 粒子

⬆ MC 扩展。

### entity.spawnParticle(type, count, dx, dy, dz, speed)

在实体中心位置生成粒子。

```js
entity.spawnParticle("minecraft:flame", 10, 0.5, 0.5, 0.5, 0.1);
entity.spawnParticle("minecraft:cloud", 5, 0.2, 0, 0.2, 0);
```

## 药水效果

全部 ⬆ MC 扩展。
Expand Down Expand Up @@ -386,6 +416,20 @@ entity.setEquipment("chest", "minecraft:iron_chestplate");
entity.setEquipment("feet", "minecraft:leather_boots");
```

### entity.setEquipmentWithEnchants(slot, itemId, enchants)

给生物穿戴带附魔的装备。`enchants` 是 `{附魔ID: 等级}` 对象。

```js
entity.setEquipmentWithEnchants("mainhand", "minecraft:diamond_sword", {
"minecraft:sharpness": 5,
"minecraft:fire_aspect": 2,
});
entity.setEquipmentWithEnchants("head", "minecraft:diamond_helmet", {
"minecraft:protection": 4,
});
```

### entity.setDropChance(slot, chance)

设置装备槽物品的掉落概率,范围 0.0–1.0。`slot` 设为 `"all"` 可一次性设置所有槽位(包括主副手和四个护甲槽)。
Expand Down Expand Up @@ -426,6 +470,14 @@ entity.setAttribute("minecraft:generic.armor", 10);

销毁实体。如果通过 `setOnDestroy()` 设置了回调,会触发它。

### entity.remove()

立即从世界中移除实体,不触发回调。与 `destroy()` 不同,`remove()` 不会调用 `setOnDestroy` 注册的回调。

```js
entity.remove(); // 简单移除,无回调
```

### entity.setOnDestroy(handler)

设置销毁回调。`handler` 接收一个参数 `(entity)`。
Expand Down
16 changes: 16 additions & 0 deletions Box3JS-NeoForge-1.21.1/docs/api/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ var mx = input.getMouseX();
var my = input.getMouseY();
```

## input.getMouseDeltaX()

获取当前帧鼠标 X 轴增量(自上一帧的移动量)。

```js
var dx = input.getMouseDeltaX();
```

## input.getMouseDeltaY()

获取当前帧鼠标 Y 轴增量(自上一帧的移动量)。

```js
var dy = input.getMouseDeltaY();
```

## input.onMouseClick(callback)

注册鼠标按键回调。返回 `GameEventHandlerToken`,调用 `.cancel()` 取消。
Expand Down
6 changes: 6 additions & 0 deletions Box3JS-NeoForge-1.21.1/docs/api/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ var bounds = new GameBounds3(
| `bounds.closestPoint(v)` | `GameVector3` | 包围盒上离点 `v` 最近的点 |
| `bounds.move(offset)` | `GameBounds3` | 平移 `offset`,返回新包围盒 |
| `bounds.moveEq(offset)` | `GameBounds3` | 原地平移 `offset`,返回自身 |
| `bounds.volume()` | `number` | 包围盒体积 (宽×高×深) |
| `bounds.isEmpty()` | `boolean` | 包围盒是否为空 (任一维度 ≤ 0) |
| `bounds.equals(b)` | `boolean` | 判断两个包围盒是否完全相等 |
| `bounds.union(b)` | `GameBounds3` | 返回同时包围两者自身和 b 的最小盒 |
| `bounds.inflate(amount)` | `GameBounds3` | 每面向外扩展 amount(返回新对象) |
| `bounds.deflate(amount)` | `GameBounds3` | 每面向内收缩 amount(最小为 0) |

### 静态方法

Expand Down
83 changes: 83 additions & 0 deletions Box3JS-NeoForge-1.21.1/docs/api/player.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,64 @@ console.log(held.id, held.count); // "minecraft:diamond_sword" 1
player.clearInventory();
```

### player.removeItem(itemId, count)

从背包中移除指定数量的物品。返回实际移除的数量。

```js
// 移除 3 个铁锭
const removed = player.removeItem("minecraft:iron_ingot", 3);
console.log("实际移除: " + removed);
```

### player.setHeldSlot(slot)

设置玩家手持快捷栏槽位 (0–8)。

```js
player.setHeldSlot(0); // 切换到第 1 格
player.setHeldSlot(4); // 切换到第 5 格
```

### player.inventoryFreeSlots

只读 `number`。返回背包空余槽位数(0–36)。

```js
if (player.inventoryFreeSlots < 2) {
player.directMessage("背包空间不足!");
}
```

### player.hasItem(itemId)

检查背包中是否拥有某物品。

```js
if (player.hasItem("minecraft:diamond")) {
player.directMessage("你有一颗钻石!");
}
```

### player.getItemCount(itemId)

统计背包中某物品的总数量。

```js
var count = player.getItemCount("minecraft:iron_ingot");
console.log("背包里有 " + count + " 个铁锭");
```

### player.givePotion(itemId, potionType, count)

给予玩家指定类型的药水(带有 `PotionContents` 组件,适用于 1.21.1+)。

```js
player.givePotion("minecraft:potion", "minecraft:healing", 3);
player.givePotion("minecraft:splash_potion", "minecraft:poison", 1);
player.givePotion("minecraft:lingering_potion", "minecraft:regeneration", 2);
```

## 自定义容器 GUI

为玩家打开脚本控制的容器 GUI(类似箱子界面),可自定义格子内容、点击行为和关闭回调。
Expand Down Expand Up @@ -579,6 +637,31 @@ player.grantAdvancement("minecraft:adventure/kill_a_mob");
player.revokeAdvancement("minecraft:story/mine_stone");
```

## Bossbar

### player.showBossbar(name, text, progress, color)

向该玩家显示一个独立的 Bossbar。

| 参数 | 类型 | 说明 |
|------|------|------|
| `name` | string | Bossbar 唯一标识名,用于后续移除 |
| `text` | string | 显示文字 |
| `progress` | number | 进度条 (0–1) |
| `color` | string | 颜色:`"pink"` / `"blue"` / `"red"` / `"green"` / `"yellow"` / `"purple"` / `"white"` |

```js
player.showBossbar("boss_health", "§c§lBoss HP", 0.75, "red");
```

### player.removeBossbar(name)

移除指定名称的 Bossbar。

```js
player.removeBossbar("boss_health");
```

## Tab 列表

### player.setPlayerListName(name)
Expand Down
56 changes: 56 additions & 0 deletions Box3JS-NeoForge-1.21.1/docs/api/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,59 @@ ui.removeDrawText(1);
```js
ui.clearDrawTexts();
```

## ui.drawItem(id, x, y, itemId, scale?)

在屏幕上绘制物品图标(每帧持续绘制,直到调用 `removeDrawItem` 移除)。

| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `id` | number | (必需) | 图标 ID,用于后续移除或更新 |
| `x` | number | (必需) | X 坐标(GUI 缩放坐标系) |
| `y` | number | (必需) | Y 坐标(GUI 缩放坐标系) |
| `itemId` | string | (必需) | 物品 ID(如 `"minecraft:diamond"`) |
| `scale` | number | `16` | 图标尺寸(像素) |

返回图标 ID(与传入的 `id` 相同)。

```js
ui.drawItem(1, 10, 10, "minecraft:diamond");
ui.drawItem(2, 30, 10, "minecraft:golden_apple", 24);
```

## ui.removeDrawItem(id)

移除指定 ID 的绘制图标。

```js
ui.removeDrawItem(1);
```

## ui.drawRect(id, x, y, w, h, color, alpha?)

在屏幕上绘制矩形(每帧持续绘制,直到调用 `removeDrawRect` 移除)。

| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `id` | number | (必需) | 矩形 ID,用于后续移除或更新 |
| `x` | number | (必需) | 左上角 X 坐标 |
| `y` | number | (必需) | 左上角 Y 坐标 |
| `w` | number | (必需) | 宽度(像素) |
| `h` | number | (必需) | 高度(像素) |
| `color` | GameRGBColor | (必需) | 填充颜色(RGB) |
| `alpha` | number | `255` | 透明度 0–255 |

返回矩形 ID(与传入的 `id` 相同)。

```js
var red = new GameRGBColor(1, 0, 0);
ui.drawRect(1, 50, 50, 100, 60, red, 128); // 半透明红色矩形
```

## ui.removeDrawRect(id)

移除指定 ID 的绘制矩形。

```js
ui.removeDrawRect(1);
```
Loading
Loading