Skip to content

Commit

Permalink
World-Events
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-Cryptic committed Oct 8, 2024
1 parent ea9b6fb commit 8ea3ed0
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions docs/wiki/World-Events.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
# WIP DOCS | Any code here is subject to major change
World Events are designed to solve the biggest issues with entities being that entities will only be ticked/loaded when the chunks they are in are loaded. Instead they are ticked on the level for both the server and client.
# What Are World Events?
World events are tickable instanced objects which are saved in a level capability, which means they are unique per dimension.
They can exist on the client and are ticked separately. World Events on the client can have renderers attached to them.

# Getting Started
As of Lodestone 1.21-1.7
To create your first world event type you must register it with a custom DeferredRegister. Lodestone has some helper methods to make this process easier for you.
# Getting Started With World Events
As of Lodestone 1.21-1.7, World Events are now registered using a DeferredRegister.
Lodestone has some helper methods to make this process easier for you.
```java
public class WorldEventTypeRegistry {
private static final DeferredRegister<WorldEventType> WORLD_EVENT_TYPES = LodestoneWorldEventTypeRegistry.createRegister("mymod");
private static final Registry<WorldEventType> REGISTRY = LodestoneWorldEventTypeRegistry.makeRegistry(WORLD_EVENT_TYPES);

public static final Supplier<WorldEventType> EXAMPLE_WORLD_EVENT = WORLD_EVENT_TYPES.register("example_event", () ->
WorldEventType.Builder.of(ExampleWorldEvent::new, ResourceLocation.fromNamespaceAndPath("mymod", "example_event"))
.clientSynced(null) // Null = no renderer but still sync to client
.build()
);
private static final Registry<WorldEventType> REGISTRY = LodestoneWorldEventTypeRegistry.makeRegistry(WORLD_EVENT_TYPES);
}
```
Like any DeferredRegister, you must initialize it with the Event Bus
```java
public class WorldEventTypeRegistry {
private static final DeferredRegister<WorldEventType> WORLD_EVENT_TYPES = LodestoneWorldEventTypeRegistry.createRegister("mymod");
private static final Registry<WorldEventType> REGISTRY = LodestoneWorldEventTypeRegistry.makeRegistry(WORLD_EVENT_TYPES);

public static void init(IEventBus eventBus) {
WORLD_EVENT_TYPES.register(eventBus);
}

}
```
Now to make your first WorldEventType you can use a [WorldEventType.Builder](https://github.com/LodestarMC/Lodestone/blob/1.21/src/main/java/team/lodestar/lodestone/systems/worldevent/WorldEventType.java#L45) which will automatically register any [WorldEventRenderer](https://github.com/LodestarMC/Lodestone/blob/1.21/src/main/java/team/lodestar/lodestone/systems/worldevent/WorldEventRenderer.java) you attach to it with [WorldEventType.Builder#clientSynced](https://github.com/LodestarMC/Lodestone/blob/1.21/src/main/java/team/lodestar/lodestone/systems/worldevent/WorldEventType.java#L74C27-L74C71).
```java
public class WorldEventTypeRegistry {
private static final DeferredRegister<WorldEventType> WORLD_EVENT_TYPES = LodestoneWorldEventTypeRegistry.createRegister("mymod");
private static final Registry<WorldEventType> REGISTRY = LodestoneWorldEventTypeRegistry.makeRegistry(WORLD_EVENT_TYPES);

public static final Supplier<WorldEventType> EXAMPLE_WORLD_EVENT = WORLD_EVENT_TYPES.register("example_event", () ->
WorldEventType.Builder.of(ExampleWorldEvent::new, ResourceLocation.fromNamespaceAndPath("mymod", "example_event"))
.clientSynced(null) // Null = no renderer but still sync to client
.build()
);

public static void init(IEventBus eventBus) {
WORLD_EVENT_TYPES.register(eventBus);
}

}
```

0 comments on commit 8ea3ed0

Please sign in to comment.