• For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
  • For issues you find with the Mobile 1.3 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.

tModLoader Yet Another Boss Health Bar

Flashkirby99

Skeletron

Yet Another Boss Health Bar

v1.3.2, for tModLoader v0.10.1.4​

(This is not Boss Health Bars)

What's the difference between this and Boss Health Bars? Preference mostly. Barack Obama Ross' one has more customisation, whereas this one is more silly effects.

Based on the Boss Health Bars mod, but with my own twist on it because why not.
  • Show the boss' head icon.
  • Kinda supports non-standard bosses.
  • Has extra settings stored in Mod Configs/YetAnotherBHB.json
  • Easily extensible for modders.
  • Support for hamstar's Mod Helpers mod.
ShowBossHealthBars (true) enable health bars.
SmallHealthBars (false) force all health bars to use the small frame.
HealthBarDrawDistance (5000) maximum distance away from a boss health bars will be drawn for.
HealthBarUIScreenOffset (16) pixel distance from the bottom of the screen to draw from.
HealthBarUIStackOffset (6) pixel distance between each bar when multiple bosses are present.
HealthBarUIDefaultAlpha (1.0) default transparency of drawn bars from 0 (fully transparent) to 1 (opaque).
HealthBarUIMaxStackSize (0.15) amount of the screen that is allowed to be taken by boss health bars.
HealthBarUIScreenLength (0.5) width of the health bar relative to the screen size.
HealthBarUIFadeTime (30) number of frames to fade in/out. 60 frames is 1 second.
HealthBarUIFadeHover (0.5) transparency of health bars when moused over.

HealthBarFXShake (false) enable shaking when a boss takes damage.
HealthBarFXShakeHorizontal (0.5) allow shaking horizontally, which may look messy.
HealthBarFXShakeIntensity (2) how much to shake the bar by.

HealthBarFXChip (true) show the amount of damage dealt over a period of time as a separate bar.
HealthBarFXChipWaitTime (60) length of time before draining the chip bar.
HealthBarFXChipSpeed (0.5) speed that chip damage visual drains.
HealthBarFXChipNumbers (false) display damage dealt on the bar.

SlimeRainBar (false) show progress bar during a slime rain (experimental feature).

Got a boss that's not showing a health bar? Here are some quicka and dirty method calls that will do the trick.

Code:
Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
if(yabhb != null)
{
   // Set up a normal Standard health bar
   Call("RegisterHealthBar", NPCID.Mothron);

   // Set up a normal Small health bar
   Call("RegisterHealthBarMini", NPCID.GoblinSummoner);

   // Set up a normal Multiple groups health bar
   Call("RegisterHealthBarMulti",
     NPCID.PirateShip, NPCID.PirateShipCannon);

   // Set up a demon-themed Standard health bar
   Call("RegisterDemonHealthBar", NPCID.WallofFlesh);

   // Set up a mech-themed Standard health bar
   Call("RegisterMechHealthBar", NPCID.TheDestroyer);
}
Step 1. Spriting
# PREFACE

So, you want to want to make a custom health bar? Well first off there are a couple of things you need to know! There are two main types of health bar styles available, standard and small. Small health bars only appear when manually set, or if the player turns on SmallHealthBars in their config file. So usually you'll just be modifying the standard health bar frames.

# TEXTURES

Health Bar graphics are made of 4 files:
1. Left Frame
2. Middle Frame
3. Right Frame
4. Fill Texture

The height of the Left and Right frames can be any height, but must align from the top.
Similarly, the Mid and Fill textures can also be any height, but must both align from the top together (which can be offset later, read on).
Fill texture should also be greyscale, since it's coloured in-game.

# MidBarOffset
The red line and green lines are the X and Y values of MidBarOffset.
The MidBarOffsetX determines how far the Fill is inset into the Left and Right frames. This must be the same distance for both sides!
The MidBarOffsetY determines how far down the Mid and Fill texture is displaced from the Left and Right frames.

# FillDecoOffset

