Adding world logic types
Overview
Section titled “Overview”Since SDK 1.2, plugins can add new trigger, condition and action types to World logic. Types registered with host.AddSceneEvent appear in the same places as built-in types. Registration in the editor is for the form, checks and preview. To actually run a type on the game server, also register a handler for the same type in the server plugin NPBridge (see “Server side” below).
| Where | What appears |
|---|---|
| World logic panel | The Category group in the trigger · condition · action menus, field inputs |
| Logic graph | Nodes and input value pins |
| Checks | Required fields · actor kinds · number ranges · enum values |
| One-line rule summary | Summary template |
| Play preview | Simulate handling · Fire button |
| AI Studio | Listed with [<plugin id>] in the type lists (section=schema · types) of the scene_rules tool the AI uses |
Write "sdk": "^1.2" or later in plugin.json. If you use the field kind ActorList, use "^1.3".
Basic use
Section titled “Basic use”-
In
Register, create anNpSceneEventand pass it tohost.AddSceneEvent. This example adds one trigger and one action.host.AddSceneEvent(new NpSceneEvent(NpSceneEventRole.Trigger, "myquest_npc_talk", "When talking to an NPC", "Quest", new[]{new NpSceneField("npc", NpSceneFieldKind.Actor, Required: true, ActorKinds: new[] { "display", "text", "spawn" }, Label: "NPC"),new NpSceneField("line", NpSceneFieldKind.Text, Label: "Line id"),},Help: "When a player starts talking to an NPC", Icon: "interact",Summary: "When a player talks to NPC {npc}")); // no Simulate = fired only with the Fire buttonhost.AddSceneEvent(new NpSceneEvent(NpSceneEventRole.Action, "myquest_start", "Start quest", "Quest", new[]{new NpSceneField("quest", NpSceneFieldKind.Text, Required: true, Label: "Quest id"),},Icon: "star", Summary: "Start quest {quest}",Simulate: s => { s.Log($"Quest {s.Str("quest")} started → {s.Player}"); return true; })); -
Build, then click Reload (selected) in the Plugin Manager. The Registered column shows
씬 이벤트 2.Known issue in 0.10.2: the Registered column shows the registration summary in Korean.
씬 이벤트 2means “Scene events 2”. -
Click Tools > World logic to open the panel. The
Questgroup in the trigger menu containsWhen talking to an NPC. -
Create a rule, click Play test, then click Fire on that rule. The log list at the bottom of the panel shows a
[<plugin id>] Quest … started → …line.
A rule that uses these types is saved in scene.json like this (part of a rule).
{ "trigger": { "type": "myquest_npc_talk", "npc": "npc_guard" }, "actions": [ { "type": "myquest_start", "quest": "q1" } ]}Tips and tricks
Section titled “Tips and tricks”- A trigger without
Simulatenever fires by itself in the preview. Leave triggers that server events cause (NPC talk and so on) withoutSimulate, and test them with the Fire button. - Conditions and actions that remember state in the preview keep that state in plugin fields and clear it in
host.WorldChanged(example below). - In the Logic graph code view, a plugin type appears as
MyquestStart(quest: "q1"). If it contains fields that cannot be read back, it is kept asNode("myquest_start", …). - The AI in AI Studio also sees plugin types. Write detailed
Label·Help· fieldHelptext so the AI uses the type correctly. - To avoid built-in type names, look them up first in the World logic type list. 0.10.2 has 157 built-in types.
Reference
Section titled “Reference”NpSceneEvent
Section titled “NpSceneEvent”public sealed record NpSceneEvent(NpSceneEventRole Role, string Type, string Label, string Category, IReadOnlyList<NpSceneField> Fields, string Help = "", string Icon = "event", string Summary = "", Func<NpSceneSim, bool>? Simulate = null);public enum NpSceneEventRole { Trigger, Condition, Action }| Field | Required | Description |
|---|---|---|
Role | Yes | Role: Trigger · Condition · Action |
Type | Yes | Saved name (JSON "type"). No leading or trailing spaces; prefix it with your own name (see “Naming rules” below). |
Label | Yes | Name shown in the form and graph. If it is empty, registration throws. |
Category | No | Menu group name. If empty, the plugin name (name in plugin.json) |
Fields | Yes | Field list (NpSceneField). An empty array if there are no fields. A field named type, or the same name used twice, makes registration throw. |
Help | No | Description (tooltip) |
Icon | No | Icon name (trigger · event · signal · interact · logic · star …). Default event; an unknown name uses the default image |
Summary | No | One-line summary template (see “Summary templates” below) |
Simulate | No | Play preview handling (see “Simulate” below) |
Plugin types appear after the built-in types within the same group.
NpSceneField
Section titled “NpSceneField”public sealed record NpSceneField(string Name, NpSceneFieldKind Kind, bool Required = false, string Default = "", string[]? Options = null, string[]? ActorKinds = null, string Label = "", string Help = "", double? Min = null, double? Max = null);| Field | Description |
|---|---|
Name | JSON key |
Kind | Field kind (table below) |
Required | If required, an empty value is a check error |
Default | Default value as a string. The format is in the “How to write Default” column of the table below |
Options | Enum choices |
ActorKinds | Actor kinds an Actor field accepts (trigger · blocker · display · text · spawn · camera · path …). If empty, any kind |
Label · Help | Name and description shown in the form |
Min · Max | Number range (checked) |
Field kinds (NpSceneFieldKind)
Section titled “Field kinds (NpSceneFieldKind)”| Kind | Form input | JSON value | How to write Default | Graph input pin | SDK |
|---|---|---|---|---|---|
Text | Text | string | "Hello" | text | 1.2 |
Number | Number | number | "1.5" | number | 1.2 |
Bool | Checkbox | true / false | "true" | boolean | 1.2 |
Enum | One of the choices (Options) | string | "none" | text | 1.2 |
Actor | Actor picker (ActorKinds only) | actor id string | actor id | actor | 1.2 |
Anim | Animation clip | clip id string | clip id | text | 1.2 |
SoundEvent | Sound event | "ns:path" string | "minecraft:block.note_block.bell" | sound | 1.2 |
Block | Block state | string (minecraft:stone) | block state string | block | 1.2 |
Item | Item | string (minecraft:diamond_sword) | item id | item | 1.2 |
Particle | Particle | string (minecraft:happy_villager) | particle id | particle | 1.2 |
Effect | Potion effect | string (minecraft:speed) | effect id | effect | 1.2 |
Vec3 | x · y · z | [x, y, z] | "[0,1,0]" | position | 1.2 |
Signal | Signal name | string | signal name | none (field only) | 1.2 |
Flag | Scene flag name | string | flag name | none (field only) | 1.2 |
ActorList | Multiple actors | array of actor ids | "cam_a,cam_b" | none (field only) | 1.3 |
- Field kinds used only by built-in types (flag value · function call · block cell list) and field options (visibility conditions · integers only · allowing
#tags· pick lists) are not in the SDK. - In the Logic graph, plugin trigger nodes automatically get the triggering-player output pin
Player({player}). Other output pins (event data · result values) cannot be created with the SDK. - When you connect an actor to an
Actorfield pin in the graph,ActorKindsis checked.
Summary templates
Section titled “Summary templates”The template for the one-line summary in the rule list. Each {field name} placeholder is replaced with that field’s value.
| Template | Field value | Displayed text |
|---|---|---|
Start quest {quest} | quest = q1 | Start quest q1 |
When a player talks to NPC {npc} | npc = npc_guard (name “Guard”) | When a player talks to NPC 「Guard」 |
When quest {quest} is {state} | state empty, Default = none | When quest q1 is none |
- An
Actorfield is replaced with the actor’s name in corner brackets (「Guard」) instead of the actor id. - Fields without a value are filled with
Default. - If
Summaryis empty, the editor’s default one-line summary is used.
Simulate — Play preview
Section titled “Simulate — Play preview”Simulate is a function that previews rules during Play and Simulate in the editor. It is not used on the game server.
| Role | What Simulate does | Return value | If omitted |
|---|---|---|---|
| Trigger | Called once per rule of that type on every preview tick. To fire, call s.Fire(player) | Ignored | Fires only with the Fire button in the World logic and Play panels |
| Condition | True/false decision | true = true | Always treated as true |
| Action | Runs the action (logging · changing your own state) | Ignored | Only leaves a log entry |
If Simulate throws, the plugin is isolated. All of that plugin’s types are removed, and the preview keeps running.
The NpSceneSim that Simulate receives:
| Member | Type | Description |
|---|---|---|
Role · Type | NpSceneEventRole · string | The role and type being handled |
RuleId | string | Rule id |
Player | string? | Who triggered it. null when handling a trigger |
Players | IReadOnlyList<string> | Current players |
Now | double | Preview time (seconds) |
Args | IReadOnlyDictionary<string, string> | Node field values (all strings) |
Str(string key, string fallback = "") | string | Field value as a string |
Num(string key, double fallback = 0) | double | Field value as a number (dot decimal) |
Bool(string key, bool fallback = false) | bool | Field value "true" / "false" |
PositionOf(string player) | NpVec3? | The player’s foot position. null if none |
Log(string text) | void | One line in the preview log ([<plugin id>] …) |
Fire(string? player) | void | (Trigger handling only) Fires this rule. Does nothing in other roles |
| Field value | Args string |
|---|---|
| Text | As is |
| Number | "1.5" (dot decimal, culture-independent) |
| True/false | "true" / "false" |
Array · object (Vec3 · ActorList) | JSON string ("[0,1,0]") |
An example of a trigger that fires by itself. It is called on every preview tick, so keep it light.
host.AddSceneEvent(new NpSceneEvent(NpSceneEventRole.Trigger, "myquest_near_spawn", "When near spawn", "Quest", new[] { new NpSceneField("r", NpSceneFieldKind.Number, Default: "5", Label: "Radius", Min: 1, Max: 64), }, Summary: "When within {r} blocks of spawn", Simulate: s => { foreach (var p in s.Players) if (s.PositionOf(p) is { } pos && Math.Abs(pos.X) + Math.Abs(pos.Z) < s.Num("r", 5)) s.Fire(p); return true; }));An example of a condition and an action that remember state.
var quests = new Dictionary<string, string>(); // player:quest → statestring Get(string? player, string quest) => quests.TryGetValue((player ?? "") + ":" + quest, out var v) ? v : "none";
host.AddSceneEvent(new NpSceneEvent(NpSceneEventRole.Condition, "myquest_state", "Quest state", "Quest", new[] { new NpSceneField("quest", NpSceneFieldKind.Text, Required: true, Label: "Quest id"), new NpSceneField("state", NpSceneFieldKind.Enum, Default: "none", Options: new[] { "none", "active", "done" }, Label: "State"), }, Summary: "When quest {quest} is {state}", Simulate: s => Get(s.Player, s.Str("quest")) == s.Str("state", "none")));
host.AddSceneEvent(new NpSceneEvent(NpSceneEventRole.Action, "myquest_activate", "Set quest to active", "Quest", new[] { new NpSceneField("quest", NpSceneFieldKind.Text, Required: true, Label: "Quest id"), }, Simulate: s => { quests[(s.Player ?? "") + ":" + s.Str("quest")] = "active"; s.Log("Started"); return true; }));
host.WorldChanged += _ => quests.Clear(); // clear in a new worldThe full code is in Sample: event_example.
Naming rules
Section titled “Naming rules”| Rule | Why |
|---|---|
Prefix Type with your own name (myquest_start). | If the same type already exists in the same role (including built-ins and other plugins), registration throws and the plugin is not loaded; its status is “Version mismatch” (“Not loaded: overlaps a built-in feature — …”). |
Use lowercase letters, digits and _. | Easier to match with the server plugin and JSON. |
Never change a Type or field Name once used. | Saved rules (scene.json) use that name. |
Do not use built-in type names (enter · chat · sound · math · if · cinematic …). | If it collides with a built-in, the plugin does not enable. |
When the plugin is disabled
Section titled “When the plugin is disabled”- The plugin’s types are removed from the menus and the graph palette.
- Rules that use those types are not deleted. They get an “Unknown type” warning, and their field values are kept.
- In the preview, a rule with an unknown trigger is skipped, an unknown condition is false, and an unknown action is skipped on its own (one warning per type).
Server side
Section titled “Server side”The server plugin NPBridge (Paper) runs the rules in game. Since NPBridge 2.0, NP Scene is part of NPBridge. NPBridge declares provides: [NPScene], so Paper plugins that used to depend on NPScene still enable. Editor plugins do not run on the server.
- Write a handler for the same type as a Paper plugin.
- Get
SceneEventsApi(packagedev.npeditor.scene.api) from Bukkit’sServicesManagerand register the type. - Match the field names and value formats (JSON) exactly with the editor-side
NpSceneField.
SceneEventsApi api = Bukkit.getServicesManager().load(SceneEventsApi.class);api.registry().plugin("myquest") .trigger(TriggerType.of("myquest_npc_talk", TriggerType.ActorUse.REQUIRED, Set.of("display", "text", "spawn"))) .action("myquest_start", (a, ctx) -> { String quest = a.str("quest", ""); // … start the quest for ctx.player() … });// fire the trigger from your own event:api.dispatch(SceneEvent.of("myquest_npc_talk", world.getName()).player(p.getUniqueId()).actor("npc_guard"));// on disable: api.registry().unregisterPlugin("myquest");- Register on the main thread. Registering reloads the scenes that use that type on the next tick, so rules that were skipped because NPBridge enabled first start working.
- The server skips unknown types with one warning (trigger = that rule is skipped, action = only that action is skipped). So the map still opens without a server handler, but that rule does not run.
Related pages
Section titled “Related pages”Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.