Using the API - Crystal-Nest/soul-fire-d GitHub Wiki

Fire Manager

FireManager is a utility class with many methods to retrieve data from all registered Fires.
Each method comes with a Javadoc explaining its use, most are getters and their use is straightforward.
Here a couple of useful methods are seen in more depth:

  • sanitize(String, String) / sanitize(ResourceLocation)
    Checks if the given Mod Id and Fire Id, or the ResourceLocation/Identifier, are valid and if so returns them.
    If they are not valid, returns FireManager#DEFAULT_FIRE_TYPE (Fire Type of normal fire).
    Does not check if there's a Fire registered with the provided values.
  • ensure(String, String) / ensure(ResourceLocation)
    Checks if the given Mod Id and Fire Id, or the ResourceLocation/Identifier, are valid and registered and if so returns them.
    If they are not valid, returns FireManager#DEFAULT_FIRE_TYPE (Fire Type of normal fire).
    Does check if there's a Fire registered with the provided values.

Finally there is also a method to unregister a previously registered Fire. However this MUST NEVER be used under any circumstance, it is deprecated and for internal use only.

Set on fire

All base cases are handled by this mod once a Fire is registered, for example you don't have to worry about setting an entity on fire when it goes into your fire source block.
However you may wish to set on a specific kind of fire a certain entity in a different situation from the base ones, for example with Torch hit! torch hits represent a new use case where handling setting on fire is needed.
To set on fire an entity while keeping this mod features you just need to call FireManager.setOnFire(Entity, int, ResourceLocation) passing it the entity you wish to set on fire, the amount of seconds the fire should last for and the Fire Type of the registered Fire.

Clear fire

Removing any fire from any entity is as easy as using base Minecraft method Entity.clearFire() (Entity.extinguish() on Fabric).

Hurting and healing

There are 3 ways to hurt/heal an entity with your custom Fire:

  1. Set the entity on fire as explained above and let the mod handle the rest.
  2. Using FireManager.damageInFire(Entity, ResourceLocation).
  3. Using FireManager.damageOnFire(Entity, ResourceLocation).

The difference between damageInFire and damageOnFire is the use context: damageInFire should be used when the entity is taking damage because it's inside or above a block considered as a fire source, like a campfire or a Fire block, while damageOnFire should be used when an entity is burning.
The API will take care of using the proper DamageSource, damage and choosing between hurting or healing.
You just need to pass to those methods the Entity you wish to hurt/heal and the Fire Type and everything will work accordingly to the configuration of the registered Fire!

Handling NBTs

There are also two methods used to write and read a Fire Type from NBTs:

  • writeNbt(CompoundTag, ResourceLocation) (Forge) / writeNbt(NbtCompound tag, Identifier fireType) (Fabric)
    Used to write to an NBT tag the given Fire Type.
  • readNbt(CompoundTag) (Forge) / readNbt(NbtCompound tag) (Fabric)
    Used to read a Fire Type from the given NBT tag.