The fill deco offset determines the X position to split the Fill texture. The left side will be stretched to fit the remaining health, whereas the right side will remain unmodified.

# BossHeadCentre

The red and green lines are the X and Y values of the BossHeadCentre. This determines where to place the boss' map icon (if it has one), from the top left corner.
In the case of boss icons that are centred halfway through a pixel, the icon will be snapped to fit the pixel*2 grid pushed right and down.

# LoopMidBar

When LoopMidBar is set to true, the Mid texture will not stretch, but instead tile-loop from the right side towards the left. Where there is overlap, the Mid texture is drawn BEHIND the Left frame.

# SMALL TEXTURES

Small textures are much more simplified, as all textures MUST be the same height and aligned to the top
Additionally, the Fill cannot indent into the Left and Right frames.
Step 2. Coding
tl;dr check the bottom and the github for examples.

# PREFACE

So, you want to give your boss a customised health bar? Well there are a few things to keep in mind, as different bosses can be implemented in different ways. There are three types of health bar behaviour supported:

Single: For simple boss fights, where the health bar of a single NPC makes up the health of the boss fight. Most vanilla bosses fall under this category.
Multiple: Where the boss fight consist of multiple NPCs with individual health pools. This mode adds up all the health of NPCs under matching types. Bosses such as Eater of Worlds and Brain of Cthulhu fall under this category.
Phase: Slightly experimental behaviour built for modded bosses. When the death of a boss would instead spawn the next phase of the boss fight, use this to show the health of the entire boss fight.

# SETUP
This should go wherever you initialise stuff with in your mod. Typically, the Load() method in your Mod class.
Code:
Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
if(yabhb != null)
{
    // Here is where you define stuff
}
Each custom healthbar begins with:
Code:
yabhb.Call("hbStart");
Which initialises a new health bar. You can then add and change properties such as its texture by various method calls, see # METHODS AVAILABLE.
Once all properties have been set, the bar must be registered to the NPC ID, using one of the following methods:
Code:
// Registers the health bar for a single NPC
yabhb.Call("hbFinishSingle", NPCID.AnglerFish);

// Registers the health bar for multiple NPCs in a group
yabhb.Call("hbFinishMultiple",
    NPCID.EaterofWorldsHead,
    NPCID.EaterofWorldsBody,
    NPCID.EaterofWorldsTail);

// Registers the health bar using phase logic. NPC IDs must be listed in order of phases fought.
yabhb.Call("hbFinishPhases",
    NPCID.GolemHead,
    NPCID.Golem);
# METHODS AVAILABLE
Code:
// Force the bar to always render with small frames
yabhb.Call("hbForceSmall", true);

// Force the bar to never display chip damage FX.
yabhb.Call("hbForceNoChip", true);

// Change rendering behaviour to loop the Mid texture.
yabhb.Call("hbLoopMidBar", true);
Code:
// Set custom textures for the standard health bar
// Values can be left as null to use the default textures
yabhb.Call("hbSetTexture",
    GetTexture("UI/CustomLeftBar"),
    GetTexture("UI/CustomMidBar"),
    GetTexture("UI/CustomRightBar"),
    GetTexture("UI/CustomMidFill"));

// Set custom textures for the standard health bar in expert mode
// Values can be left as null to use the default textures
yabhb.Call("hbSetTextureExpert",
    GetTexture("UI/CustomLeftBar_Expert"),
    GetTexture("UI/CustomMidBar_Expert"),
    GetTexture("UI/CustomRightBar_Expert"));

// Set custom textures for the small health bar
// Values can be left as null to use the default textures
yabhb.Call("hbSetTextureSmall",
    GetTexture("UI/CustomLeftBar_Small"),
    GetTexture("UI/CustomMidBar_Small"),
    GetTexture("UI/CustomRightBar_Small"),
    GetTexture("UI/CustomMidFill_Small"));

