Skip to content
NP Editor Docs
This is not the latest version — view the latest

Adding world logic types

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).

WhereWhat appears
World logic panelThe Category group in the trigger · condition · action menus, field inputs
Logic graphNodes and input value pins
ChecksRequired fields · actor kinds · number ranges · enum values
One-line rule summarySummary template
Play previewSimulate handling · Fire button
AI StudioListed 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".

  1. In Register, create an NpSceneEvent and pass it to host.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 button
    host.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; }));
  2. 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. 씬 이벤트 2 means “Scene events 2”.

  3. Click Tools > World logic to open the panel. The Quest group in the trigger menu contains When talking to an NPC.

  4. 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" } ]
}
  • A trigger without Simulate never fires by itself in the preview. Leave triggers that server events cause (NPC talk and so on) without Simulate, 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 as Node("myquest_start", …).
  • The AI in AI Studio also sees plugin types. Write detailed Label · Help · field Help text 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.
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 }
FieldRequiredDescription
RoleYesRole: Trigger · Condition · Action
TypeYesSaved name (JSON "type"). No leading or trailing spaces; prefix it with your own name (see “Naming rules” below).
LabelYesName shown in the form and graph. If it is empty, registration throws.
CategoryNoMenu group name. If empty, the plugin name (name in plugin.json)
FieldsYesField list (NpSceneField). An empty array if there are no fields. A field named type, or the same name used twice, makes registration throw.
HelpNoDescription (tooltip)
IconNoIcon name (trigger · event · signal · interact · logic · star …). Default event; an unknown name uses the default image
SummaryNoOne-line summary template (see “Summary templates” below)
SimulateNoPlay preview handling (see “Simulate” below)

Plugin types appear after the built-in types within the same group.

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);
FieldDescription
NameJSON key
KindField kind (table below)
RequiredIf required, an empty value is a check error
DefaultDefault value as a string. The format is in the “How to write Default” column of the table below
OptionsEnum choices
ActorKindsActor kinds an Actor field accepts (trigger · blocker · display · text · spawn · camera · path …). If empty, any kind
Label · HelpName and description shown in the form
Min · MaxNumber range (checked)
KindForm inputJSON valueHow to write DefaultGraph input pinSDK
TextTextstring"Hello"text1.2
NumberNumbernumber"1.5"number1.2
BoolCheckboxtrue / false"true"boolean1.2
EnumOne of the choices (Options)string"none"text1.2
ActorActor picker (ActorKinds only)actor id stringactor idactor1.2
AnimAnimation clipclip id stringclip idtext1.2
SoundEventSound event"ns:path" string"minecraft:block.note_block.bell"sound1.2
BlockBlock statestring (minecraft:stone)block state stringblock1.2
ItemItemstring (minecraft:diamond_sword)item iditem1.2
ParticleParticlestring (minecraft:happy_villager)particle idparticle1.2
EffectPotion effectstring (minecraft:speed)effect ideffect1.2
Vec3x · y · z[x, y, z]"[0,1,0]"position1.2
SignalSignal namestringsignal namenone (field only)1.2
FlagScene flag namestringflag namenone (field only)1.2
ActorListMultiple actorsarray 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 Actor field pin in the graph, ActorKinds is checked.

The template for the one-line summary in the rule list. Each {field name} placeholder is replaced with that field’s value.

TemplateField valueDisplayed text
Start quest {quest}quest = q1Start 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 = noneWhen quest q1 is none
  • An Actor field 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 Summary is empty, the editor’s default one-line summary is used.

Simulate is a function that previews rules during Play and Simulate in the editor. It is not used on the game server.

RoleWhat Simulate doesReturn valueIf omitted
TriggerCalled once per rule of that type on every preview tick. To fire, call s.Fire(player)IgnoredFires only with the Fire button in the World logic and Play panels
ConditionTrue/false decisiontrue = trueAlways treated as true
ActionRuns the action (logging · changing your own state)IgnoredOnly 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:

MemberTypeDescription
Role · TypeNpSceneEventRole · stringThe role and type being handled
RuleIdstringRule id
Playerstring?Who triggered it. null when handling a trigger
PlayersIReadOnlyList<string>Current players
NowdoublePreview time (seconds)
ArgsIReadOnlyDictionary<string, string>Node field values (all strings)
Str(string key, string fallback = "")stringField value as a string
Num(string key, double fallback = 0)doubleField value as a number (dot decimal)
Bool(string key, bool fallback = false)boolField value "true" / "false"
PositionOf(string player)NpVec3?The player’s foot position. null if none
Log(string text)voidOne line in the preview log ([<plugin id>] …)
Fire(string? player)void(Trigger handling only) Fires this rule. Does nothing in other roles
Field valueArgs string
TextAs 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 → state
string 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 world

The full code is in Sample: event_example.

RuleWhy
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.
  • 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).

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.

  1. Write a handler for the same type as a Paper plugin.
  2. Get SceneEventsApi (package dev.npeditor.scene.api) from Bukkit’s ServicesManager and register the type.
  3. 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.