Custom Npcs – Scripting in minecraft
Api Links
Languages
To use scripting you need to download one of the libraries below and put them in your mods folder.
- ECMAScript(more commenly know as javascript): You need java 8 or higher and go to your java/jre/lib/ext folder and copy the nashorn.jar to the mods folder
- Python: Download the standalone jar from the Jython website and put it in the mods folder.
- Lua: Download the luaj.zip from the Luaj website and put the lib/luaj-jse.jar into the mods folder.
- Ruby: Download the jruby.zip from the JRuby website and put the lib/jruby.jar into the mods folder.
There are probably more scripting languages available. These are just some examples. You can usually find them by googling: java scriptengine <your language name>
API
If there is any extra functionality you would like feel free to ask for it on the forums or join us on discord
Simple script example
Hooks
| Function | Event | Description |
|---|---|---|
| init | NpcEvent.InitEvent | Called when the npc spawns or respawns |
| tick | NpcEvent.UpdateEvent | Called as update tick (once every 10 ticks) |
| interact | NpcEvent.InteractEvent | Called when a player interacts with the npc |
| dialog | DialogEvent.OpenEvent | Called when a player opens a dialog from the npc |
| dialogOption | DialogEvent.OptionEvent | Called when a player selects a dialog option |
| dialogClose | DialogEvent.CloseEvent | Called when a player closes a dialog |
| damaged | NpcEvent.DamagedEvent | Called when an npc gets attacked. Can be cancelled |
| died | NpcEvent.DiedEvent | Called when an npc gets killed |
| meleeAttack | NpcEvent.MeleeAttackEvent | Called when an npc is going to attack |
| rangedLaunched | NpcEvent.RangedLaunchedEvent | Called when an npc fires a projectile |
| target | NpcEvent.TargetEvent | Called when an npc targets something |
| targetLost | NpcEvent.TargetLostEvent | Called when an npc looses his target |
| kill | NpcEvent.KilledEntityEvent | Called when an npc kills something |
| role | RoleEvent.* | Called by some roles |
| collide | NpcEvent.CollideEvent | Called when an npc collides with an entity |
| timer | NpcEvent.TimerEvent | Called when a timer finishes |
| trigger | WorldEvent.TriggerEvent | Called when /noppes script trigger is used or ICustomNpc.trigger |
ScriptBlock/ScriptedBlockDoor events:
| Function | Event | Description |
|---|---|---|
| init | BlockEvent.InitEvent | Called when the block is created or loaded |
| tick | BlockEvent.UpdateEvent | Called as update tick (once every 10 ticks) |
| interact | BlockEvent.InteractEvent | Called when a player interacts with the block |
| redstone | BlockEvent.RedstoneEvent | Called when the block receives a new redstone signal |
| fallenUpon | BlockEvent.EntityFallenUponEvent | Called when an entity falls upon this block |
| doorToggle | BlockEvent.DoorToggleEvent | Called when the scripteddoor gets opened/closed |
| broken | BlockEvent.BreakEvent | Called when the block is broken |
| exploded | BlockEvent.ExplodedEvent | Called when the block was blown up |
| rainFilled | BlockEvent.RainFillEvent | Called when it rains sometimes |
| neighborChanged | BlockEvent.NeighborChangedEvent | Called when a neighboring block is changed |
| clicked | BlockEvent.ClickedEvent | Called when the block is clicked |
| harvested | BlockEvent.HarvestedEvent | Called when a block is destroyed by a player |
| collide | BlockEvent.CollidedEvent | Called when an entity collides with the block |
| timer | BlockEvent.TimerEvent | Called when a timer finishes |
| trigger | WorldEvent.TriggerEvent | Called when /noppes script trigger is used or IBlockScripted.trigger |
Player events:
| Function | Event | Description |
|---|---|---|
| init | PlayerEvent.InitEvent | Called when the player is created or loaded |
| tick | PlayerEvent.UpdateEvent | Called as update tick (once every 10 ticks) |
| interact | PlayerEvent.InteractEvent | Called when a player interacts with the block |
| broken | PlayerEvent.BreakEvent | Called when a block is broken |
| toss | PlayerEvent.TossEvent | Called when a player tosses an item on the ground |
| pickUp | PlayerEvent.PickUpEvent | Called when a player picks up an item |
| containerOpen | PlayerEvent.ContainerOpen | Called when a player opens a container |
| containerClosed | PlayerEvent.ContainerClosed | Called when a player closes a container |
| died | PlayerEvent.DiedEvent | Called when a player dies |
| attack | PlayerEvent.AttackEvent | Called when a player left clicks |
| kill | PlayerEvent.KilledEntityEvent | Called when a player kills an entity |
| damaged | PlayerEvent.DamagedEvent | Called when a player gets damaged |
| damagedEntity | PlayerEvent.DamagedEntityEvent | Called when a player damages an entity |
| rangedLaunched | PlayerEvent.RangedLaunchedEvent | Called when a player shoots an arrow |
| timer | PlayerEvent.TimerEvent | Called when a timer finishes |
| login | PlayerEvent.LoginEvent | Called when a player logs in |
| logout | PlayerEvent.LogoutEvent | Called when a player logs out |
| chat | PlayerEvent.ChatEvent | Called when a player says something |
| factionUpdate | PlayerEvent.FactionUpdateEvent | Called when a players faction points change |
| dialog | DialogEvent.OpenEvent | Called when a player opens a dialog from the npc |
| dialogOption | DialogEvent.OptionEvent | Called when a player selects a dialog option |
| dialogClose | DialogEvent.CloseEvent | Called when a player closes a dialog |
| questStart | QuestEvent.QuestStartEvent | Called when a player starts a quest |
| questCompleted | QuestEvent.QuestCompletedEvent | Called when a player finishes all objectives of a quest |
| questTurnIn | QuestEvent.QuestTurnedInEvent | Called when a player turns in a quest to get the rewards |
| trigger | WorldEvent.TriggerEvent | Called when /noppes script trigger is used or IPlayer.trigger |
ScriptedItem events:
| Function | Event | Description |
|---|---|---|
| init | ItemEvent.InitEvent | Called when the item is created or loaded |
| tick | ItemEvent.UpdateEvent | Called as update tick (once every 10 ticks) when item is in the inventory |
| interact | ItemEvent.InteractEvent | Called when a player interacts with the block/entity or air |
| attack | ItemEvent.AttackEvent | Called when a player left click on a block/entity or air |
| toss | ItemEvent.TossEvent | Called when a player tosses the item on the ground |
| spawn | ItemEvent.SpawnEvent | Called when a scripted item spawns into the world |
| pickedUp | ItemEvent.PickedUpEvent | Called when a player picks up a scripted item |
Projectile events:
| Function | Event | Description |
|---|---|---|
| projectileTick | ProjectileEvent.UpdateEvent | Called as update tick (once every 10 ticks) |
| projectileImpact | ProjectileEvent.ImpactEvent | Called when the projectile impacts an entity or block |
CustomGuis events:
| Function | Event | Description |
|---|---|---|
| customGuiClosed | CustomGuiEvent.CloseEvent | Called when the custom gui gets closed |
| customGuiButton | CustomGuiEvent.ButtonEvent | Called when a custom gui button is pressed |
| customGuiSlot | CustomGuiEvent.SlotEvent | Called when a custom gui slot is pressed |
| customGuiScroll | CustomGuiEvent.ScrollEvent | Called when a custom gui scroll list is pressed |
