# Event Basics

If you are familiar with Java libraries like `javax.swing`, or have done Forge/Fabric coding before, then don't worry - events shouldn't be a mystery to you!

Forge and Fabric already use events. However, they are not very multiplatform - they change massively version to version. That's why OneConfig has its own event system, helping OneConfig to achieve its aim of uniting all Minecraft mods.

## Getting on the Bus

To get events to work, its important to register any Object/Class that uses them to the EventBus. This is very simple, and its a great idea to do this in your constructor, for example:

```java
public MyClassConstructor() {
    EventManager.INSTANCE.register(this);
}
```

This will allow that class to use the Event system. Continue reading to subscribe to your first event!

## Using the Bus

Once you have registered your class, you can now `@Subscribe` to (use) the events you would like. For example, to subscribe to a TickEvent:

```java
@Subscribe
private void onTick(TickEvent event) { // the parameter type specifies what event you are subscribing to
    // do something every tick (once every 50ms in Minecraft)
}
```

{% hint style="danger" %}
All methods annotated with `@Subscribe` must not be static!
{% endhint %}

So, as a general rule for events:

* [ ] Subscribe your class to the EventBus using EventManager
* [ ] Annotate your method you would like to use an event using `@Subscribe`
* [ ] Choose your event type by setting the parameter type in the method (you can name the variable whatever you want, a common name is just `event`)

Easy as that!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.polyfrost.org/oneconfig/events/event-basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
