跳转到内容

scene.json 格式

scene.json 是包含场景 Actor · 动画片段 · 世界逻辑规则的 JSON 文件。编辑器在生成 .npbuild 时写入(导出窗口「包含场景」),服务器插件 NP Scene 读取并执行。格式名称为 np-scene,版本为 1。

阶段作用
1. 编辑器将 Actor · 片段 · 规则保存到世界文件(.npworld)中。坐标为编辑器世界坐标。
2. 导出为每个 .npbuild 分块写入 scene.json。坐标转换为以该分块的最小角(origin)为基准。
3. 服务器安装安装 .npbuild 时应用旋转 · 翻转 · 位置,转换为服务器坐标。
4. 服务器运行NP Scene 创建 Actor 并执行规则。
{
"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
shape字符串box · sphere(size = 直径)。只有 trigger 可以是 sphere
tags字符串数组标签。为空时为 []
parent字符串所附加的父 Actor id(仅在有时)
props对象各种类的属性

在编辑器中设为「仅编辑器」的 Actor 不会导出。

kindpos 含义主要 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
  • 服务器会忽略不认识的 props 字段。
  • visible: false 的 display · text · light 以隐藏状态开始。通过规则动作 actor_show 显示。
  • blocker 的 barrier 用 barrier 方块填满框内的空格。push 不放方块,而是推开进入其中的对象。

Actor 组件(触发器体积 · 阻挡体积 · 交互 · 音源 · 光源 · 文本展示)通常作为一行场景 Actor 导出。

键值
id<Actor id>.<组件 id>(例:door.interact)
kindtrigger · 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[].actorActor id
tracks[].propertypos · rot · scale · visible · text · color
keys[].t时刻(秒)。按 t 升序
keys[].v值 — pos · rot · scale = [x,y,z],visible = 布尔值,text = 字符串,color = "#aarrggbb"
keys[].easelinear(缺省时为此) · 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"
字段项目(* 必填)含义
cutst* · camera*(camera Actor,"" = 玩家视角) · blend(秒,0)从该时刻起切换为该相机视角
eventst* · signal*在该时刻发送信号 — 与动作 signal 相同
soundst* · event* · volume(1) · pitch(1) · at(Actor)在该时刻播放声音
titlest* · title · subtitle · duration(2) · fade_in(0.5) · fade_out(0.5)在该时刻显示屏幕标题
fadest* · 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一个触发器节点
filteronce · once_per_player · cooldown(秒) · permission
conditions条件节点数组 — 全部为真时才执行动作
actions动作节点数组 — 按顺序执行

节点是由 type 和该 type 的字段组成的对象。各 type 的字段见世界逻辑 type 列表。

  • 数值字段即使写成字符串也能读取。
  • 节点中的 _graph 字段仅供编辑器使用(逻辑图节点位置 · 断点)。服务器会忽略。
  • 方块触发器(block_break · block_place · block_interact)的 area 为 blocks 时,cells 为 [[x,y,z], …],以 origin 为基准(最多 4,096 格)。没有 area 时为 zone。

选择接收者的动作(声音 · 屏幕标题 · 消息 · 战斗动作等)使用 audience。

值接收者
player触发者(默认)
inside动作的 actor 区域内的所有人。没有时为规则触发区域内的所有人
world世界中的所有人
radius距 at Actor(为空时为触发者)r(16)方块以内
"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 · defaulttype = bool · int · float · string · player · actor · position · 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)使用同一存储。

自 0.9.7 起新增 variables,自 0.9.11 起新增 enums · types。

np-scene 1 只做追加。新功能以新字段 · 新 type 的形式添加,不更改 format · version。

情况执行器的处理
未知的顶层字段 · 片段字段 · props 字段忽略。
未知的触发器 type跳过该规则(警告一次)。
未知的条件 type将该条件视为假(警告一次)。
未知的动作 type只跳过该动作,继续执行下一个动作(警告一次)。
未知的节点字段忽略。

编辑器不会删除未知的 type · 字段,而是原样保留。其他事件插件添加的 type 也会在装有该插件的服务器上执行。