You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|**Server Reload Script**|`.reload.kts`| a chat greeting for joining players |
48
+
|**Client Reload Script**|`.reload.kts` with `@file:ClientSide`| a line of text on the HUD |
49
+
|**Startup Script**|`.startup.kts`| an item registered under the file's name |
50
+
|**Node Script**|`.node.kts`| start, stop, and once-a-second handlers |
51
+
|**UI Script**|`.ui.kts`| a simple screen |
52
+
|**Dialogue**|`.story`| a dialogue with two answers |
53
+
54
+
Then enter the file name. The extension can be omitted, the IDE adds it. The new file opens in the editor right away with a working example to start from.
55
+
56
+

57
+
58
+
The item is only offered inside `scripts`, because the engine loads scripts and dialogues from there only.
59
+
40
60
## Code editor
41
61
42
62
Opening `.kts`, `.story`, `.hss`, and other supported text files starts the built-in editor. Depending on the file type, it provides syntax highlighting, diagnostics, completion, signature help, inlay hints, and navigation. Diagnostics are shown in the editor and in a resizable problems panel.
@@ -59,8 +79,9 @@ Useful editor shortcuts:
59
79
60
80
Saving a file writes it to the `hollowengine` directory. What must be reloaded depends on the file:
61
81
62
-
- use **File > Reload Client Resources** or `F3 + T` for models, textures, HSS, UI declarations, and other client resources;
63
-
- use **File > Reload Server Resources** or `/reload` for datapack content and reloadable server scripts;
82
+
- use **File > Reload Client Resources** or `F3 + T` for models, textures, HSS, UI declarations, client reloadable scripts (`@file:ClientSide`), and other client resources;
83
+
- use **File > Reload Server Resources** or `/reload` for datapack content and server reloadable scripts;
84
+
-`.startup.kts` changes only apply after restarting the game;
64
85
- ordinary `.kts` scripts are started explicitly with `/hollowengine scripting run <path>`.
65
86
66
87
The compiler addon is required to compile edited scripts. A modpack can instead ship scripts that were compiled ahead of time.
Copy file name to clipboardExpand all lines: docs/en/scripting/events/index.mdx
+33-9Lines changed: 33 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,42 +11,66 @@ order: 1
11
11
12
12
The HollowEngine event system lets you inject custom logic into specific in-game actions, including player actions, entity actions, block updates, and more.
13
13
14
+
## Which side an event fires on
15
+
16
+
Minecraft is split into two sides: the **server** runs the world and the players, the **client** draws the picture and takes input. Even singleplayer runs a separate server inside. That is why every event in this section states its side, and it has to be listened to from a matching script:
|**Client**| a `.reload.kts` with `@file:ClientSide`|
22
+
|**Both sides**| either of them: a server script gets the server copy of the event, a client script the client copy |
23
+
|**Game startup**| only `.startup.kts`: the event fires once, before any reloadable script exists |
24
+
25
+
If you subscribe to an event from the wrong side, the engine logs an error when the script starts. That makes it easy to see why a handler "does not fire on the server".
26
+
27
+
:::advice
28
+
`.startup.kts` scripts and addons are not bound to a side and receive events of both sides. When such code listens to a "both sides" event, check the side yourself, for example with `event.player.level().isClientSide`.
29
+
:::
30
+
14
31
## Creating a handler
15
32
16
-
There are two ways to create a handler: automatically (see [reloadable scripts](/docs/hollowengine/scripting/reload)) or manually by creating and registering a function:
33
+
The simplest way to subscribe is the `@SubscribeEvent` annotation in a [reloadable script](/docs/hollowengine/scripting/reload). If a handler has to be added from code, for example only under some condition, subscribe through the script's scope:
17
34
18
35
```kotlin
19
36
funonPlayerJoin(event:PlayerEvent.Join) {
20
37
event.player.send("Welcome back!")
21
38
}
22
39
23
-
val handle =PlayerEvent.Join.register(::onPlayerJoin) // Start listening for the event and store the handler
24
-
PlayerEvent.Join.unregister(handle) // Stop listening for the event (the method will no longer be called)
// You can also pass a lambda instead of a function:
27
-
PlayerEvent.Join.register { event ->
43
+
PlayerEvent.Join.subscribe(this) { event ->
28
44
event.player.send("Welcome back!")
29
45
}
30
46
```
31
47
48
+
`this` here is the reloadable script itself: the subscription lives as long as the script and is removed when it restarts. It respects the script's side just like `@SubscribeEvent`.
49
+
50
+
:::warning
51
+
`PlayerEvent.Join.register { ... }` without a scope subscribes forever, until the game exits. In scripts such a handler is not removed on `/reload` and fires once more after every restart.
52
+
:::
53
+
32
54
## Priorities
33
55
34
56
Sometimes an event needs to run before other handlers, especially if it may cancel the event.
35
-
You can change the handler order by configuring its priority:
57
+
Pass a priority: the higher it is, the earlier the handler runs. The default priority is zero.
Copy file name to clipboardExpand all lines: docs/en/scripting/events/jei_events.mdx
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,23 @@ order: 6
5
5
6
6
*Events that allow integration with Just Enough Items (JEI): registering categories and recipes, hiding them, or adding item descriptions.*
7
7
8
+
**Side:** client (every event on this page)
9
+
10
+
:::warning
11
+
JEI only runs in the player's game, so these events have to be listened to from a client script: add `@file:ClientSide` at the top of the `.reload.kts`. A server script cannot subscribe to them, and the engine logs an error saying so.
0 commit comments