Repository navigation
annotations_us
English · 中文
NekoJS annotations go on Java classes exposed to scripts. They do two jobs:
- Control which members scripts see: renaming and hiding. These take effect at runtime.
-
Add types and descriptions for the editor: these only affect the declarations generated by
/nekojs probe, not whether scripts can call anything.
The annotations live in com.tkisor.nekojs.api.annotation; @PlatformAvailability is in com.tkisor.nekojs.api.spec. Write annotation text in English.
import com.tkisor.nekojs.api.annotation.*;
@Doc("Helpers for my addon.")
public class MyHelperJS {
@Remap("add")
@Doc("Adds two integers.")
@Param(name = "a", value = "first number")
@Param(name = "b", value = "second number")
@Return("the sum")
public int addInternal(int a, int b) {
return a + b;
}
@HideFromJS
public void resetCache() { }
}Scripts call MyHelper.add(1, 2) and cannot see addInternal or resetCache. After /nekojs probe, the editor shows the description and parameter docs for add.
| Annotation | Applies to | Effect | Where it applies |
|---|---|---|---|
@Remap("name") |
Methods, fields | Renames to the given script name | Runtime and declarations |
@RemapByPrefix({...}) |
Classes, methods, fields | Strips a name prefix | Runtime and declarations |
@HideFromJS |
Classes, methods, fields | Hides from scripts | Runtime and declarations |
@Doc("...") |
Classes, methods, constructors, fields | Description text; repeatable | Declarations |
@Param(name, value) |
Methods, constructors | Parameter description; repeatable | Declarations |
@Return("...") |
Methods | Return value description | Declarations |
@Overload({...}) |
Methods, constructors | Extra TypeScript signature; repeatable | TypeScript declarations |
@DeprecatedNekojs |
Classes, methods, constructors, fields | Marks something scripts should stop using | Declarations |
@ScriptInput(Provider.class) |
Parameters | Sets the input shape a parameter accepts | TypeScript declarations |
@ScriptOutput("...") |
Methods | Sets the TypeScript return type | TypeScript declarations |
@RegisterNekoJSPlugin |
Classes | Marks a plugin class | Plugin discovery |
@PlatformAvailability |
Interfaces, methods | Declares which platforms must implement a Spec interface | Compile-time check |
@CalledByDynamicCode |
Classes, methods, constructors | Marks code called by generated code | Source only |
A few less common declaration annotations are listed under "Other declaration annotations" below.
These three annotations change the member names scripts see at runtime. Generated method declarations use the same names.
Gives one method or field a specific script name:
public class NbtHelperJS {
@Remap("byte") // byte is a Java keyword, so the Java method needs another name
public NbtValue byteValue(Number value) { ... }
}Typical uses: the script name is a Java keyword (like byte in the built-in NBT API), or you want the internal Java name to differ from the script name.
@Remap can also be placed on a parameter, but it currently has no effect: declarations still take parameter names from Java reflection.
Strips a name prefix in bulk. On a class, it applies to every member that class declares:
@RemapByPrefix("neko$")
public interface ItemStackExtension extends ItemStackSpec {
default String neko$getId() { ... } // scripts see getId(), and the Bean property id
}- Only the first matching prefix is stripped, and the rest of the name must not be empty.
-
Case is kept:
@RemapByPrefix("get")turnsgetNameintoName, notname. For a lowercase name, use@Remap("name")on that member. - The main use is stripping the
neko$prefix (see Spec interfaces below). Strippingneko$givesgetId, so scripts can also read the Bean propertyid.
Hides a method or field from scripts:
public class TimerJS {
@HideFromJS
public void close() { ... } // engine-internal; scripts cannot call it
}On a class, it hides the methods and fields declared by that class. It does not hide inherited members, the class itself or its constructors.
When a member has several of these annotations, its script name is decided in this order:
-
@HideFromJS(on the member or its declaring class): hidden. -
@Remapon the member. -
@RemapByPrefixon the member. -
@RemapByPrefixon the declaring class or an interface it implements. - Otherwise, the Java name.
These annotations only affect the declarations generated by /nekojs probe. They do not change whether or how scripts can call anything.
@Doc("Creates an item stack from an id or item-like value.")
@Param(name = "id", value = "item id like 'minecraft:stone', '#tag', or an item-like object")
@Return("the resolved stack; never null")
public static ItemStack of(Object id) { ... }-
@Doccan be repeated; each one is a paragraph. - Put
@Paramon the method or constructor, not on the parameter;namemust match the parameter name. - The output is the JSDoc description plus
@paramand@returnslines. - To document a global binding, or for anything annotations cannot express, use the plugin hook
registerTypeDocs; see Plugin development. - Edits made with
ProbeEvents.modifyTypein scripts take precedence over annotations.
Declares extra TypeScript signatures for a method. Use it when reflection cannot work them out: different parameter counts, parameters declared as Object, or forms with different meanings.
@Doc("Creates a stack from an id.")
@Overload({"id: string"})
@Overload(value = {"item: $ItemStack", "count?: number"}, doc = "Copy with a count.")
public static ItemStack of(Object input, int count) { ... }- Each
valueentry is one parameter, written asname: Typeorname?: Typeand emitted as is. - An empty
returnsuses the reflected return type;docdescribes this signature. - Type names must be visible in the generated module, usually in
$Nameform. NekoJS does not check them or add imports. - It is only a declaration: the Java implementation must actually support every call form.
- If one parameter simply accepts several inputs (strings, objects and so on), a type adapter is enough and you do not need
@Overload. See Type adapters. - Only TypeScript declarations use it; Python
.pyioutput does not.
Tells script authors to stop using a member. Editors strike it through.
@DeprecatedNekojs(value = "Tag filters moved to Ingredient.matchTag.", replacedBy = "matchTag")
public static IngredientJS anyTag(String tag) { ... }The output is @deprecated Tag filters moved to Ingredient.matchTag. Use matchTag instead.
It is separate from Java's @Deprecated: @Deprecated alone does not mark anything deprecated in script declarations.
When a parameter has a broad type such as Map<String, Object>, or the real shape of a return value cannot be expressed with Java types, use these to write the exact TypeScript type.
public boolean register(String id, @ScriptInput(PostEffectOptions.class) Map<String, Object> options) { ... }
@ScriptOutput("import('java:java/util').$Map<string, unknown> & { readonly width: number; readonly height: number }")
public Map<String, Object> measure() { ... }- The
@ScriptInputclass must implementScriptInputShapeProviderand have a public no-argument constructor. ItsinputShape()describes the input withAdapterInputShape. -
@ScriptOutputtakes a TypeScript type expression and also applies to Bean getters and inherited methods. Refer to external types with inlineimport('module').Type. If the returned value still has callable Java methods, intersect with the Java type as in the example. - Both only affect TypeScript declarations; they do not convert or check runtime values. The declaration must match the real behavior.
- An empty
@ScriptOutputexpression fails generation withNEKO-4064.
| Annotation | Applies to | Effect |
|---|---|---|
@ScriptNullable |
Methods, parameters | A registry builder getter or setter parameter may be null; declarations add | null
|
@ScriptInternalConstructor |
Constructors | Leaves the constructor out of declarations, for objects only the engine creates. Does not change whether it can be called at runtime |
@ScriptTypeView(Interface.class) |
Classes | Return values and event objects appear as the given public interface in declarations instead of the implementation class |
@ScriptNativeBridge |
Classes | Lets a stable() API module expose Minecraft or loader types |
@ContractReceiver |
Classes | NekoJS internal; marks data types that can receive extension methods |
Marks a plugin class on NeoForge. Fabric also needs a nekojs entrypoint. Parameters: priority (default 1000, higher runs first), clientOnly (default false) and requiredMods (default {}, all must be present). See Plugin development.
NekoJS uses Spec interfaces to describe "a set of script methods every platform must implement", and each platform's Extension interface implements them. Method names carry a neko$ prefix to avoid clashing with Minecraft's own methods, and @RemapByPrefix("neko$") strips it for scripts.
// Spec: the cross-platform script surface
@RemapByPrefix("neko$")
@PlatformAvailability(PlatformAvailability.Scope.ALL)
public interface EntitySpec {
String neko$getId();
void neko$kill();
}
// Platform Extension: implements the spec with Minecraft types
@RemapByPrefix("neko$")
public interface EntityExtension extends EntitySpec {
@Override
default String neko$getId() { ... }
@Override
default void neko$kill() { ... }
}Scope values:
| Value | Meaning |
|---|---|
ALL |
Every platform must implement it |
NF_ONLY |
NeoForge only (1.21.1 and 26.x) |
NF26_ONLY |
NeoForge 26.x only |
CR_ONLY |
Old Cleanroom marker; there is currently no supported build for it |
Check Fabric support separately; @PlatformAvailability itself does not implement anything.
Compile-time checks: NekoJS's own NeoForge build runs the common-api-processor annotation processor, which checks that:
- An Extension interface that directly extends a Spec implements every
neko$method of that Spec itself; a missing one is a compile error. - When compiled with
-Anekojs.platform=nf26ornf121(cris also accepted), every Spec the current platform requires has an Extension. The old valuenfis an error.
NekoJS's Fabric build does not run this processor yet, and third-party plugins usually do not either. Without it, Spec interfaces are just a convention: the neko$ prefix and renaming still help, but nothing is checked at compile time.
Marks classes, methods and constructors called by generated JS code or reflection, so maintainers do not delete them as unused. It is kept in source only and does nothing at runtime. Whether your IDE stops reporting them as unused depends on the tool.
-
Public field declarations ignore renaming and hiding. At runtime,
@Remap,@RemapByPrefixand@HideFromJSall apply to fields, but generated declarations still show fields under their Java names, even with@HideFromJS. Adjust declarations withProbeEvents.modifyTypein scripts if needed. -
Declaration files are not a security boundary. Hiding or renaming something in declarations does not restrict runtime access; use
@HideFromJSto really hide it.
Next steps:
-
Probe type generation: how annotations become
.d.ts. -
Plugin development: add declarations with
registerTypeDocs.
Previous: Event extensions · Contents · Next: Project architecture
- 首页 / Home · 中文 · EN
- 平台与兼容性 / Platforms and compatibility · 中文 · EN
- 快速开始 / Quick start · 中文 · EN
- 配置参考 / Configuration · 中文 · EN
- 常见问题 / FAQ · 中文 · EN
- 脚本基础 / Script basics · 中文 · EN
- 脚本 API 约定 / Script API conventions · 中文 · EN
- 脚本属性 / Script properties · 中文 · EN
- 全局绑定 / Global bindings · 中文 · EN
- 数据、状态与持久化 / Data, state and persistence · 中文 · EN
- Python 脚本 / Python scripts · 中文 · EN
- Python 特性清单 / Python feature support · 中文 · EN
- 事件参考 / Event reference · 中文 · EN
- AI 辅助脚本编写 / AI-assisted authoring · 中文 · EN
- 命令 / Commands · 中文 · EN
- 错误与日志参考 / Error and log reference · 中文 · EN
- 客户端绘制与后处理 / Client rendering and post effects · 中文 · EN
- 版本化脚本包 / Versioned script packs · 中文 · EN
- 配方系统 / Recipe system · 中文 · EN
- 注册新内容 / Registering new content · 中文 · EN
- 模块系统 / Module system · 中文 · EN
- TypeScript 与 JSX / TypeScript and JSX · 中文 · EN
- JSX 客户端 UI / JSX client UI · 中文 · EN
- MixinJS(实验性) / MixinJS (experimental) · 中文 · EN
- Node.js 兼容 / Node.js compatibility · 中文 · EN