scene.json 格式
scene.json 是包含场景 Actor · 动画片段 · 世界逻辑规则的 JSON 文件。编辑器在生成 .npbuild 时写入此文件(导出窗口的 包含场景 ),服务器插件 NPBridge(从 2.0 起包含旧版 NP Scene)读取并执行。实时连接期间,编辑器以同一格式直接发送到服务器。格式名称为 np-scene,版本为 1。
| 阶段 | 作用 |
|---|---|
| 1. 编辑器 | 将 Actor · 片段 · 规则保存到世界文件(.npworld)中。坐标为编辑器世界坐标。 |
| 2. 导出 | 为每个 .npbuild 分块写入 scene.json。坐标改为以该分块的最小角(origin)为基准。 |
| 3. 服务器安装 | 安装 .npbuild 时应用旋转 · 翻转 · 位置,转换为服务器坐标。 |
| 4. 服务器执行 | NPBridge 创建 Actor 并执行规则。 |
- 自行编写服务器端处理程序时,按本文档的键名和值格式原样对应。插件添加的 type 的字段也按同一规则保存(添加世界逻辑 type)。
- 对使用了 0.10.2 流程控制动作(
gate·stop·do_once·flip_flop·switch)和数学函数inverse_lerp·wrap·snap的规则,编辑器会加上min_bridge: "2.0.8"。先将服务器升级到 NPBridge 2.0.8 及以上,再进行部署。 - 规则节点中的
_graph字段是逻辑图节点的位置。手动修改 JSON 时无需删除,服务器会忽略它。
{ "format": "np-scene", "version": 1, "origin": [120, 64, -40], "actors": [ … ], "animations": [ … ], "logic": [ … ], "variables": [ … ], "enums": [ … ], "types": [ … ]}| 键 | 类型 | 必有 | 含义 |
|---|---|---|---|
format | 字符串 | 是 | 始终为 "np-scene" |
version | 数字 | 是 | 始终为 1 |
origin | [x,y,z] | 是 | 此分块最小角的编辑器坐标。仅供参考。 |
actors | 数组 | 是 | 场景 Actor |
animations | 数组 | 是 | 动画片段(序列器) |
logic | 数组 | 是 | 世界逻辑规则 |
variables | 数组 | 有声明时 | 变量声明 |
enums | 数组 | 有定义时 | enum |
types | 数组 | 有定义时 | 数据类型 |
没有任何 Actor · 片段 · 规则时,.npbuild 中不写入 scene.json。
- 所有位置(
pos、路径点、位置关键帧、所选方块格)都以origin为基准,即编辑器坐标减去origin后的值。 - 进入某个分块的 Actor 是
pos的 X · Z 位于该分块范围内的 Actor。不考虑高度。 - 不属于任何分块的 Actor 会产生导出警告。
rot为[yaw, pitch, roll](度),采用 Minecraft 方式:yaw 0 = 南(+Z),90 = 西(−X),pitch + = 向下。
{"id": "trig_gate", "kind": "trigger", "name": "城门前", "pos": [10, 64, 5], "rot": [0, 0, 0], "size": [6, 4, 3], "shape": "box", "tags": ["gate"], "props": {}}| 键 | 类型 | 含义 |
|---|---|---|
id | 字符串 | 世界内唯一的名称。英文字母 · 数字 · _ . -,1~64 个字符 |
kind | 字符串 | 见下表 |
name | 字符串 | 显示名称 |
pos | [x,y,z] | 位置(含义因种类而异 — 见下表) |
rot | [yaw,pitch,roll] | 方向。trigger 始终为 [0,0,0] |
scale | [x,y,z] | 倍率。仅 display · text |
size | [x,y,z] | 整体大小(方块)。仅 trigger · blocker · particles |
shape | 字符串 | box · sphere(size = 直径)。trigger · particles 可以使用 sphere,blocker 始终为 box |
tags | 字符串数组 | 标签。为空时为 [] |
parent | 字符串 | 附加到的父 Actor 的 id(仅在有父 Actor 时) |
props | 对象 | 各种类的属性 |
在编辑器中设为“仅编辑器”的 Actor 不会导出。
kind | pos 含义 | 主要 props |
|---|---|---|
trigger | 区域中心 | (无)· 来自交互组件时为 interactable: true |
spawn | 脚下 | role(player · npc · mob · custom)· entity(npc · mob 时) |
display | 模型中心 | display(item · block)· item_model 或 block · visible · glow · glow_color · billboard(fixed · vertical · horizontal · center)· brightness(-1 = 周围光照,0~15) |
text | 文字中心 | text · color · background(#aarrggbb)· billboard · visible · shadow · see_through · alignment(center · left · right)· line_width |
light | 所在格(floor(pos)) | level(0~15)· visible |
camera | 眼睛 | fov |
path | 第一个点 | points([[x,y,z], …])· closed |
sound | 声音位置 | event · radius · mode(random · loop)· interval_min · interval_max · volume · pitch_min · pitch_max · time(any · day · night)· underground_only |
blocker | 框中心 | mode(barrier · push)· affects(players · all)· visible_in_editor |
particles | 范围中心 | preset(fireflies · sparkles · spores · embers · snow · magic_dust · waterfall_mist)· particle(为空时为预设粒子)· color · density(0~1)· speed · size · time(always · night · day)· view_distance · max_per_second |
- 服务器忽略未知的
props字段。 visible: false的display·text·light以隐藏状态开始,通过规则动作actor_show显示。blocker的barrier用 barrier 方块填满框内的空格。push不放方块,而是推开进入其中的对象。particles只由服务器在view_distance内的玩家周围生成,每秒最多max_per_second个。
来自组件的 Actor
Section titled “来自组件的 Actor”Actor 组件(触发器体积 · 阻挡体积 · 交互 · 音源 · 光源 · 文本展示)作为一行场景 Actor 导出。
| 键 | 值 |
|---|---|
id | <Actor id>.<组件 id>(例:door.interact) |
kind | trigger · blocker · sound · light · text |
parent | 所属 Actor 的 id(仅供参考 — 如果是方块 Actor,所属 Actor 不在 actors 中) |
tags | 所属 Actor 的标签 |
服务器无需认识新的 kind。
{"id": "gate_open", "name": "城门打开", "length": 3.0, "loop": false, "tracks": [ {"actor": "npc_guard", "property": "pos", "keys": [{"t": 0, "v": [12.5, 64, 8.5], "ease": "smooth"}, {"t": 3, "v": [14.5, 64, 8.5]}]}, {"actor": "txt_welcome", "property": "visible", "keys": [{"t": 0, "v": true}]} ]}| 键 | 含义 |
|---|---|
id · name | 片段名称 |
length | 长度(秒) |
loop | 是否循环 |
tracks[].actor | Actor id |
tracks[].property | pos · rot · scale · visible · text · color |
keys[].t | 时刻(秒)。按 t 升序 |
keys[].v | 值 — pos · rot · scale = [x,y,z],visible = 布尔值,text = 字符串,color = "#aarrggbb" |
keys[].ease | linear(缺省时为此值)· step · smooth。用于从该关键帧到下一个关键帧之间。 |
visible·text始终为阶跃。- 第一个关键帧之前取第一个值,最后一个关键帧之后取最后一个值。
- 不循环的片段结束后停留在最后的姿态。
- 多个片段驱动同一 Actor · 属性时,后开始的片段优先。
actor_show·actor_hide优先于visible轨道。
可以在片段中添加以下字段。全部为可选,旧版执行器会忽略它们,只运行 tracks。
"cuts": [{"t": 0, "camera": "cam_a"}, {"t": 3, "camera": "cam_b", "blend": 1}, {"t": 5.5, "camera": ""}],"events": [{"t": 2, "signal": "intro_mid"}],"sounds": [{"t": 0.2, "event": "minecraft:block.bell.use", "volume": 1, "pitch": 1, "at": "crystal"}],"titles": [{"t": 0.6, "title": "广场的水晶", "subtitle": "", "duration": 1.8, "fade_in": 0.3, "fade_out": 0.5}],"fades": [{"t": 0, "v": 1}, {"t": 0.9, "v": 0, "ease": "smooth"}],"fade_color": "#000000"| 字段 | 项目(* 必填) | 含义 |
|---|---|---|
cuts | t* · camera*(camera Actor,"" = 玩家视角)· blend(秒,0) | 从该时刻起切换到该相机视角 |
events | t* · signal* | 在该时刻发出信号 — 与动作 signal 相同 |
sounds | t* · event* · volume(1)· pitch(1)· at(Actor) | 在该时刻播放声音 |
titles | t* · title · subtitle · duration(2)· fade_in(0.5)· fade_out(0.5) | 在该时刻显示屏幕标题 |
fades | t* · v*(0~1)· ease | 屏幕遮罩不透明度 |
fade_color | "#rrggbb"(默认黑色) | 遮罩颜色 |
{"id": "r_gate_enter", "name": "进入城门", "enabled": true, "trigger": {"type": "enter", "actor": "trig_gate"}, "filter": {"once": false, "once_per_player": true, "cooldown": 10, "permission": ""}, "conditions": [{"type": "time", "value": "day"}], "actions": [ {"type": "sound", "event": "minecraft:block.bell.use", "at": "trig_gate", "audience": "player"}, {"type": "anim_play", "anim": "gate_open"}, {"type": "wait", "seconds": 2}, {"type": "actor_show", "actor": "txt_welcome"} ]}| 键 | 含义 |
|---|---|
id · name | 规则名称 |
enabled | 关闭时不执行。 |
trigger | 一个触发器节点 |
filter | once · once_per_player · cooldown(秒)· permission |
conditions | 条件节点数组 — 全部为真时才执行动作 |
actions | 动作节点数组 — 按顺序执行 |
min_bridge | (由编辑器添加)此规则所需的服务器 NPBridge 版本(例 "2.0.8" — 流程控制动作 · 新数学函数)。NPBridge 2.0.8 及以上的服务器会整体跳过要求比自身更新版本的规则。 |
stop_unknown | (由编辑器添加)服务器不认识时必须当场停止的动作 type 列表(例 ["gate"])。NPBridge 2.0.8 及以上的服务器遇到此列表中的未知动作时,会停止该次执行,不运行剩余动作。不在列表中的未知动作会被跳过。 |
节点是由 type 和该 type 的字段组成的对象。各 type 的字段见世界逻辑 type 列表。
- 数字字段即使写成字符串也能读取。
- 节点中的
_graph字段仅供编辑器使用(逻辑图节点位置 · 断点)。服务器会忽略它。 - 方块触发器(
block_break·block_place·block_interact)的area为blocks时,cells为[[x,y,z], …],以origin为基准(最多 4,096 格)。没有area时为zone。
字段值 · 表达式 · 结果变量
Section titled “字段值 · 表达式 · 结果变量”| 形式 | 含义 |
|---|---|
字段值整体为 "{名称}" | 该字段绑定到变量。在执行前,将变量值按字段种类转换后填入(位置字段 = "x y z" → 三个数字)。无法读取值时视为空字段。 |
{名称|过滤器} | 类型转换({block1|name} · {spot|y} …)。服务器不认识的过滤器会被忽略,直接使用原值。 |
| 表达式字段 | {名称} · 数学函数 · 比较 · and or not · 向量 · 带引号的字符串。没有需要计算的内容时,只做 {名称} 替换 + 四则运算。 |
结果字段 var · scope | 产生值的节点(math · calc · *_get · *_split …)将结果保存为 {var} · {var.名称}。新节点的 scope 默认为 local(仅在该次触发内有效,被调用的函数中也能读取)。 |
| 事件变量 | 只在触发器发生时存在的名称({amount} · {attacker} · {block} · {block_pos} …)。有同名的声明变量时,声明优先,用 {event.名称} 读取事件值。 |
函数 · 数学 · 如果 · 循环的字段见变量 · 函数 · 数据类型和世界逻辑 type 列表。
audience
Section titled “audience”选择接收者的动作(声音 · 屏幕标题 · 消息 · 战斗动作等)使用 audience。
| 值 | 接收者 |
|---|---|
player | 触发者(默认) |
inside | 动作的 actor 区域内的所有人。没有时为规则触发区域内的所有人 |
world | 世界中的所有人 |
radius | 距 at Actor(为空时为触发者)r(16)个方块以内 |
变量 · enum · 数据类型
Section titled “变量 · enum · 数据类型”"variables": [{"name": "score", "type": "int", "scope": "player", "default": "0"}, {"name": "hero", "type": "Hero", "scope": "player"}],"enums": [{"name": "Job", "values": ["warrior", "mage", "archer"]}],"types": [{"name": "Hero", "fields": [{"name": "hp", "type": "int", "default": "20"}, {"name": "job", "type": "Job"}]}]| 字段 | 键 | 含义 |
|---|---|---|
variables[] | name · type · scope · default | type = bool · int · float · string · player · actor · position · block · item · sound · particle · effect · enum 名称 · 数据类型名称。scope = global · player。没有 default 时为该类型的零值 |
enums[] | name · values | 值列表。初始值 = default 或第一个值 |
types[] | name · fields[](name · type · default) | 字段类型 = 基本类型 · enum · 其他数据类型 |
- 所有值都以字符串保存。数字为
0.###,布尔值为true·false,位置为"x y z"。 - 数据类型变量可以按字段展开的名称(
hero.hp、hero.stats.str)保存。 - 未声明的名称是全局字符串变量,与标志(
flag·set_flag)使用同一存储。 - 数据类型变量的
default为对象时,表示各字段的初始值(例:{"actor": "a1", "pos": "4 1 2", "block": "minecraft:gold_block"})。未列出的字段使用数据类型的初始值。 block·item·sound·particle·effect的值是minecraft:stone这样的 id 字符串(方块可以包含[状态])。
Actor 逻辑(蓝图)
Section titled “Actor 逻辑(蓝图)”编辑器中的 Actor 逻辑只保存在 .npworld 中,在 scene.json 中展开为规则 · 变量(没有 blueprints 字段 — 服务器无需更改)。
| 编辑器 | scene.json |
|---|---|
附加在 Actor a1 上的 Actor 逻辑中的规则 r | 规则 id a1.r |
该逻辑的变量 open · {open} · 设置变量 open | 世界变量 a1__open(初始值 = 各 Actor 的值 → 逻辑的初始值) |
{self} | a1 |
该逻辑中的函数 f | a1__f |
其他位置的 {@a1.open} · 设置变量 @a1.open | a1__open |
np-scene 1 只做追加。新功能以新字段 · 新 type 的形式添加,不更改 format · version。
| 情况 | 执行器的处理 |
|---|---|
未知的顶层字段 · 片段字段 · props 字段 | 忽略。 |
未知的 Actor kind | 仅作为数据保留(警告)。 |
| 未知的触发器 type | 跳过该规则(每个 type 警告一次)。 |
| 未知的条件 type | 视该条件为假(警告一次)。 |
| 未知的动作 type | 只跳过该动作,继续执行下一个动作(警告一次)。但如果在规则的 stop_unknown 列表中,则当场停止(NPBridge 2.0.8 及以上)。 |
规则的 min_bridge 比服务器版本新 | 整体跳过该规则(NPBridge 2.0.8 及以上)。 |
| 未知的节点字段 | 忽略。 |
编辑器不会删除未知的 type · 字段,而是原样保留。其他事件插件添加的 type 也会在装有该插件的服务器上执行。
0.10.2 起:流程控制动作
gate·stop·do_once·flip_flop·switch和数学函数inverse_lerp·wrap·snap需要 NPBridge 2.0.8 才能运行。对于比它更旧的服务器(或不报告版本的服务器),编辑器不会通过实时同步 · 场景部署上传这类逻辑,并会说明原因。导出为文件时只发出警告,并加上min_bridge·stop_unknown。
非 Minecraft 官方产品,与 Mojang 及 Microsoft 无关。