// Set custom textures for the small health bar in expert mode
// Values can be left as null to use the default textures
yabhb.Call("hbSetTextureSmallExpert",
    GetTexture("UI/CustomLeftBar_Small_Expert"),
    GetTexture("UI/CustomMidBar_Small_Expert"),
    GetTexture("UI/CustomRightBar_Small_Expert"));
Code:
// Methods for setting the offsets. See part 1 of the tutorial for more information.
yabhb.Call("hbSetMidBarOffsetY", 10);
yabhb.Call("hbSetMidBarOffset", 30, 10);
yabhb.Call("hbSetBossHeadCentre", 80, 32);
yabhb.Call("hbSetBossHeadCentreSmall", 14, 14);
yabhb.Call("hbSetFillDecoOffset", 10);
yabhb.Call("hbSetFillDecoOffsetSmall", 10);
Code:
// Set the three colours the bar will change colours between. Defaults to (Green -> Yellow -> Red)
yabhb.Call("hbSetColours",
    new Color(0f, 1f, 0f), // 100%
    new Color(1f, 1f, 0f), // 50%
    new Color(1f, 0f, 0f));// 0%

// Force the health bar to use a custom texture as the boss head icon.
// A useful array to grab textures from is Main.npcHeadBossTexture[]
yabhb.Call("hbSetBossHeadTexture", GetTexture("UI/CustomBossHeadIcon"));
Tl;DR Here's what a custom bar looks like:

# EXAMPLE LAYOUT & CODE

Code:
Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
if(yabhb != null)
{
     yabhb.Call("hbStart");
     yabhb.Call("hbSetTexture",
         GetTexture("UI/ExampleLeft"),
         GetTexture("UI/ExampleMid"),
         GetTexture("UI/ExampleRight"),
         GetTexture("UI/ExampleFill"));
     yabhb.Call("hbSetMidBarOffset", 20, 12);
     yabhb.Call("hbSetBossHeadCentre", 22, 34);
     yabhb.Call("hbSetFillDecoOffsetSmall", 16);
     yabhb.Call("hbFinishSingle", NPCID.Mothron);
}

. . .










Download
via GitHub
or
via Mod Browser


(tModLoader 0.9 version)

Flashkirby99 - I am making this mod.
Several previous modders - The original idea and previous implementations

github repo
DISCLAIMER: I wrote this half asleep, so sorry for any half finished- sentences.

By default this mod supports single NPC bosses, and worm-type bosses. Since some vanilla and mod bosses have more complicated ways of determining damage throughout a fight, you may want to mod in your own specific behaviour:

Available on GitHub

Since 1.2 it's much easier to add quick support for this mod.

METHOD 1
Adding a boss bar for a single NPC (in this case, Zombies). Normally any single NPC boss with the boss flag set as true will be detected by this mod. Stick this in your Load() method, or somwhere similar that gets called at startup. You can add as many as you want (within reason).
Code:
public override void Load()
{
  Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
  if (yabhb != null)
  {
    yabhb.Call("RegisterHealthBar", NPCID.Zombie);
    yabhb.Call("RegisterHealthBar", NPCID.FemaleZombie);
    yabhb.Call("RegisterHealthBar", NPCID.SwampZombie);
  }
}
For these standard health bars, the following preset styles are available via the first method:
RegisterHealthBar
RegisterDemonHealthBar
RegisterMechHealthBar
RegisterDD2HealthBar

Additionally, if you want a miniboss with a tiny health bar:
RegisterHealthBarMini


METHOD 2
However worms and other multi-NPC enemies are a different story. If your boss is using some form of multiple health bars, consider the following:
Code:
public override void Load()
{
  Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
  if (yabhb != null)
  {
    yabhb.Call("RegisterHealthBarMulti",
      NPCID.EaterofWorldsHead,
      NPCID.EaterofWorldsBody,
      NPCID.EaterofWorldsTail);
  }
}
Like method 1, there are preset multi-npc bars available:
RegisterHealthBarMulti
RegisterDemonHealthBarMulti
RegisterMechHealthBarMulti
RegisterDD2HealthBarMulti
RegisterHealthBarMultiMini


