Using Rhino Events to React to In-Game Actions
What Events Are
Most mods that use Rhino expose an event system. Events let your script run code when something happens in the world, such as a player joining, a block being broken, or a tick passing. Instead of polling for changes, you register a callback that the mod calls for you.
Registering a Callback
1. Find the event registration function in the host mod's scripting API. It typically takes an event name and a function.
2. Write your handler function. It usually receives an event object containing details like the player, position, or block involved.
3. Inside the handler, read the fields you need from the event object and perform your logic.
4. Register the handler once, typically at the top level of your script, not inside another function, so it is set up when the script loads.
Practical Tips
Keep handlers short. If you need heavy computation, check whether the event fires every tick, because that can lag the game. Use the event object's cancellation method if the mod supports it and you want to prevent the default action. Log inside handlers while developing so you can confirm they fire when expected.