Skip to content

Magic Helper Methods

Deadlydiamond98 edited this page Aug 1, 2024 · 8 revisions


Methods

addMana(int amount)

Adds Mana to entity if the entity's mana isn't at the maximum level

If the amount of mana added to the entity is greater than the max level, but the entity's mana bar isn't full, the entity's mana will fill to be the max level

If the amount of mana added is negative, removeMana(amount * -1) will be called


removeMana(int amount)

Removes Mana from entity if the entity's mana isn't less than or equal to 0

If the amount of mana removed from the entity is greater than the amount of mana the entity has, mana won't be removed

If the amount of mana added is negative, addMana(amount * -1) will be called


canAddMana(int amount)

Returns true if the Mana isn't at its max level


canRemoveMana(int amount)

Returns true if the amount of mana can be removed from the entity without dipping below 0


increaseMaxMana(int amount, boolean replenish)

Increases the entity's Maximum mana by amount. If Replenish is true, the entity will also have its mana increase by amount

If the amount of mana added is negative, decreaseMaxMana(amount * -1) will be called


decreaseMaxMana(int amount)

Decreases the entity's Maximum mana by amount. If The Mana decrease ends up being less than 1, it doesn't remove the mana.

If the amount of mana added is negative, increaseMaxMana(amount * -1, false) will be called


canDecreaseMaxMana(int amount)

Checks if the entity's maximum mana can be decreased by amount without being less than 1


enableManaRegen(boolean regen, int tickPause, int amount)

Allows an entity to regenerate mana passively if it is true.

tickPause determines how many ticks need to pass before increasing the entity's mana by amount (if tickPause is 40 and amount is 1, the entity will regenerate 1 mana every 40 ticks)


hasManaRegen()

Returns true if the entity is passively regenerating Mana


How to Use

All entities start off with a Magic Level of 0 and a Max Magic of 100 by default. They are added to LivingEntities, so you just call it like any other LivingEntity method

Here's a small example on how you'd call these methods:

public void exampleManaMethod(LivingEntity user) {
    if (user.canAddMana(10)) {
        user.addMana(10)
    }

Other

While the methods getWhenNeededRenderTime() and setWhenNeededRenderTime() exist, they should be left alone as they are used for Client-Side rendering of the Magic Bar if the Magic Bar is set to only be on screen When Needed.

Clone this wiki locally