Host API
Overview
Section titled “Overview”The host you receive in Register(INpEditorHost host) is the starting point for every plugin feature. This page covers info, notifications, the world, events, settings, 3D drawing and the account. The Add… registration points are in Registration points, and Scene · View are in Scene access and play camera. All types are in the NP.Editor.Sdk namespace.
Basic use
Section titled “Basic use”-
Store the
hostyou receive inRegisterin a field. Use the samehostinside callbacks. -
Read the world through
host.World. Even after a new world is opened,host.Worldalways points to the current world. -
To change blocks, group the changes in one
host.World.Edit(label, e => { … })call. One call is one undo step.int n = host.World.Edit("Stone floor", e =>{for (int x = 0; x < 8; x++)for (int z = 0; z < 8; z++)e.Set(x, 0, z, "minecraft:stone");});host.Message($"{n} cells changed (Ctrl+Z to undo)"); -
Tell the user the result with
host.Message, and keep detailed records in the Output Log withhost.Log. -
Clear your state in
host.WorldChangedso you are ready when a new world or another world is opened.
Tips and tricks
Section titled “Tips and tricks”- Use the return value of
Edit(the number of cells actually changed) to see whether locked cells were skipped. If it is smaller than the number of cells you set, a lock, a protected area or a cell guard blocked them. - Do not call
Editwhile iteratingBlocks(). Get the list first with.ToList(), then make changes. Committedfires for user edits, AI work and edits from other plugins alike. Some steps have many cells, so count onlyChanges.Countinstead of reading each change.- Separate results for the user (
Message) from detailed debug text (Log).Messageis also written to the%APPDATA%\NPEditor\logs\godot.logfile, butLogappears only in the Output Log panel. - Write 3D drawing as “clear everything and redraw”. Keep one function that calls
Draw.Clear()and then adds everything again, and call that function whenever the state changes.
Reference
Section titled “Reference”INpEditorHost
Section titled “INpEditorHost”| Member | Type | SDK | Description |
|---|---|---|---|
SdkVersion | string | 1.0 | The editor’s SDK version (0.10.2 = "1.5.0") |
EditorVersion | string | 1.0 | The editor version (for example "0.10.2") |
PluginId | string | 1.0 | The id from your plugin.json |
PluginDir | string | 1.0 | The folder containing your plugin.json (full path) |
World | INpWorld | 1.0 | The current world |
WorldChanged | event Action<NpWorldChange>? | 1.0 | When the world changes |
Committed | event Action<NpCommit>? | 1.0 | Each time an undo step completes |
Message(string text) | void | 1.0 | A short notification (status bar · viewport notification · Output Log) |
Log(string text) | void | 1.0 | One Output Log line [<id>] <text> |
Settings | INpSettings | 1.1 | This plugin’s settings store |
Draw | INpDraw | 1.1 | 3D overlay drawing in the viewport |
Scene | INpScene | 1.3 | Read scene actors — Scene access and play camera |
View | INpView | 1.3 | Play state · camera — Scene access and play camera |
Account | INpAccount | 1.4 | Read-only account license — see “Account” below |
Add… · SetShowFlag | void | 1.0~1.5 | Registration points — Registration points |
World: INpWorld
Section titled “World: INpWorld”| Member | Type | Description |
|---|---|---|
FilePath | string? | The current file path. null for a new, unsaved world |
Selection | NpBox? | The current selection box. null if none |
Bounds | NpBox? | The extent that contains blocks. null for an empty world. It scans the whole world, so do not call it often. |
GetBlock(int x, int y, int z) | string | The block state string. Air is "minecraft:air" |
IsAir(int x, int y, int z) | bool | Whether the cell is air |
Blocks(NpBox? box = null) | IEnumerable<NpBlock> | Every non-air cell. If box is given, only cells inside it (chunks that do not touch the box are skipped) |
CountBlocks() | long | The number of non-air blocks |
Edit(string label, Action<INpEdit> build) | int | Changes blocks. One call = one undo step. Returns the number of cells actually changed |
INpEdit is used inside Edit.
| Member | Description |
|---|---|
Set(int x, int y, int z, string state) | Sets the cell to the block state string. An empty string, "air" or "minecraft:air" is air. |
Clear(int x, int y, int z) | Sets the cell to air. |
labelis the name shown in the undo history.- Locked cells are skipped. Locked cells = cells blocked by a Co-building region lock, a locked actor, a protected area or a cell guard (
AddCellGuard). - If another large edit (fill, terrain and so on) is running,
InvalidOperationException(“Another edit is in progress — try again when it finishes”) is thrown. If you do not catch it, the plugin is isolated. - Block state strings are not validated; they are written exactly as given. Write them precisely in the Minecraft format (
namespace:id[property=value,…]) and do not omit the namespace (minecraft:). Custom blocks arenp:<id>.
Data types
Section titled “Data types”| Type | Declaration | Description |
|---|---|---|
NpCell | readonly record struct NpCell(int X, int Y, int Z) | One cell (block coordinates) |
NpBlock | readonly record struct NpBlock(int X, int Y, int Z, string State) | Cell + block state string |
NpBox | readonly record struct NpBox(NpCell Min, NpCell Max) | Box (both ends inclusive). SizeX · SizeY · SizeZ · Contains(x, y, z) |
NpVec3 | readonly record struct NpVec3(float X, float Y, float Z) | 3D point (one block = 1). NpVec3.Center(NpCell) = center of the cell |
NpWorldChange | sealed record NpWorldChange(NpWorldChangeReason Reason, string? Path) | Why the world changed, and the file path |
NpWorldChangeReason | enum { New, Open, Replaced, ShotScenario } | New · open · world replaced · screen verification started |
NpCommit | sealed record NpCommit(string Label, IReadOnlyList<NpBlockChange> Changes) | One undo step |
NpBlockChange | readonly record struct NpBlockChange(int X, int Y, int Z, string Old, string New) | The before and after state of one cell |
Events
Section titled “Events”| Event | When | Value passed | What to do |
|---|---|---|---|
WorldChanged | New · open · world replaced · screen verification started | NpWorldChange | Clear your state (previews · selection · drawings · check results). |
Committed | Each time an undo step completes | NpCommit | Logging and statistics only. Keep it light. |
var towers = new List<NpCell>();int edits = 0;host.WorldChanged += c =>{ towers.Clear(); host.Draw.Clear();};host.Committed += c => edits += c.Changes.Count; // keep it lightChangesinCommittedbuilds block names when it is read. If there are many cells, look only atCount.- If a handler throws, the plugin is isolated.
- Host events are unhooked automatically when the plugin is unloaded, and
-=does nothing. To stop handling, filter with a flag inside the handler.
Notifications and logs
Section titled “Notifications and logs”| Member | Where it appears | When to use |
|---|---|---|
Message(text) | Left side of the status bar (shortened, full text in the tooltip) · viewport notification · Output Log · logs\godot.log | To tell the user a result |
Log(text) | Output Log panel ([<id>] …) | Debug records · detailed results |
Settings: INpSettings (SDK 1.1)
Section titled “Settings: INpSettings (SDK 1.1)”Each plugin has one key–value (string) store. Every Set is written to the file immediately, and values persist across editor restarts and plugin reloads.
| Member | Type | Description |
|---|---|---|
Keys | IReadOnlyCollection<string> | List of stored keys |
Get(string key) | string? | The value. null if missing |
Get(string key, string fallback) | string | The value. fallback if missing |
GetInt(string key, int fallback = 0) | int | Read as an integer. fallback if it cannot be read |
GetDouble(string key, double fallback = 0) | double | Read as a floating-point number (dot decimal) |
GetBool(string key, bool fallback = false) | bool | Read as "true" / "false" |
Set(string key, string? value) | void | Store. null deletes the key. An empty key throws. |
SetInt · SetDouble · SetBool | void | Typed store |
Changed | event Action<string>? | When a value changes or is deleted (key name) |
int height = host.Settings.GetInt("height", 12);var ui = new NpUi() .Number("Height", height, 4, 64, 1, v => { height = (int)v; host.Settings.SetInt("height", height); }); // save as soon as it changes| Item | Value |
|---|---|
| File | %APPDATA%\NPEditor\plugin_settings\<id>.json |
| Format | {"format":"np-plugin-settings","version":1,"values":{…}} |
| Same value | Setting the same value again does not write the file. |
| Corrupt file | Starts with empty settings and keeps the old file next to it as <id>.json.bad. The Output Log records a “Couldn’t read settings file, starting with empty settings” line. |
| Large data | Do not store it here. Every Set rewrites the whole file. Keep data of several MB in your own files under PluginDir. |
3D drawing: INpDraw (SDK 1.1)
Section titled “3D drawing: INpDraw (SDK 1.1)”Draws lines, boxes and text over the viewport. It does not affect blocks, selection or clicks. Coordinates are world coordinates (one block = 1), and colors are "#rrggbb".
| Member | Description |
|---|---|
Count | Number of items currently drawn |
Line(NpVec3 a, NpVec3 b, string color = "#ffcc33") | Line |
Box(NpVec3 min, NpVec3 max, string color = "#ffcc33", bool filled = false, float alpha = 0.25f) | Box edge lines. If filled, translucent faces are drawn too. |
Cell(NpCell c, string color = "#ffcc33", bool filled = false) | Box around one block cell (slightly larger) |
Text(NpVec3 at, string text, string color = "#ffffff", float size = 1f) | Text that always faces the camera. size = scale relative to block height |
Clear() | Clears everything |
void Redraw(){ host.Draw.Clear(); // when redrawing, clear and draw everything if (host.World.Selection is not { } b) return; host.Draw.Box(new NpVec3(b.Min.X, b.Min.Y, b.Min.Z), new NpVec3(b.Max.X + 1, b.Max.Y + 1, b.Max.Z + 1), "#ffcc33", filled: true, alpha: 0.1f); host.Draw.Text(new NpVec3(b.Min.X, b.Max.Y + 2, b.Min.Z), $"{b.SizeX}×{b.SizeY}×{b.SizeZ}");}| Limit | Value |
|---|---|
| Maximum count | 20,000 per plugin. Anything beyond is ignored. |
| Text length | Up to 200 characters |
size | 0.1 – 20 |
alpha | 0 – 1 |
min · max of Box | Drawn correctly even if swapped. |
| When the plugin is disabled | Cleared automatically. |
Account: INpAccount (SDK 1.4)
Section titled “Account: INpAccount (SDK 1.4)”Read-only access to the license of the account signed in to the editor. The tier is decided only by a license the server has signed, and the raw license (signed text) is never given to plugins.
| Member | Type | Description |
|---|---|---|
Tier | string | Tier text: free · supporter · builder · studio · partner · beta · dev. Other values may come in the future, so decide only with Has when the text is unknown. |
Has(string feature) | bool | Whether the license has that feature code (for example editor_pro · beta_builds · ai_mapgen · mcp_web · collab_plus) |
Changed | event Action? | When the license changes (sign-in · daily refresh · expiry). Called on the main thread. |
public sealed class Plugin : INpEditorPlugin, IDisposable{ private INpEditorHost _h = null!; private bool _pro; private Action? _onAccount;
public void Register(INpEditorHost host) { _h = host; _pro = host.Account.Has("editor_pro"); _onAccount = () => _pro = _h.Account.Has("editor_pro"); host.Account.Changed += _onAccount; }
public void Dispose() { if (_onAccount != null) _h.Account.Changed -= _onAccount; // only this event must be unhooked by hand }}- Server features are checked again by the server when they run. Use the
Hasresult only to decide whether to show a button. - In development builds with the license check turned off,
TierisdevandHasalways returnstrue. - Unlike other host events,
Account.Changedis not unhooked automatically when the plugin unloads. Unhook it with-=inDispose. Exceptions thrown by the handler are not isolated; they are ignored.
Related pages
Section titled “Related pages”Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.