tModLoader Yet Another Boss Health Bar

Yet Another Boss Health Bar
v1.2.1, for tModLoader v0.10.0.2​

(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.

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
      );
  }
}
gbOLC2d.png

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


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.
YqVzkzv.png

. . .

4QHnjZX.png

DWhwZv8.png

unknown.png


5pVHVs8.png

xNtmjZg.png


kdcROYP.png

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
FKBossHealthBar.png

github repo
Yet Another Boss Health Bar
v1.2.1, for tModLoader v0.10.0.2​

(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.

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
      );
  }
}
gbOLC2d.png

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


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.
YqVzkzv.png

. . .

4QHnjZX.png

DWhwZv8.png

unknown.png


5pVHVs8.png

xNtmjZg.png


kdcROYP.png

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
FKBossHealthBar.png

github repo
Does this work for the latest Mod Browser?
 
Hey Dude! I have installed the calamity mod and when I start a boss battle of the mod, he doesn't have a bar. Can you say me how I can put it to him a bar or if I have to have something on? Thanks ! :D
 
you didnt read the part on the first post of "adding your own boss support".
No, i've seen this, but also i saw the posts about game crashes and etc, so i decide to ask first.
Anyway, i try one of the thorium bosses and seems it's working nicely. Next i check calamity and see if some bad things happend.
 
That'll be an toggle-on option in the next update as well as some back end stuff for other mod devs to make it work nicely with things like multi-phase bosses, though that'll probably still be at least a month away as I am still on hiatus, sorry!
 
Hello, i have some issues whit the healtbars, i am ussing this mod and calamity mod and when i battle whit the bosses (Vanilla ones too) the HP bar looks white.

 
Okay, so when I start a boss battle the health bar of the calimity's bosses it doesn't appear.
Sorry for my bad English
Some modded bosses are not tagged as being bosses. In such a case, this mod doesn't pick it up and the mod creator will have to do it themselves.

I recently downloaded this mod, and every time a boss shows up, my game crashes. Could someone help?
Which mods are you running?

For some reason all i see when i use this mod is a white bar. Not sure how to fix this.
Hello, i have some issues whit the healtbars, i am ussing this mod and calamity mod and when i battle whit the bosses (Vanilla ones too) the HP bar looks white.

I need to know how to reproduce this. Will probably need a mod list, and maybe platform too?? I've never come across this issue, does it still happen in the current version?
 
What do you mean by a "health bar for slimes?" Are you having a Slime Rain event on your world?

I'm not that person, but the Slime Rain progression bar only works properly if I complete the event by killing all the slimes. If I kill a couple and go underground, the progression bar will persist until I log out. It's not always on the screen, but it pops back in frequently, I think whenever an appropriate slime is around. The progression doesn't count down if you kill new slimes, though. It's always say "67/75" or whatever. It's pretty annoying.
 
I'm not that person, but the Slime Rain progression bar only works properly if I complete the event by killing all the slimes. If I kill a couple and go underground, the progression bar will persist until I log out. It's not always on the screen, but it pops back in frequently, I think whenever an appropriate slime is around. The progression doesn't count down if you kill new slimes, though. It's always say "67/75" or whatever. It's pretty annoying.
Ah, I see what you mean. Yeah, that does sound like a bug. I haven't encountered it, so I didn't know it was a thing.
 
v1.3, for tModLoader v0.10.0.4

Download (63.6 KB)


Evening all. For my first trick, I present an update to YABHB. This one's for all you modders out there.

Additions
  • Moon Lord and Plantera health bars have new textures and icons.
  • Supports Mod Helper (by hamstar)
  • Modders can now add looping textures along the middle of the bar.
  • Text now has borders.
Changes
  • New system for creating health bars, see OP in forum thread. Old system still works, but is deprecated.
  • Slime rain progress bar is now optional in the config json file.
  • No longer references TModSettings.
Fixes
  • Mod icon size fixed, should appear on the mod browser now.
 
Back
Top Bottom