Skip to content

Commit

Permalink
MAJOR CHANGE: Seperated ArchEvents.handle and FabricEvents.handle int…
Browse files Browse the repository at this point in the history
…o handleServer, handleClient, handleStartup.

Updated to be compatible with 6.1
  • Loading branch information
Hunter19823 committed Sep 11, 2023
1 parent d390b74 commit fb65483
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See the below example for how to listen to the event.

```js
// See above for the first part of this example.
ArchEvents.handle('server starting', event => {
ArchEvents.handleServer('server starting', event => {
console.log('Custom Arch Event handler has fired!');
console.log("Event Class: " + event); // Returns the class of the event. (It's always a ProxyClass)
console.log("Method Name: " + event.getMethodName()); // Returns the name of the method that fired the event.
Expand All @@ -71,13 +71,22 @@ ArchEvents.handle('server starting', event => {
// We can return a value like so:
// event.setResult("Hello World!");
});
// Pre KubeJS 6.0, you would use ArchEvents.handle for all script types.
// Instead of ArchEvents.handleClient, ArchEvents.handleServer, or ArchEvents.handleStartup.
```

This example showcases how to listen to the event we registered above.
You use the name of the event you registered to listen to it.
The event parameter is an instance of the `ProxyClass` class.
You can listen to any event from any script context (Startup, Client, Server) with the same syntax.

***Important Note for KubeJS Additions 3.2.0+ (KubeJS 6.1+)***:

Due to changes with KubeJS Event handlers, `ArchEvents.handle` has been split into `ArchEvents.handleClient`, `ArchEvents.handleServer`, and `ArchEvents.handleStartup` for each script type respectively.
The syntax is the same as the above example, however, you must use the correct method for the script type you are using.

For previous versions of KubeJS Additions, you can use `ArchEvents.handle` for all script types.

## [Custom Fabric Event Listeners](https://github.com/Hunter19823/kubejsadditions/blob/3d489ddef363573218f68a8a7e34f924729fe1c2/fabric/src/main/java/pie/ilikepiefoo/fabric/FabricEventsJS.java#L60)

#### Fabric Event Register (Startup) (Cannot be reloaded without a restart)
Expand All @@ -104,7 +113,7 @@ See the below example for how to listen to the event.

```js
// See above for the first part of this example.
FabricEvents.handle('chat messages', event => {
FabricEvents.handleServer('chat messages', event => {
console.log('Custom Arch Event handler has fired!');
console.log("Event Class: " + event); // Returns the class of the event. (It's always a ProxyClass)
console.log("Method Name: " + event.getMethodName()); // Returns the name of the method that fired the event.
Expand All @@ -118,13 +127,23 @@ FabricEvents.handle('chat messages', event => {
// We can return a value like so:
// event.setResult("Hello World!");
});

// Pre KubeJS 6.0, you would use FabricEvents.handle for all script types.
// Instead of FabricEvents.handleClient, FabricEvents.handleServer, or FabricEvents.handleStartup.
```

This example showcases how to listen to the event we registered above.
You use the name of the event you registered to listen to it.
The event parameter is an instance of the `ProxyClass` class.
You can listen to any event from any script context (Startup, Client, Server) with the same syntax.

***Important Note for KubeJS Additions 3.2.0+ (KubeJS 6.1+)***:

Due to changes with KubeJS Event handlers, `FabricEvents.handle` has been split into `FabricEvents.handleClient`, `FabricEvents.handleServer`, and `FabricEvents.handleStartup` for each script type respectively.
The syntax is the same as the above example, however, you must use the correct method for the script type you are using.

For previous versions of KubeJS Additions, you can use `FabricEvents.handle` for all script types.

### [Common Events](https://github.com/Hunter19823/kubejsadditions/blob/1.19.2/common/src/main/java/pie/ilikepiefoo/events/AdditionalEvents.java)

#### Entity Enter Chunk (Server Only)
Expand Down
30 changes: 15 additions & 15 deletions common/src/main/java/pie/ilikepiefoo/events/AdditionalEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
import pie.ilikepiefoo.events.custom.ArchEventRegisterEventJS;

