Download EventsLib — Minecraft Mods — MetaMods

EventsLib

Active

Downloads

0

Last update

5 months ago

Versions

1.21 — 1.21.5
Client and server
Neoforge
Libraries

EventsLib

This is a library mod created to expand capabilities of other modifications that require more detailed events when working with status effects. This content does not add any items to the game and by itself does not alter gameplay. For regular players it will remain useless until a modification that utilizes its functionality is installed.

The main purpose is to provide mod developers with additional tools for precisely tracking effect application on creatures. Specifically, it adds the MobEffectTickEvent, through which one can obtain information about what portion of the effect's duration remains (in percentage), as well as directly access the effect instance itself and the entity it affects.

// Example of using MobEffectTickEvent
@SubscribeEvent
public static void onMobEffectTick(MobEffectTickEvent event) {
    float remainingPercentage = event.getPercentageLeft();
    String entityName = event.getEntity().getName().getString();
    String effectName = event.getEffectInstance().getEffect().value().toString();

    System.out.println("Entity: " + entityName
            + " is affected by: " + effectName
            + " with " + remainingPercentage + "% duration remaining.");

    if (remainingPercentage == 50.0f) {
        System.out.println("Effect on " + entityName + " reached half duration for: " + effectName);
    }
    if (remainingPercentage == 20.0f) {
        System.out.println("Effect on " + entityName + " decreased to 20% duration: " + effectName);
    }
}

The library also includes a method that activates once when the effect's action completely ends. For example, in the Fargo's Talismans modification this functionality is used to remove attributes added to the player through the pedestal, which is a more efficient solution compared to constant tracking through the PlayerTick method.

// Example of using onEffectRemoved (in a class extending MobEffectEndEffect)
@Override
public void onEffectRemoved(LivingEntity entity, int amplifier) {
    super.onEffectRemoved(entity, amplifier);
    if (entity instanceof Player) {
        System.out.println("The effect's action has ended.");
    }
}
Project members
STS15

STS15

Developer

Created: 22 May 2025

ID: 65426