The event Manager is your go-to point if you want to register custom event handlers.

You can register EventHandlers for everything that derives from MCEvent. Make sure to tell ZC of the type you are using, so that you can access the event's properties.

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

ZenScript
Copy
import crafttweaker.api.events.CTEventManager;

Name: register

Registers a new Event listener.

Return Type: void

ZenScript
Copy
// CTEventManager.register<T : MCEvent>(consumer as Consumer<T>) as void

CTEventManager.register<crafttweaker.api.event.entity.player.MCAnvilRepairEvent>((event) => {
 var player = event.player;
 var result = event.itemResult;
 println("Player '" + player.name + "' crafted " + result.commandString);
 });
CTEventManager.register<crafttweaker.api.event.MCEvent>((event) => {
 //Don't actually register a consumer for every event
 println("Some Event was captured");
 });
参数类型描述
参数
消费者
类型
Consumer<T>
描述
The event handler as consumer
参数
T
类型
MCEvent
描述
The type of the event

Name: register

Registers a new Event listener with a specific priority.

Return Type: void

ZenScript
Copy
// CTEventManager.register<T : MCEvent>(priority as EventPriority, consumer as Consumer<T>) as void

CTEventManager.register<crafttweaker.api.event.entity.player.MCAnvilRepairEvent>(EventPriority.HIGHEST, (event) => {
 var player = event.player;
 var result = event.itemResult;
 println("Player '" + player.name + "' crafted " + result.commandString);
 });
参数类型描述
参数
priority
类型
EventPriority
描述
priority for this listener
参数
消费者
类型
Consumer<T>
描述
The event handler as consumer
参数
T
类型
MCEvent
描述
The type of the event