METHOD 3 (Semi-advanced)
These are more complicated. Say you have some custom textures you want to use. Then the "RegisterCustomHealthBar" method call lets you define several settings, or leave them as null to use default behaviour. The format follows:
Code:
string "RegisterCustomHealthBar",
int NPCID, // this one cannot be null
bool? ForceSmall,
string displayName,
Texture2D fill,
Texture2D left,
Texture2D mid,
Texture2D right,
int midBarOffsetX,
int midBarOffsetY,
int fillDecoOffsetX,
int bossHeadCentreOffsetX,
int bossHeadCentreOffsetY,
Texture2D fillSmall,
Texture2D leftSmall,
Texture2D midSmall,
Texture2D rightSmall,
int fillDecoOffsetXSM,
int bossHeadCentreOffsetXSmall,
int bossHeadCentreOffsetYSmall
For a total of 20 parameters. If you are defining multiple NPCs with "RegisterCustomHealthBarMulti", replace the int NPCID with an int[], eg.
Code:
new int[] { NPCID.BrainofCthulhu, NPCID.Creeper }
So how does this work in practice? Say we want to make a health bar for a flying snake (because hey why not), giving it a custom health bar. The textures we have made prior are being stored as: UI/CustomBar*.png
Then it becomes a simple matter of inserting or 20 parameters:
Code:
public override void Load()
{
  Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
  if (yabhb != null)
  {
    yabhb.Call("RegisterCustomHealthBar",
      NPCID.FlyingSnake, // This is the enemy we want to track health for
      false, // ForceSmall left as false
      "Murder Dragoram Snake", // We can set a custom display name too
      // The default bar textures
      GetTexture("UI/CustomBarFill"),
      GetTexture("UI/CustomBarLeft"),
      GetTexture("UI/CustomBarMiddle"),
      GetTexture("UI/CustomBarRight"),
      // Since I based the textures off the default, there is no
      // need to change any of the offsets.
      null, null, null, null, null,
      // Small textures. Note you don't have to add small textures,
      //or any textures at all - just leave these as null to use default
      GetTexture("UI/CustomBarFillSmall"),
      GetTexture("UI/CustomBarLeftSmall"),
      GetTexture("UI/CustomBarMiddleSmall"),
      GetTexture("UI/CustomBarRightSmall"),
      // Same deal with offsets
      null, null, null
      );
  }
}

⁽ᶦᵍⁿᵒʳᵉ ᵗʰᵉ ᶠᵃᶜᵗ ᵗʰᵃᵗ ᴵ ᵃᶜᶜᶦᵈᵉⁿᵗˡʸ ʳᵉᵖˡᵃᶜᵉᵈ ᵃˡˡ ʷʰᶦᵗᵉˢ ʷᶦᵗʰ ᵗʳᵃⁿˢᵖᵃʳᵉⁿᶜʸ⁾


METHOD 4 (Advanced)
If you want as much control over the health bar as possible without resorting to just importing this mod, the mod Call "RegisterCustomMethodHealthBar" and "RegisterCustomMethodHealthBarMulti" provide the most options, as most textures and settings are replaced with Func<> calls, allowing for things like expert mode only graphics. Again, use null to indicate where to let base code run instead.
Code:
string "RegisterCustomHealthBar",
int NPCID, // this one cannot be null
bool? ForceSmall,
Func<NPC, string> getBossDisplayNameNPC,
Func<Texture2D> fill,
Func<Texture2D> left,
Func<Texture2D> mid,
Func<Texture2D> right,
int midBarOffsetX,
int midBarOffsetY,
int fillDecoOffsetX,
int bossHeadCentreOffsetX,
int bossHeadCentreOffsetY,
Func<Texture2D> fillSmall,
Func<Texture2D> leftSmall,
Func<Texture2D> midSmall,
Func<Texture2D> rightSmall,
int fillDecoOffsetXSM,
int bossHeadCentreOffsetXSmall,
int bossHeadCentreOffsetYSmall,
Func<NPC, int, int, Color> getHealthColour
For a total of 21 parameters. The last argument is the addition of a colour function to let you define how the bar's colour changes based on life and lifeMax. An example of how this is used in this mod itself is with the DD2 crystal, where no textures need changing, but the health bar colour behaviour does:
Code:
public override void Load()
{
    Func<NPC, int, int, Color> customColour = CustomHealthBarColour;
    Call("RegisterCustomMethodHealthBar", NPCID.DD2EterniaCrystal,
    true, null, null, null, null, null,
    null, null, null, null, null,
    null, null, null, null,
    null, null, null,
    customColour
  );
}

