IEvent
Namespace Mc.Scripting · Kind interface
public interface IEventAn event type. Catalogue events are ref structs: a handler gets the event by reference and can neither store it nor capture it in a closure or an async method, so the borrowed native data it carries (strings, byte buffers) cannot outlive the dispatch. Plugin-defined events are ordinary blittable structs that start with an EventHeader field (or ref structs of the same layout).
Remarks
Section titled “Remarks”Catalogue events are generated from src/scripting/events.json. Plugins can declare their own events: implement IEvent.Key (e.g. “myplugin:thing”) and leave IEvent.CatalogueId at 0; an id is assigned at runtime.
Examples
Section titled “Examples”A custom event
public struct HomeSetEvent : IEvent{ public EventHeader Header; // must come first public Entity Player; public BlockPos Position;
public static string Key => "homes:set"; public static bool IsCancellable => true;}
// fire it from your pluginvar ev = new HomeSetEvent { Player = p, Position = pos };if (Events.Fire(ref ev)) { /* nobody cancelled */ }Properties
Section titled “Properties”| Member | Description |
|---|---|
static virtual ushort CatalogueId { get; } |
Catalogue id for built-in events, 0 for plugin-defined events. |
static virtual bool IsCancellable { get; } |
Whether handlers can cancel the event. |
static abstract string Key { get; } |
Registry key (“plugin:name” for plugin events). |
CatalogueId
Section titled “CatalogueId”static virtual ushort CatalogueId { get; }Catalogue id for built-in events, 0 for plugin-defined events.
IsCancellable
Section titled “IsCancellable”static virtual bool IsCancellable { get; }Whether handlers can cancel the event.
static abstract string Key { get; }Registry key (“plugin:name” for plugin events).