# Developer API

## Links

* [#how-it-works](#how-it-works "mention")
* [#weaponmechanicsapi](#weaponmechanicsapi "mention")
* [#events](#events "mention")
* [Cloning Repository](/weaponmechanics/developer-api/cloning-repository.md)
* [Projectile Scripts](/weaponmechanics/developer-api/projectile-scripts.md)

***

## How it works

Before jumping into contributing or making your addon, you should be familiar with the "big" sections of WeaponMechanics.

#### Data Serialization

Instead of pulling values from a `YamlConfiguration` instance, WeaponMechanics stores a flattened `Map<String, Object>`, and each weapon uses probably 100 different "serializers." We coded these serializers to check for user errors, and to report them to the console immediately.&#x20;

#### Projectiles

WeaponMechanics does not use Minecraft entities. Instead, we use "fake" ray-traced projectiles. When you use a disguise like a snowball or armor stand, WeaponMechanics spawns a fake entity using packets.

#### Weapon Handlers

The "big chunks of logic" are separated into handlers, like the ShootHandler and the ReloadHandler.&#x20;

***

## WeaponMechanicsAPI

The [WeaponMechanicsAPI class](https://github.com/WeaponMechanics/MechanicsMain/blob/master/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanicsAPI.java) is a list of easy-access examples. If you are looking for a specific method, try tracing the API calls to their source (This will help you find new methods).

{% hint style="success" %}
Want a new API method added? Submit a feature request!
{% endhint %}

**Checking if a Player is scoping/reloading/whatever**

WeaponMechanics has player wrappers. Use `WeaponMechanics.getEntityWrapper(entity)` to get a wrapper. You probably want to get `HandData` (use `IEntityWrapper#getMainHandData()` and `IEntityWrapper#getOffHandData()`).

**Generating/Giving weapon items**

The `InfoHandler` handles weapon generation. Use `WeaponMechanics.getWeaponHandler().getInfoHandler()`. It can also be used to check if an existing `ItemStack` is a WeaponMechanics weapon.

**Spawning Projectiles**

Perhaps you want to spawn in a projectile after implementing your custom projectile or using one of the premade projectile classes. While you can create your own repeating task, this becomes messy. Instead, add projectiles to the `ProjectilesRunnable` instance (Use `WeaponMechanics.getProjectilesRunnable()`) then add projectiles through that.

**Checking for block regeneration**

You probably don't want to interfere with block regeneration when working in protected regions. Or perhaps you are implementing a feature that causes block damage and want to use WeaponMechanic's premade system. Either way, look at `BlockDamageData`.

## Events

For the complete list of events, check out the [events package](https://github.com/WeaponMechanics/MechanicsMain/tree/master/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/weaponevents). Most events inherit from the `WeaponEvent` class.


---

# 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://cjcrafter.gitbook.io/weaponmechanics/developer-api.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.