private Color CustomHealthBarColour(NPC npc, int life, int lifeMax)
{
    float percent = (float)life / lifeMax;
    float R = 1f, G = 1f;
    if (percent > 0.5f)
    {
        R = 1f - (percent - 0.5f) * 2;
    }
    else
    {
        G = 1f + ((percent - 0.5f) * 2f);
    }
    return new Color(R * 0.75f, G, R);
}
And, like the previous method, the same rules apply with an int[]{int,int...} in place of a single int when using "RegisterCustomMethodHealthBarMulti".


Custom Health Bar Texture Rules
The following defines a set of rules as to what you can do and where with custom textured healthbars. For simplicity's sake just use the one's available from github as a template so you won't have to mess with offset values.
 
Last edited:

Flashkirby99

Skeletron
Suggestions from @RexodinoLP from discord for posterity:
. . .​
well, I have 3 ways for it to appear
1: fading in/out
2: slides from below the screen, healthbar fills up
3: like invasions
. . .​
and maybe, uh. a way to make it either be on the top of the screen or bottom
. . .​
maybe, hmmm
make the bars smaller
everytime theres a new one
. . .​
Final suggestion for now:
Special healthbars for some bosses
some Vanilla bosses have special healthbars, and maybe some modded boss support
for example
Moon Lord has a luminite healthbar
WoF a fleshy one
 

Keks

Terrarian
It does not work for me...I have it installed, and reloaded my mods, but when I spawned a boss, there is just no healthbar
 

Keks

Terrarian
For me to help you as much as possible (not all may be relevant but you never know):
  1. Mod List
  2. Screenshot (even if it's not working, it helps)
  3. Which Boss is being spawned (or any of them)
  4. Singleplayer? Multiplayer?
Imma post it tomorrow, cuz I have to go to bed
 

Sapharan

Golem
I have a suggestion(s):
-skyrim like bar decrease (from sides to middle)
-Layered health bars for bosses that have multiple phases
-Smaller health bars for bosses that have parts (like skeletron and it's hands)
-Special features for certain bars (BoC you have to kill its minions first, so a number of icons representing his minions above hp bar)
 
Last edited:

Flashkirby99

Skeletron
I may work on this more in the future... but I also need to update Dust and Sound, fix bugs in Expeditions and add hardmode content to WeaponOut. Plus other life things, so idk.
I have a suggestion(s):
-skyrim like bar decrease (from sides to middle)
-Layered health bars for bosses that have multiple phases
-Smaller health bars for bosses that have parts (like skeletron and it's hands)
-Special features for certain bars (BoC you have to kill its minions first, so a number of icons representing his minions above hp bar)
-That shouldn't be too hard
-That'd be super useful to have but it'd need to be coded per boss, so beyond vanilla... shrug
-Same as previous
-Same as previous

What mods does this currently support?
If the mod has a boss that has a health, it probably supports it. Less simple if the boss does wacky things with it's health and hitbox (like how Brain of Cthulu can't be hurt until the creepers are defeated, or the moonlord having it's core health as a separate entity).
 

Sapharan

Golem
Yeah i'm aware of that but.. If you could add these as toggable option for example called "Special Features" and make an inside api to allow people creatinge multiple bars in their mods and/or adding minion counter then it could be totaly doable.
 

Xenomus

Spazmatism
this mod is so simple, but yet so effective and gives a really huge rpg feel:) looking forward to see something like this in terraria ow
 
Top Bottom