Skip to content
CleverNucleus edited this page Jun 22, 2021 · 3 revisions

Events

The API introduces three new events:

PlayerAttributeModifiedEvent

This event fires on the server only whenever an attribute's value changes (for GAME type attributes that includes when modifiers are applied/removed). The event passes through a player instance (using PlayerEntity, however the implementation is ServerPlayerEntity), a player attribute instance (using IPlayerAttribute), the attributes old value and its new value. If you want to add some functionality to your attribute whenever its value changes, you must test that the attribute is yours, as shown below:

PlayerAttributeModifiedEvent.MODIFIED.register((player, attribute, oldValue, newValue) -> {
    if(attribute.equals(ExampleMod.MAX_MANA.get()) {
        // Do something whenever Max Mana's value changes
    }
});

PlayerLevelUpEvent

This event fires on the server only whenever enough vanilla experience levels are gained to level up. The event fires only once, and until the player chooses to level up, the event will not fire again no matter how much experience is gained. It only fires on the first instance of enough experience levels. The event passes through a player instance (using PlayerEntity, however the implementation is ServerPlayerEntity). It can be used as shown below:

PlayerLevelUpEvent.LEVEL_UP.register(player -> {
    // Do something here; maybe shoot a firework
});

NameplateRenderEvent

This event fires on the client only whenever a player's nameplate is rendered (i.e. not when invisible or too far away). PlayerEx uses this event to add in the optional lvl n nameplate just below the player's name. The event passes through a PlayerEntityRenderer instance, an AbstractClientPlayerEntity instance, a MatrixStack, a VertexConsumerProvider and an int for light.

It can be used as shown below (this should be used in a client entry point):

NameplateRenderEvent.ON_RENDER.register((renderer, player, matrixStack, vertexConsumerProvider, light) -> {
    // Do something
});