The Magic Bar is a GUI feature added by Koala Lib. The Magic Bar will only refill itself when the player is at full hunger and doesn't have a Magic Regeneration Delay. Various Items can be used to add or remove Magic from the Magic Bar.

Screenshot of the Magic Bar in Game

Every time Magic is consumed, the following formula is used to add a Magic Regeneration Delay to the player:

floor( min( 0.7 * (1 - (mana / max mana)) * 500 - 45 , -60)


Koala Lib allows you to change the position of the Magic Bar on screen, and change when the Magic Bar is shown (Always, When Using, or Never).

Using the Library

To enable the Magic Bar in a mod, you can toggle it in your mod's initializer:

public class KoalaLib implements ModInitializer {
	@Override
	public void onInitialize() {
        ToggleableContent.enableMagicBar(true);
    }
}

Doing this will show the bar on screen and allow you to use it. There are a few built in Items to help with creating Items that Consume or Grant Magic, but there are also many built in helper methods in the MagicBarHelper class.



Adding Magic

public static boolean addMana(LivingEntity entity, int amount)

The addMana() method takes in an entity and an amount. The entity is the entity that magic will be added to, while the amount is the magic the entity will be granted.

Removing Magic

public static boolean removeMana(LivingEntity entity, int amount)

The removeMana() method takes in an entity and an amount. The entity is the entity that magic will be removed from, while the amount is the magic the entity will loose. This method will apply a regeneration delay which will prevent magic from being gained for a small period.

public static boolean removeMana(LivingEntity entity, int amount, boolean addDelay)

There is an alternative method which also takes in a boolean, "addDelay". If this is false, a regeneration delay won't be applied to the entity.

Adding Max Magic

public static boolean increaseMaxMana(LivingEntity entity, int amount, boolean replenish)

The increaseMaxMana() method increases the maximum magic on an entity. The entity is the entity that magic will be added to, while the amount is the magic the entity will have added to their max. The "replenish" value will determine if the amount added will be replenished.

Removing Max Magic

public static boolean decreaseMaxMana(LivingEntity entity, int amount)

The decreaseMaxMana() method decreases the maximum magic on an entity. The entity is the entity that magic will be added to, while the amount is the magic the entity will have removed from their max.



Magic checks

public static boolean canAddMana(LivingEntity entity, int amount)

This method can be used to check if Mana can be added.

public static boolean canRemoveMana(LivingEntity entity, int amount)

This method can be used to check if Mana can be removed.

public static boolean canDecreaseMaxMana(LivingEntity entity, int amount)

This method can be used to check if the max Mana can be decreased (meaning it wouldn't go below zero).