public interface AdditionalEvents {
EventGroup GROUP = EventGroup.of("CommonAddedEvents");
EventGroup GROUP = EventGroup.of("CommonAddedEvents");

EventHandler ENTITY_ENTER_CHUNK = GROUP.server("entityEnterChunk", () -> EntityEnterChunkEventJS.class);
EventHandler ENTITY_TAME = GROUP.server("entityTame", () -> EntityTameEventJS.class).hasResult();
EventHandler PLAYER_CHANGE_DIMENSION = GROUP.server("playerChangeDimension", () -> PlayerChangeDimensionEventJS.class);
EventHandler PLAYER_CLONE = GROUP.server("playerClone", () -> PlayerCloneEventJS.class);
EventHandler PLAYER_RESPAWN = GROUP.server("playerRespawn", () -> PlayerRespawnEventJS.class);
EventHandler ENTITY_ENTER_CHUNK = GROUP.server("entityEnterChunk", () -> EntityEnterChunkEventJS.class);
EventHandler ENTITY_TAME = GROUP.server("entityTame", () -> EntityTameEventJS.class).hasResult();
EventHandler PLAYER_CHANGE_DIMENSION = GROUP.server("playerChangeDimension", () -> PlayerChangeDimensionEventJS.class);
EventHandler PLAYER_CLONE = GROUP.server("playerClone", () -> PlayerCloneEventJS.class);
EventHandler PLAYER_RESPAWN = GROUP.server("playerRespawn", () -> PlayerRespawnEventJS.class);

EventGroup ARCH_EVENTS = EventGroup.of("ArchEvents");
EventHandler ARCH_STARTUP_EVENT_HANDLER = ARCH_EVENTS.startup("handle", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler ARCH_CLIENT_EVENT_HANDLER = ARCH_EVENTS.client("handle", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler ARCH_SERVER_EVENT_HANDLER = ARCH_EVENTS.server("handle", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler ARCH_EVENT_REGISTER = ARCH_EVENTS.startup("registry", () -> ArchEventRegisterEventJS.class);
EventGroup ARCH_EVENTS = EventGroup.of("ArchEvents");
EventHandler ARCH_STARTUP_EVENT_HANDLER = ARCH_EVENTS.startup("handleStartup", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler ARCH_CLIENT_EVENT_HANDLER = ARCH_EVENTS.client("handleClient", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler ARCH_SERVER_EVENT_HANDLER = ARCH_EVENTS.server("handleServer", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler ARCH_EVENT_REGISTER = ARCH_EVENTS.startup("registry", () -> ArchEventRegisterEventJS.class);

static void register() {
GROUP.register();
ARCH_EVENTS.register();
}
static void register() {
GROUP.register();
ARCH_EVENTS.register();
}

}
34 changes: 17 additions & 17 deletions fabric/src/main/java/pie/ilikepiefoo/fabric/FabricEventsJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ public interface FabricEventsJS {
// World Render Events
EventHandler BEFORE_ENTITIES = GROUP.client("beforeEntities", () -> WorldRenderContextEventJS.class);
EventHandler AFTER_ENTITIES = GROUP.client("afterEntities", () -> WorldRenderContextEventJS.class);
EventHandler AFTER_TRANSLUCENT = GROUP.client("afterTranslucent", () -> WorldRenderContextEventJS.class);
EventHandler AFTER_SETUP = GROUP.client("afterSetup", () -> WorldRenderContextEventJS.class);
EventHandler START_RENDER = GROUP.client("startRender", () -> WorldRenderContextEventJS.class);
EventHandler LAST_RENDER = GROUP.client("lastRender", () -> WorldRenderContextEventJS.class);
EventHandler END_RENDER = GROUP.client("endRender", () -> WorldRenderContextEventJS.class);
EventHandler BEFORE_BLOCK_OUTLINE = GROUP.client("beforeBlockOutline", () -> BeforeBlockOutlineRenderEventJS.class).hasResult();
EventHandler BLOCK_OUTLINE = GROUP.client("blockOutline", () -> BlockOutlineRenderEventJS.class);
EventHandler AFTER_TRANSLUCENT = GROUP.client("afterTranslucent", () -> WorldRenderContextEventJS.class);
EventHandler AFTER_SETUP = GROUP.client("afterSetup", () -> WorldRenderContextEventJS.class);
EventHandler START_RENDER = GROUP.client("startRender", () -> WorldRenderContextEventJS.class);
EventHandler LAST_RENDER = GROUP.client("lastRender", () -> WorldRenderContextEventJS.class);
EventHandler END_RENDER = GROUP.client("endRender", () -> WorldRenderContextEventJS.class);
EventHandler BEFORE_BLOCK_OUTLINE = GROUP.client("beforeBlockOutline", () -> BeforeBlockOutlineRenderEventJS.class).hasResult();
EventHandler BLOCK_OUTLINE = GROUP.client("blockOutline", () -> BlockOutlineRenderEventJS.class);

// Custom Events
EventGroup CUSTOM = EventGroup.of("FabricEvents");
EventHandler FABRIC_STARTUP_EVENT_HANDLER = CUSTOM.startup("handle", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler FABRIC_CLIENT_EVENT_HANDLER = CUSTOM.client("handle", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler FABRIC_SERVER_EVENT_HANDLER = CUSTOM.server("handle", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler FABRIC_EVENT_REGISTER = CUSTOM.startup("registry", () -> FabricEventRegisterEventJS.class);
// Custom Events
EventGroup CUSTOM = EventGroup.of("FabricEvents");
EventHandler FABRIC_STARTUP_EVENT_HANDLER = CUSTOM.startup("handleStartup", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler FABRIC_CLIENT_EVENT_HANDLER = CUSTOM.client("handleClient", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler FABRIC_SERVER_EVENT_HANDLER = CUSTOM.server("handleServer", () -> ProxyEventJS.class).extra(Extra.REQUIRES_STRING);
EventHandler FABRIC_EVENT_REGISTER = CUSTOM.startup("registry", () -> FabricEventRegisterEventJS.class);

static void register() {
GROUP.register();
CUSTOM.register();
}
static void register() {
GROUP.register();
CUSTOM.register();
}

}

6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enabled_platforms=fabric,forge
archives_base_name=kubejsadditions
mod_id=kubejsadditions
mod_name=KubeJS Addditions
mod_version=3.1.1
mod_version=3.2.0
mod_description=A mod that adds a bunch of additional features to KubeJS.
mod_author=ILIKEPIEFOO2
mod_icon=assets/kubejsadditions/kubejs_logo.png
Expand All @@ -19,9 +19,9 @@ architectury_version=6.5.82
fabric_loader_version=0.14.20
fabric_api_version=0.76.0
forge_version=43.2.11
kubejs_version=1902.6.1-build.348
kubejs_version=1902.6.2-build.15
jei_version=11.6.0.1016
mixin_extras=0.2.0-beta.9
mixin_extras=0.2.0-rc.2
# Mod upload info
curseforge_id=594387
modrinth_id=BZemjxZb
Expand Down

0 comments on commit fb65483

Please sign in to comment.