From d2194bb10acc01c28ca2c3ad46e2cd15a6803b32 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sun, 15 Mar 2026 07:11:43 +0200 Subject: [PATCH] INDEXED PROJECT WITH AGENTS.md + IMPORTANT MODERM MIGRATION RESEARCH --- AGENTS.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..7505196 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,59 @@ +# Scripting API — `src/api/java/noppes/npcs/api` + +## Purpose +Public Java interfaces that define the scripting API surface. Scripts (JS/Java) interact +with the game exclusively through these interfaces — implementations live in `noppes.npcs.scripted` +and `noppes.npcs.controllers.data`. This separation means API changes affect every scripter. + +## Package Layout +| Package | Contents | +|---------|----------| +| `entity/` | Core entity types: `IEntity`, `IEntityLivingBase`, `IPlayer`, `ICustomNpc`, `IAnimatable`, plus energy projectile variants | +| `entity/data/` | NPC visual data: `IModelData`, `IHitboxData`, `ITintData`, model scale/rotation | +| `event/` | 20 event interfaces (`INpcEvent`, `IPlayerEvent`, `IBlockEvent`, `IQuestEvent`, etc.) containing nested hook event types | +| `handler/` | Singletons and data managers: `ICloneHandler`, `IFactionHandler`, `IQuestHandler`, `IScriptHookHandler`, `IPlayerData`, etc. | +| `handler/data/` | Data objects: `IQuest`, `IDialog`, `IFaction`, `IAnimation`, `IFrame`, `ILinkedItem`, `ICustomEffect`, `IParty`, etc. | +| `item/` | Item wrappers: `IItemStack`, `IItemArmor`, `IItemLinked`, `IItemCustom` | +| `ability/` | Ability system: `IAbility`, `IAbilityAction`, `IChainedAbility`, `IDataAbilities`, `IPlayerAbilityData` | +| `gui/` | Custom GUI components: `ICustomGui`, `IButton`, `ILabel`, `ITextField`, `IScroll`, `IItemSlot` | +| `overlay/` | Screen overlays: `ICustomOverlay`, `IOverlayLabel`, `IOverlayLine`, `IOverlayTexturedRect` | +| `block/` | Scripted blocks: `IBlockScripted`, `ITextPlane` | +| `roles/`, `jobs/` | NPC role/job interfaces: `IRoleTrader`, `IJobGuard`, etc. | +| Root | Primitives: `IWorld`, `IPos`, `INbt`, `IBlock`, `ITimers`, `IDamageSource`, `IContainer`, `IParticle` | + +## Entity Hierarchy +`IEntity` → `IEntityLivingBase` → `IEntityLiving` → `ICustomNpc` +`IEntity` → `IEntityLivingBase` → `IPlayer` +Both `IPlayer` and `ICustomNpc` implement `IAnimatable`. + +## Event/Hook Pattern +Every scriptable context has an event interface (e.g., `INpcEvent`) with nested inner interfaces +for each hook. Each inner interface has a `@hookName` Javadoc tag naming the script function: +```java +/** @hookName damaged */ +@Cancelable +interface DamagedEvent extends INpcEvent { + float getDamage(); + void setDamage(float damage); + IEntity getSource(); +} +``` +Scripts receive the event as a parameter: `function damaged(event) { event.setDamage(0); }`. +Cancelable events can call `event.setCanceled(true)` to prevent default behavior. + +## Hook Registration (Addon API) +`IScriptHookHandler` allows addons to register custom hooks with full metadata via +`IHookDefinition` (hook name, event class FQN, param names, required imports, cancelable flag). +Registered hooks appear in the script editor's hook list and get proper stub generation. + +## API Entry Point +`AbstractNpcAPI` (accessed as `API` in scripts) provides global utilities: world access, +item/entity creation, handler lookups, temp/stored data, NBT construction, overlay/GUI creation. + +## Design Rules +- **Interface-only API**: No implementation classes. Scripters see only `I*` interfaces. +- **Method overloads**: Provide both object-based (`IPos`) and primitive-based (`double x, y, z`) signatures. +- **Generic type params**: Entity interfaces use `` to expose `getMCEntity()` for advanced users. +- **`@Deprecated` methods**: Keep for backward compatibility, add replacement alongside. +- **`@hookName` tag**: Required on every event inner interface — drives editor hook list and stub generation. +- **No runtime dependencies on editor**: API interfaces must never reference client/GUI classes.